void Start() { int memorySize = 2; BrainStructure brainStructure = new BrainStructure() { InputCount = 16, LevelSizes = new int[] { 3 + memorySize }, MemoryBitCount = memorySize }; Genome genome = new Genome(brainStructure); genome.SetRandomValues(); Console.WriteLine("Genome: " + genome.GetView()); DigitalBrain brain = new DigitalBrain(); brain.Load(genome); BitStorage input = new BitStorage(brainStructure.InputCount); BitStorage output = new BitStorage(brainStructure.OutputCount); for (int i = 0; i < 5; i++) { input.SetRandomValues(); Console.WriteLine("\r\nInput: " + input.GetView()); for (int j = 0; j < 1; j++) { //int bitToChange = Common.Random.Next(genome.Length); //genome[bitToChange] ^= true; //Console.WriteLine("Genome: " + genome.GetView()); //brain.Load(genome); for (int k = 0; k < 3; k++) { brain.Process(input, output); Console.WriteLine("Output: " + output.GetView() + " Memory: " + brain.Memory.GetView()); } } } }
void TestCompilation() { var bs = new BrainStructure() { InputCount = 100, MemoryBitCount = 16, LevelSizes = new int[] { 50, 24 } }; Genome genome = new Genome(bs); genome.SetRandomValues(); var brain = new DigitalBrain(); brain.Load(genome); var output = new BitStorage(bs.OutputCount); var input = new BitStorage(bs.InputCount); input.SetRandomValues(); Console.WriteLine(input.GetView()); int count = 10000; var start = DateTime.Now; Parallel.For(0, count, i => { brain.Process(input, output); }); Console.WriteLine(output.GetView() + " " + count / (DateTime.Now - start).TotalSeconds); brain.Compile(); start = DateTime.Now; Parallel.For(0, count, i => { brain.Process(input, output); }); Console.WriteLine(output.GetView() + " " + count / (DateTime.Now - start).TotalSeconds); }
void Performance() { var brains = new List <IBrain>(); var bs = new BrainStructure() { InputCount = 100, MemoryBitCount = 16, LevelSizes = new int[] { 50, 24 } }; for (int i = 0; i < 100; i++) { Genome genome = new Genome(bs); genome.SetRandomValues(); var brain = new DigitalBrain(); brain.Load(genome); brains.Add(brain); } Console.WriteLine("Compiling"); int nr = 0; var cStart = DateTime.Now; Parallel.ForEach(brains, brain => { (brain as DigitalBrain).Compile(); lock (brains) { Console.SetCursorPosition(0, 0); Console.WriteLine("Compiling " + ++nr); } }); Console.WriteLine("Compilations per second " + nr / (DateTime.Now - cStart).TotalSeconds); return; var output = new BitStorage(bs.OutputCount); int op = 0; DateTime start = DateTime.Now; for (int i = 0; i <= 10000; i++) { var input = new BitStorage(bs.InputCount); input.SetRandomValues(); Parallel.ForEach(brains, brain => { brain.Process(input, output); }); op += brains.Count; if (i % 10 == 0) { double seconds = (DateTime.Now - start).TotalSeconds; double performance = op; performance /= seconds; Console.SetCursorPosition(0, 0); Console.WriteLine(seconds.ToString("f2") + " => " + i + " ; " + performance.ToString("f2")); } } Console.WriteLine("Press any key"); Console.ReadKey(true); }