コード例 #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]);
            }
        }
コード例 #2
0
ファイル: Recognition.cs プロジェクト: vkristijan/NENR
        private void canvas_MouseUp(object sender, MouseEventArgs e)
        {
            List <PointF> points = canvas.GetPoints();

            int n     = _ffann.InputSize() / 2;
            var input = PointFListToDoubleArray(ScalePoints(points, n));

            double[] output = _ffann.GetOutput(input);
            Label    label  = Encoder.Decode(output);

            lbl_label.Text = label.ToString();
        }
コード例 #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);
        }