public ColorComponentSearch(ColorFilteringPars filteringPars, ColorMixingPars mixingPars, HdrRGB targetColor, params BaseColor[] baseColors) { Contract.Requires(filteringPars != null); Contract.Requires(mixingPars != null); Contract.Requires(baseColors != null); Contract.Requires(baseColors.Length > 0); FilteringPars = filteringPars; MixingPars = mixingPars; BaseColors = baseColors; TargetColor = targetColor; }
private static void RunGA() { const int validationSampleCount = 3; var recipes = new ColorRecipes(@"recipe.xml"); int trainingSampleCount = recipes.Count - validationSampleCount; var shuffled = recipes;//.OrderBy(r => RandomGenerator.Random.Next()).ToList(); var trainingComp = new ColorMixerGenomComparer(shuffled.Take(trainingSampleCount)); var validationComp = new ColorMixerGenomComparer(shuffled.Skip(trainingSampleCount)); var bestComp = new CombinedColorMixerGenomComprarer(trainingComp, validationComp); // Algo int valuesCount = new ColorMixingPars().ValuesCount + new ColorFilteringPars().ValuesCount; // Cross Entropy var selAlgo = new GaussianSelectionAlgorithm(.15); var mp = new PointMutationPars(PointMutationType.Uniform, 0.005, 0.09); var opt = new CrossEntropy(valuesCount, 200, 40, mp, selAlgo, trainingComp); //// GA //var selAlgo = new GaussianSelectionAlgorithm(.6); ////var selAlgo = new TournamentSelectionAlgorithm(10); //var mp = new PointMutationPars(PointMutationType.Gaussian, 0.005, 0.025); //var opt = new GA(valuesCount, 200, 10, mp, selAlgo, trainingComp); // Harmony //var wsAlgo = new GaussianSelectionAlgorithm(.1, SelectionDirection.FromBottom); //var mp = new PointMutationPars(PointMutationType.Gaussian, 0.02, 0.005); //var opt = new HarmonySearch(valuesCount, 200, 99.9, mp, wsAlgo, trainingComp); opt.Initialize(); Genom best = null; // Run while (true) { opt.NextGeneration(); var current = opt[0]; bool bestChanged = false; if (best == null) { best = current; bestChanged = true; } else if (bestComp.Compare(current, best) < 0) { best = current; bestChanged = true; } //if (opt.GenerationNo % opt.PopulationSize == 0) { Console.WriteLine("\n-- Generation {0} --", opt.GenerationNo); Show("Current", current, trainingComp, validationComp); Show("Best", best, trainingComp, validationComp, bestChanged); } } }