Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------- Very simple neural network in 'AND' configuration ------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using aneuro32.Nn.Structure.FeedForward;
- using aneuro32.Functions;
- using aneuro32.Learning.Supervised.Propagation;
- using aneuro32.Misc;
- namespace M_Adeline_testApp
- {
- class Program
- {
- static void Main(string[] args)
- {
- double[][] input =
- {
- new double[] {0,0},
- new double[] {0,1},
- new double[] {1,0},
- new double[] {1,1}
- };
- double[][] target =
- {
- new double[] {0},
- new double[] {0},
- new double[] {0},
- new double[] {1}
- };
- // Build M-Adeline network, a very simple neural network configuration
- MAdeline MyNet = new MAdeline(2);
- // Add neuron threshold, important where input values are zero
- MyNet.AddBiasWeight();
- // Connects neurons, initilize all
- MyNet.Build();
- // Instantius training algorithm
- WindrowHoff trainingAlg = new WindrowHoff(
- ref MyNet,
- input,
- target,
- activation_mode.sigmoid,
- 0.001,
- 0.5
- );
- bool retVal;
- // Training
- do
- {
- retVal = trainingAlg.iteration();
- if (retVal != true)
- {
- Console.WriteLine("Training error: " + trainingAlg.NetworkError);
- break;
- }
- } while (!trainingAlg.isTrained);
- // Testing
- int j = 0;
- Console.WriteLine("Net test:");
- foreach (double[] _in in input)
- {
- MyNet.SetInput(input[j]);
- MyNet.Exec();
- Console.WriteLine("\nPattern n° "+j);
- Console.WriteLine("Input: " + input[j][0] + " " + input[j][1]);
- Console.WriteLine("Output: " + MyNet.output.OutputValue.ToString("0.00") + " Ideal: " + target[j][0]);
- j++;
- }
- Console.WriteLine("\nNet final error: "+trainingAlg.CurrentMeanSquareError.ToString("0.######"));
- Console.WriteLine("Total epoch: "+trainingAlg.CurrentEpoch);
- List<double> weights = MyNet.SaveWeights();
- // Display weights:
- Console.WriteLine("\nNet final weights: ");
- foreach (double d in weights)
- {
- Console.WriteLine(d.ToString("0.######"));
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment