Beispiel #1
0
        static void Main(string[] args)
        {
            int[] layout = { 1, 6, 1 };
            ActivationFunction[] activationFunctions = { Sigmoid(), Sigmoid() };
            FFANN ffann = new FFANN(layout, activationFunctions);

            int n = ffann.WeightCount();

            double[] weights = new double[n];
            Random   rnd     = new Random();

            for (int i = 0; i < n; ++i)
            {
                weights[i] = rnd.NextDouble();
            }
            ffann.SetWeights(weights);

            Dataset dataset = new Dataset();

            dataset.Read("dummyData.txt");
            Console.WriteLine(ffann.CalculateError(dataset));

            Backpropagation train = new Backpropagation(ffann, 0.1, dataset);

            train.MaxIteration = 100000;
            train.MaxError     = 1e-6;
            train.Train(1);

            for (int i = 0; i < dataset.Size; ++i)
            {
                Console.WriteLine(ffann.GetOutput(dataset.GetInput(i))[0].ToString("0.0000") + "  " + dataset.GetOutput(i)[0]);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            int[] layout = ReadLayout(args[1]);
            var   activationFunctions = new ActivationFunction[layout.Length - 1];

            for (int i = 0; i < layout.Length - 1; ++i)
            {
                activationFunctions[i] = Sigmoid();
            }

            FFANN ffann = new FFANN(layout, activationFunctions);

            Console.WriteLine(ffann.WeightCount());

            int n = ffann.WeightCount();

            double[] weights = new double[n];
            Random   rnd     = new Random();

            for (int i = 0; i < n; ++i)
            {
                weights[i] = rnd.NextDouble();
            }
            ffann.SetWeights(weights);

            Dataset dataset = new PointDataset(layout[0] / 2);

            dataset.Read(args[0]);
            Console.WriteLine(ffann.CalculateError(dataset));

            Backpropagation train = new Backpropagation(ffann, 0.2, dataset);

            train.MaxIteration = 5000;
            train.MaxError     = 1e-6;

            int batchSize;

            switch (args[2])
            {
            case "1":
                batchSize = dataset.Size;
                break;

            case "2":
                batchSize = 1;
                break;

            default:
                batchSize = 20;
                break;
            }
            train.Train(batchSize);

            Application.Run(new Recognition(ffann));
        }
Beispiel #3
0
        public double Evaluate(Chromosome c)
        {
            double error = 0;

            _ffann.SetWeights(c._values);
            foreach (var data in _data)
            {
                double   x      = data.X;
                double   y      = data.Y;
                double[] input  = { x, y };
                double[] output = _ffann.GetOutput(input);

                error += Math.Pow(output[0] - data.Z1, 2);
                error += Math.Pow(output[1] - data.Z2, 2);
                error += Math.Pow(output[2] - data.Z3, 2);
            }

            error /= 3;
            error /= _data.Count;
            c.Cost = error;
            return(error);
        }