Beispiel #1
0
        private void BuildGrids()
        {
            MlpNetwork network = _programLogic.ExaminedNetwork;

            BuildGridColumns(uiInputData, network.InputCount + 1);
            uiInputData.Rows.Add(2);
            uiInputData.Rows[0].Cells[0].Value = "Input number (i)";
            uiInputData.Rows[1].Cells[0].Value = "Original inputs (u(i))";
            uiInputData.Rows[2].Cells[0].Value = "Normalized inputs (x(i))";
            BuildGridColumns(uiTeachingProgress, network.OutputCount + 1);
            uiTeachingProgress.Rows.Add(5);
            uiTeachingProgress.Rows[0].Cells[0].Value = "Output number (j)";
            uiTeachingProgress.Rows[1].Cells[0].Value = "Value before teaching (y(j))";
            uiTeachingProgress.Rows[2].Cells[0].Value = "Value expected (z(j))";
            uiTeachingProgress.Rows[3].Cells[0].Value = "Error before teaching (e(j))";
            uiTeachingProgress.Rows[4].Cells[0].Value = "Value after teaching (y'(j))";
            uiTeachingProgress.Rows[5].Cells[0].Value = "Error after teaching (e'(j))";
            for (int i = 1; i < uiTeachingProgress.ColumnCount; i++)
            {
                DataGridViewCellStyle style =
                    uiTeachingProgress.Rows[2].Cells[i].Style;
                style.BackColor = style.SelectionBackColor = Color.LightGreen;
                style           = uiTeachingProgress.Rows[3].Cells[i].Style;
                style.BackColor = style.SelectionBackColor = Color.Pink;
                style           = uiTeachingProgress.Rows[5].Cells[i].Style;
                style.BackColor = style.SelectionBackColor = Color.Pink;
            }
        }
Beispiel #2
0
        internal void LoadTeachingSet(string fileName)
        {
            TeachingSet tset = NeuralNetworks.TeachingSet.FromFile(fileName);

            if (tset == null || tset.Count == 0)
            {
                throw new ApplicationException("The file does not contain any data.");
            }
            _teachingSetFileName   = fileName;
            _teachingSet           = tset;
            _normalizedTeachingSet = new TeachingSet(tset);
            _normalizedTeachingSet.Normalize();
            _examinedNetwork = new MlpNetwork(tset.InputCount, false,
                                              new int[] { tset.OutputCount }, typeof(BipolarNeuron));
            InitializeTeaching();
        }
Beispiel #3
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();
        }
Beispiel #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));*/
            }
        }