public AdjustedNeuralNetworkPopulation Create(NeuralNetwork network, NeuralNetworkTest test, out AdjustedNeuralNetworkBodyFactory bodyFactory) { Contract.Requires(network != null); Contract.Requires(test != null); return DoCreate(network, test, out bodyFactory); }
public static void Begin() { //var parameters = new AdjustedTestableNetworkParameters //{ // Test = test, // Network = NeuralArchitecture.CreateLayered( // test.InputSize, // test.OutputSize, // () => new Synapse(), // () => new ActivationNeuron(new LinearActivationFunction(1)), // true, // 20, 10) //}; var parameters = new AdjustedTestableNetworkParameters { Test = test, Network = NeuralArchitecture.CreateFullConnected( test.InputSize, test.OutputSize, 20, () => new Synapse(), () => new ActivationNeuron(new LinearActivationFunction(1)), true) }; var factory = new AdjustedNeuralNetworkBodyFactory(parameters); factory.CrossoverChunkSize = IntRange.CreateFixed((parameters.Network.ConnectionCount + parameters.Network.NodeCount) / 2 - 1); //factory.CrossoverChunkSize = new InclusiveRange(10, 10); factory.PointMutationChance = 0.005; var population = new AdjustedNeuralNetworkPopulation(); population.ChanceOfMigration = 0.1; for (int idx = 0; idx < groupCount; idx++) { var group = new AdjustedNeuralNetworkGroup( factory, groupSize); //group.SelectionStrategy = new RandomSelectionStrategy(); population.Groups.Add(group); } var context = new GAContext(population); context.BestBodyArrived += OnBestArrived; context.Start(); Console.ReadKey(); context.Stop(); }
private AdjustedNeuralNetworkPopulation DoCreate(NeuralNetwork network, NeuralNetworkTest test, out AdjustedNeuralNetworkBodyFactory bodyFactory) { var parameters = new AdjustedTestableNetworkParameters { Test = test, Network = network, MutationStrength = MutationStrength }; bodyFactory = new AdjustedNeuralNetworkBodyFactory(parameters); if (CrossoverChunkSize.HasValue) { bodyFactory.CrossoverChunkSize = CrossoverChunkSize.Value; } else { bodyFactory.CrossoverChunkSize = IntRange.CreateFixed(parameters.AdjustableItems.Length / 2 - 1); } bodyFactory.PointMutationChance = PointMutationChance; var newPop = new AdjustedNeuralNetworkPopulation(); newPop.ChanceOfMigration = ChanceOfMigration; for (int gIdx = 0; gIdx < groupCount; gIdx++) { var group = new AdjustedNeuralNetworkGroup(bodyFactory, groupSize); if (SelectionStrategy != null) group.SelectionStrategy = SelectionStrategy; newPop.Groups.Add(group); } return newPop; }