/// <summary> /// Create a NEAT population. /// </summary> /// <param name="architecture">The architecture string to use.</param> /// <param name="input">The input count.</param> /// <param name="output">The output count.</param> /// <returns>The population.</returns> public IMLMethod Create(String architecture, int input, int output) { if (input <= 0) { throw new EncogError("Must have at least one input for NEAT."); } if (output <= 0) { throw new EncogError("Must have at least one output for NEAT."); } IDictionary <String, String> args = ArchitectureParse.ParseParams(architecture); ParamsHolder holder = new ParamsHolder(args); int populationSize = holder.GetInt( MLMethodFactory.PropertyPopulationSize, false, 1000); int cycles = holder.GetInt( MLMethodFactory.PropertyCycles, false, NEATPopulation.DefaultCycles); IActivationFunction af = this.factory.Create( holder.GetString(MLMethodFactory.PropertyAF, false, MLActivationFactory.AF_SSIGMOID)); NEATPopulation pop = new NEATPopulation(input, output, populationSize); pop.Reset(); pop.ActivationCycles = cycles; pop.NEATActivationFunction = af; return(pop); }
static void Main(string[] args) { // this form of ANN uses genetic algorithm to produce // hidden layer of neurons // A NEAT network starts with only an // input layer and output layer. The rest is evolved as the training progresses. // Connections inside of a NEAT neural network can be feedforward, recurrent, // or self - connected.All of these connection types will be tried by NEAT as it // attempts to evolve a neural network capable of the given task. IMLDataSet trainingSet = new BasicMLDataSet(XORInput, XORIdeal); NEATPopulation pop = new NEATPopulation(2, 1, 1000); pop.Reset(); pop.InitialConnectionDensity = 1.0; // not required, but speeds processing. ICalculateScore score = new TrainingSetScore(trainingSet); // train the neural network TrainEA train = NEATUtil.ConstructNEATTrainer(pop, score); EncogUtility.TrainToError(train, 0.01); NEATNetwork network = (NEATNetwork)train.CODEC.Decode(train.BestGenome); // TODO no persistance? no means to peek structure? // test the neural network Console.WriteLine(@"Neural Network Results:"); EncogUtility.Evaluate(network, trainingSet); }
public void ResetTraining() { Substrate substrate = SubstrateFactory.factorSandwichSubstrate(11, 11); BoxesScore score = new BoxesScore(11); pop = new NEATPopulation(substrate, 500); pop.ActivationCycles = 4; pop.Reset(); train = NEATUtil.ConstructNEATTrainer(pop, score); OriginalNEATSpeciation speciation = new OriginalNEATSpeciation(); train.Speciation = new OriginalNEATSpeciation(); }
/// <summary> /// The entry point for this example. If you would like to make this example /// stand alone, then add to its own project and rename to Main. /// </summary> /// <param name="args">Not used.</param> public static void ExampleMain(string[] args) { IMLDataSet trainingSet = new BasicMLDataSet(XORInput, XORIdeal); var pop = new NEATPopulation(2, 1, 1000); pop.Reset(); pop.InitialConnectionDensity = 1.0; // not required, but speeds processing. ICalculateScore score = new TrainingSetScore(trainingSet); // train the neural network var train = NEATUtil.ConstructNEATTrainer(pop, score); EncogUtility.TrainToError(train, 0.01); var network = (NEATNetwork)train.CODEC.Decode(train.BestGenome); // test the neural network Console.WriteLine(@"Neural Network Results:"); EncogUtility.Evaluate(network, trainingSet); }