Exemple #1
0
        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 PatternMatching(int x, int y, int output)
        {
            InitializeComponent();

            ProgressBegin();

            pm = new Grid2DControler(x, y, output);

            BasicConfig    bc = pm.BasicConfiguration;
            TrainingConfig tc = pm.TrainingConfiguration;
            Grid2DConfig   gc = new Grid2DConfig(bc.Node);

            bc.ActivationType.Value            = EActivationType.Symmetric;
            bc.BiasNeuronEnable.Value          = true;
            bc.BiasNeuronOutput.Value          = 0.9d;
            bc.DeadNeuronDecayEnabled.Value    = false;
            bc.FlatspotEliminationEnable.Value = true;
            bc.FlatspotElimination.Value       = 0.05d;
            bc.InitialSymmetryBreaking.Value   = 0.2d;
            bc.LearningRate.Value             = 0.3d;
            bc.ManhattanTrainingEnable.Value  = false;
            bc.MomentumTermEnable.Value       = false;
            bc.SymmetryPreventionEnable.Value = true;
            bc.SymmetryPrevention.Value       = 0.05d;
            bc.WeightDecayEnable.Value        = true;
            bc.WeightDecay.Value = 0.01d;

            bc.LowInput.Value   = -3d;
            bc.HighInput.Value  = 3d;
            bc.LowOutput.Value  = -0.95d;
            bc.HighOutput.Value = 0.95d;

            tc.AutoTrainingAttempts.Value          = 1;
            tc.AutoTrainingEpochs.Value            = 400;
            tc.AutoTrainingPercentSuccessful.Value = 1.0d;
            tc.ShuffleEnable.Value          = true; // make it more robust for noise
            tc.ShuffleNoiseSigma.Value      = 0.2d;
            tc.ShuffleSwapProbability.Value = 0.2d; // 0.2 = every 5ht pixel is swapped (20% probability) !!

            gc.All2AllEnable.Value         = false;
            gc.HorizontalLinesEnable.Value = true;
            gc.VerticalLinesEnable.Value   = true;
            gc.RingsEnable.Value           = true;
            gc.LittleSquaresEnable.Value   = true;

            pm.BuildNetwork(true);

            //pm.NetworkTrainer = new SimpleTrainer();
            //pm.NetworkTrainer = new OpenloopTrainer();
            //pm.NetworkTrainer = new ConditionalTrainer();
            pm.NetworkTrainer = new FeedbackTrainer();

            ProgressStatus(50);

            pm.Patterns.PatternAdded   += pm_OnNewPatternAdded;
            pm.PatternSelectionChanged += pm_OnPatternSelectionChanged;
            pm.InputChanged            += pm_OnInputChanged;
            pm.NetworkRebuilt          += pm_OnNetworkRebuilt;

            outputStat.Init(pm);
            inputGrid.Init(pm);
            inputGrid.OnGridChanged += inputGrid_OnGridChanged;

            ProgressEnd();
        }