Esempio n. 1
0
        public float[] Training(float []x)
        {
            BackPropNeuralNet bnn = new BackPropNeuralNet(numInput, numHidden, numOutput);
            float[] yValues = new float[numOutput];
            float[] tValues = new float[numOutput];
            tValues.SetValue(0, 0);
            int maxEpochs = 10000;
            float errorThresh = 0.00001f;
            Console.WriteLine("\nSetting max epochs = " + maxEpochs + " and error threshold = " + errorThresh.ToString("F6"));

            int epoch = 0;
            double error = double.MaxValue;
            Console.WriteLine("\nBeginning training using back-propagation\n");

            while (epoch < maxEpochs) // train
            {
                if (epoch % 20 == 0) Console.WriteLine("epoch = " + epoch);

                yValues = bnn.ComputeOutputs(x);
                error = Helpers.Error(tValues, yValues);
                if (error < errorThresh)
                {
                    Console.WriteLine("Found weights and bias values that meet the error criterion at epoch " + epoch);
                    break;
                }
                bnn.UpdateWeights(tValues, learnRate, learnRate);
                ++epoch;
            } // train loop

            float[] finalWeights = bnn.GetWeights();
            return finalWeights;
        }
Esempio n. 2
0
 public float[] Test(float[] weighs,float []x)
 {
     BackPropNeuralNet b = new BackPropNeuralNet(numInput,numHidden, numOutput);
     b.SetWeights(weighs);
     return b.ComputeOutputs(x);
 }