Exemplo n.º 1
0
        private void CreateNetwork()
        {
            if (uiSuspendCreating.Checked)
            {
                return;
            }

            int    layerCount       = uiLayerCount.Value;
            int    outputCount      = uiOutputCount.Value;
            double weightsRange     = GetWeightsRange(uiWeightsRange.Value);
            double topWeight        = weightsRange / 2.0;
            double bottomWeight     = topWeight - weightsRange;
            double biasWeightsRange = GetWeightsRange(uiBiasWeightsRange.Value);
            double bottomBiasWeight = -(biasWeightsRange / 2.0);

            int[] neuronCounts = new int[layerCount];
            for (int i = 0; i < neuronCounts.Length - 1; i++)
            {
                neuronCounts[i] = layerCount;
            }
            neuronCounts[neuronCounts.Length - 1] = outputCount;
            Type neuronType;

            switch (uiTransferFunctionType.SelectedIndex)
            {
            case 0: neuronType = typeof(BipolarNeuron); break;

            case 1: neuronType = typeof(UnipolarNeuron); break;

            case 2: neuronType = typeof(SigmoidalNeuron); break;

            case 3: neuronType = typeof(TanhNeuron); break;

            default: throw new InvalidOperationException();
            }

            _examinedNetwork = new MlpNetwork(2, true, neuronCounts, neuronType);
            _examinedNetwork.Randomize(_randomGenerator, bottomWeight, topWeight);
            if (uiDifferentBiasRange.Checked)
            {
                foreach (Neuron n in _examinedNetwork.Layers[0])
                {
                    n.Weights[n.Weights.Length - 1] =
                        bottomBiasWeight +
                        _randomGenerator.NextDouble() * biasWeightsRange;
                }
            }

            _netFun.NeuralNetwork = _examinedNetwork;
            _netFun.OutputOffset  = 0.5;
            _netFun.OutputScale   = 0.5;

            _netFun.OutputColors.Clear();
            for (int i = 0; i < outputCount; i++)
            {
                //{tga to paint only blue/red
                _netFun.OutputColors.Add(Color.FromArgb(255, 0, 0));
                //tga}

                //_netFun.OutputColors.Add(Color.FromArgb(
                //    _randomGenerator.Next(255),
                //    _randomGenerator.Next(255),
                //    _randomGenerator.Next(255)));
            }

            CreateNeuronLines();
        }
Exemplo n.º 2
0
 private void RestartTeaching()
 {
     _examinedNetwork.Randomize(_randomGenerator, -1.0, 1.0, 0.001);
     StepNumber = 0;
     uiChartPlotter.Invalidate();
 }
Exemplo n.º 3
0
 internal void InitializeTeaching()
 {
     _examinedNetwork.Randomize(_randomGenerator, -0.1, 0.1);
     _currentElementIndex = -1;
     _teachingStep        = 0;
 }
Exemplo n.º 4
0
        private void CreateNetwork()
        {
            int[] neuronCounts = new int[trackBar3.Value];
            for (int i = 0; i < neuronCounts.Length - 1; i++)
            {
                neuronCounts[i] = trackBar3.Value;
            }
            neuronCounts[neuronCounts.Length - 1] = trackBar2.Value;
            _network = new MlpNetwork(2, true, neuronCounts,
                                      checkBox2.Checked ? typeof(SigmoidalNeuron) : typeof(BipolarNeuron));
            if (checkBox2.Checked)
            {
                foreach (Neuron[] layer in _network.Layers)
                {
                    foreach (Neuron n in layer)
                    {
                        ((SigmoidalNeuron)n).Beta = 100.0;
                    }
                }
            }
            _network.Randomize(_randomGenerator, -10.0, 10.0);

            /*foreach (Neuron n in _network.Layers[0])
             *  n.Weights[n.Weights.Length - 1] =
             *      _randomGenerator.NextDouble() * 20.0 - 10.0;*/
            netFun.NeuralNetwork = _network;
            netFun.OutputColors.Clear();
            if (trackBar2.Value == 2)
            {
                netFun.OutputColors.Add(Color.Red);
                netFun.OutputColors.Add(Color.Green);
            }
            else
            {
                for (int i = 0; i < trackBar2.Value; i++)
                {
                    netFun.OutputColors.Add(Color.FromArgb(
                                                _randomGenerator.Next(255),
                                                _randomGenerator.Next(255),
                                                _randomGenerator.Next(255)));
                }
            }

            _neuronLines.Data.Clear();
            foreach (Neuron n in _network.Layers[0])
            {
                double     a            = n.Weights[0];
                double     b            = n.Weights[1];
                double     c            = n.Weights[2];
                RectangleF vrect        = chartPlotter4.VisibleRectangle;
                PointF[]   points       = new PointF[2];
                int        currentPoint = 0;
                double     y            = (-c - a * vrect.Left) / b;
                if (y >= vrect.Top && y <= vrect.Bottom)
                {
                    points[currentPoint++] = new PointF(vrect.Left, (float)y);
                }
                y = (-c - a * vrect.Right) / b;
                if (y >= vrect.Top && y <= vrect.Bottom)
                {
                    points[currentPoint++] = new PointF(vrect.Right, (float)y);
                }
                if (currentPoint < 2)
                {
                    double x = (-c - b * vrect.Top) / a;
                    if (x >= vrect.Left && x <= vrect.Right)
                    {
                        points[currentPoint++] = new PointF((float)x, vrect.Top);
                    }
                    if (currentPoint < 2)
                    {
                        x = (-c - b * vrect.Bottom) / a;
                        if (x >= vrect.Left && x <= vrect.Right)
                        {
                            points[currentPoint++] = new PointF((float)x, vrect.Bottom);
                        }
                    }
                }
                _neuronLines.Data.Add(points[0]);
                _neuronLines.Data.Add(points[1]);

                /*_neuronLines.Data.Add(new PointF(i / 10f, i / 10f));
                 * _neuronLines.Data.Add(new PointF(i / 10f + 0.1f, i / 10f));*/
            }
        }