Exemplo n.º 1
0
        private void BuildNet()
        {
            List <Layer> layers;
            int          hiddenNuerons, it;
            double       rate, lower;
            double       error;
            FunctionType Ftype;

            layers        = new List <Layer>();
            hiddenNuerons = 7;
            rate          = 0.5;
            Ftype         = FunctionType.SIGMOID;

            layers.Add(new Layer(inputs[0].Features.Length, inputs[0].Features.Length, rate, Ftype));
            layers.Add(new Layer(hiddenNuerons, layers[layers.Count - 1].Neurons.Length, rate, Ftype));
            layers.Add(new Layer(inputs[0].DesiredValue.Length, layers[layers.Count - 1].Neurons.Length, rate, Ftype));

            net = new NeuralNetwork(layers.ToArray());
            net.SetTrainSet(inputs.ToArray());

            error = double.MaxValue;
            lower = double.MaxValue;

            it = 0;
            while (error > 0.001 && it++ < 10000000)
            {
                error = net.Train();
                if (error < lower)
                {
                    lower = error;
                }
                if (it % 50 == 0)
                {
                    MyDelegates.SetTextValue(LBL_IT, "epochs : " + it);
                    MyDelegates.SetTextValue(LBL_ERROR, "Error : " + Math.Round(error, 5));
                    MyDelegates.SetTextValue(LBL_LOWEST, "Lowest : " + Math.Round(lower, 9));
                }

                if (it % 1000 == 0)
                {
                    try
                    {
                        ClassifySpace();
                    }catch (Exception) {}
                }
            }
        }