public static void RunEvolution2() { var bmp = new System.Drawing.Bitmap(FILE_IN); ImageSys img = new ImageSys(bmp); Texture txt = new Interpolent(img, Intpol.Nearest); //var fitness = BuildFitness(txt); Console.WriteLine("Collecting Sample Points..."); ControlPoints.BuildData(); Fitness <CPPN> fitness = x => ControlPoints.GradeImage(x); EvolSpecies <CPPN> evolver = new EvolSpecies <CPPN>(500, 1.0, fitness); //100, 0.1 CPPN best = new CPPN(); CPPN proto = new CPPN(); Renderor ren = new Renderor(); ImageSys output = new ImageSys(256, 256); //img.BMP.Save(FILE_OUT + "test.png"); Console.WriteLine("Aproximating Image: " + FILE_IN); evolver.Initialise(best); for (int i = 0; i < MAX_GEN; i++) { Console.WriteLine(); string index = i.ToString("0000"); Console.WriteLine("Rendering Best Fit..."); ren.Render(best, output); output.BMP.Save(FILE_OUT + "A" + index + ".png"); Console.WriteLine("Rendering Random Species..."); ren.Render(proto, output); output.BMP.Save(FILE_OUT + "B" + index + ".png"); int nodes = best.NumNurons; int axons = best.NumAxons; double fit = evolver.TopFitness; Console.WriteLine(); Console.WriteLine("Generation " + i + ": " + nodes + " " + axons + " " + fit); Console.WriteLine("Num Species: " + evolver.NumSpecies); Console.WriteLine("Threshold: " + evolver.Threshold.ToString("0.00")); ////we cannot have more species than there are indvidual organisms //if (evolver.NumSpecies > 100) throw new Exception(); evolver.Evolve(); evolver.GetTopSpec(best); evolver.GetRandProto(proto); } }
public static void RandomMutaitons() { var bmp = new System.Drawing.Bitmap(FILE_IN); ImageSys img = new ImageSys(bmp); Texture txt = new Interpolent(img, Intpol.Nearest); var fitness = BuildFitness(txt); CPPN network = new CPPN(); VRandom rng = new RandMT(); network.Randomize(rng); Renderor ren = new Renderor(); ImageSys output = new ImageSys(256, 256); //img.BMP.Save(FILE_OUT + "test.png"); Console.WriteLine("Building Network..."); for (int i = 0; i < 200; i++) { network.Mutate(rng, 1.0); } Console.WriteLine("Aproximating Image: " + FILE_IN); //NOTE: Make it so we don't accept mutations that //result in NaN fitness! for (int i = 0; i < MAX_GEN; i++) { //network.Mutate(rng, 1.0); //0.1 network.Randomize(rng); ren.Render(network, output); string file = i.ToString("0000") + ".png"; output.BMP.Save(FILE_OUT + file); int nodes = network.NumNurons; int axons = network.NumAxons; double fit = fitness(network); //Console.WriteLine(); Console.WriteLine("Generation " + i + ": " + nodes + " " + axons + " " + fit); } }
public static void RunEvolution() { var bmp = new System.Drawing.Bitmap(FILE_IN); ImageSys img = new ImageSys(bmp); Texture txt = new Interpolent(img, Intpol.Nearest); var fitness = BuildFitness(txt); EvolMonogen <CPPN> evolver = new EvolMonogen <CPPN>(50, 0.1, fitness); CPPN best = new CPPN(); evolver.Initialise(best); Renderor ren = new Renderor(); ImageSys output = new ImageSys(256, 256); //img.BMP.Save(FILE_OUT + "test.png"); Console.WriteLine("Aproximating Image: " + FILE_IN); for (int i = 0; i < MAX_GEN; i++) { evolver.Evolve(); evolver.GetTopSpec(best); ren.Render(best, output); string index = i.ToString("0000"); output.BMP.Save(FILE_OUT + index + ".png"); int nodes = best.NumNurons; int axons = best.NumAxons; double fit = evolver.TopFitness; Console.WriteLine(); Console.WriteLine("Generation " + i + ": " + nodes + " " + axons + " " + fit); } }