public void RunDemo() { Console.WriteLine("### BUILDING BLOCK DEMO ###"); //Initialize the pattern matching building block //for a 2x2 grid and 2 output neurons. Grid2DControler gpm = new Grid2DControler(2, 2, 2); gpm.BuildNetwork(true); //Add 4 patterns to the pattern manager. //note that the input array is in row by row order, //and the output numers the (single!) output neuron to train for. gpm.Patterns.Add("first", 0, new bool[] { true, false, true, false }); gpm.Patterns.Add("second", 1, new bool[] { true, true, false, false }); gpm.Patterns.Add("third", 1, new bool[] { false, true, false, false }); gpm.Patterns.Add("fourth", 0, new bool[] { false, true, true, false }); //Some configuration ... gpm.TrainingConfiguration.AutoTrainingEpochs.Value = 500; //Calculate all patterns. The CalculateCurrentNetwork method //returns the output neuron index that matches best. //First select a pattern, then calculate it: Console.WriteLine("# Initial Status"); for (int i = 0; i < gpm.PatternCount; i++) { gpm.SelectPattern(i); Console.Write(gpm.CalculateCurrentNetwork() + ": "); App.PrintArray(gpm.NeuralNetwork.CollectOutput()); } Console.WriteLine("Successful Patterns: " + gpm.CountSuccessfulPatterns()); //Train the third pattern one time: Console.WriteLine("# Third Pattern Training"); gpm.SelectPattern(2); gpm.TrainCurrentNetwork(); for (int i = 0; i < gpm.PatternCount; i++) { gpm.SelectPattern(i); Console.Write(gpm.CalculateCurrentNetwork() + ": "); App.PrintArray(gpm.NeuralNetwork.CollectOutput()); } Console.WriteLine("Successful Patterns: " + gpm.CountSuccessfulPatterns()); //Autotrain all Patterns: Console.WriteLine("# Auto Training:"); Console.WriteLine(gpm.AutoTrainNetwork() ? "successful" : "failed"); for (int i = 0; i < gpm.PatternCount; i++) { gpm.SelectPattern(i); Console.Write(gpm.CalculateCurrentNetwork() + ": "); App.PrintArray(gpm.NeuralNetwork.CollectOutput()); } Console.WriteLine("Successful Patterns: " + gpm.CountSuccessfulPatterns()); Console.WriteLine("=== COMPLETE ==="); Console.WriteLine(); }
public void SelectAndActivatePattern(int pattern) { pm.SelectPattern(pattern); }