예제 #1
0
        /// <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)
        {
            {
                // Create an dbnn belief network.
                int[]             hidden = { 2, 3 };
                DeepBeliefNetwork dbn    = new DeepBeliefNetwork(TRAINING_INPUT[0].Length, hidden, TRAINING_IDEAL[0].Length);
                dbn.Random = new MersenneTwisterGenerateRandom(54321);
                dbn.Reset();


                // Layer by layer unsupervised training.
                for (int level = 0; level < hidden.Length; level++)
                {
                    UnsupervisedTrainDBN trainUnsupervised = new UnsupervisedTrainDBN(
                        dbn, level, TRAINING_INPUT, LearningRateUnsupervised, K);
                    for (int i = 0; i < 2000; i++)
                    {
                        trainUnsupervised.Iteration();
                    }
                }

                // Supervised training.
                SupervisedTrainDBN trainSupervised = new SupervisedTrainDBN(
                    dbn, TRAINING_INPUT, TRAINING_IDEAL, LearningRateSupervised);
                int iteration = 0;
                do
                {
                    iteration++;
                    trainSupervised.Iteration();
                    Console.WriteLine("Iteration: " + iteration + ", Supervised training: error = "
                                      + trainSupervised.LastError);
                } while (trainSupervised.LastError > 0.001);


                // Use test data.
                foreach (double[] input in TEST_INPUT)
                {
                    double[] output = dbn.ComputeRegression(input);
                    Console.WriteLine(string.Join(",", input) + " -> " + string.Join(",", output));
                }
            }
        }