Randomize() public method

Perform a simple randomization of the weights of the neural network between -1 and 1.
public Randomize ( ) : void
return void
Esempio n. 1
0
        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="app">Holds arguments and other info.</param>
        public void Execute(IExampleInterface app)
        {
            var network = new FlatNetwork(2, 4, 0, 1, false);
            network.Randomize();

            IMLDataSet trainingSet = new BasicMLDataSet(XORInput, XORIdeal);


            var train = new TrainFlatNetworkResilient(network, trainingSet);

            int epoch = 1;

            do
            {
                train.Iteration();
                Console.WriteLine(@"Epoch #" + epoch + @" Error:" + train.Error);
                epoch++;
            } while (train.Error > 0.01);

            var output = new double[1];
            // test the neural network
            Console.WriteLine(@"Neural Network Results:");
            foreach (IMLDataPair pair in trainingSet)
            {
                double[] input = pair.Input.Data;
                network.Compute(input, output);
                Console.WriteLine(input[0] + @"," + input[1] + @":" + output[0]);
            }
        }
        public static long BenchmarkEncogFlat(double[][] input, double[][] output)
        {
            var network = new FlatNetwork(input[0].Length, HIDDEN_COUNT, 0,
                                          output[0].Length, false);
            network.Randomize();
            var trainingSet = new BasicMLDataSet(input, output);

            var train = new TrainFlatNetworkBackPropagation(
                network, trainingSet, 0.7, 0.7);

            var a = new double[2];
            var b = new double[1];

            var sw = new Stopwatch();
            sw.Start();
            // run epoch of learning procedure
            for (int i = 0; i < ITERATIONS; i++)
            {
                train.Iteration();
            }
            sw.Stop();

            return sw.ElapsedMilliseconds;
        }