Ejemplo n.º 1
0
        public AnnVisualizerForm(NeuralNetwork ann)
        {
            _ann = ann;
            InitializeComponent();
            ResizeEnd += AnnVisualizerForm_Resize;
            Paint += AnnVisualizerForm_Paint;

            var tlayer = new NeuralLayer(1);
            Neuron input = new NeuronInput(tlayer, "X");
            tlayer.Neurons.Add(input);
            _transferFunc = new Neuron(tlayer, new NeuralLayer(0), "transfer");
            _transferFunc.Weights[0].X = 1.0;

            Recompute();
        }
Ejemplo n.º 2
0
        void addNeuron(Neuron nn, int X, int Y, int idxNeuron)
        {
            var label = new Label();
            label.AutoSize = true;
            label.Location = new System.Drawing.Point(X, Y);
            label.Name = "label" + idxNeuron.ToString();
            label.Size = new System.Drawing.Size(35, 13);
            label.TabIndex = 0;
            label.Text = nn.Label;
            Controls.Add(label);
            _neuronUIcontrols.Add(label);

            if (nn.GetType() == typeof(NeuronInput) || nn.GetType() == typeof(NeuronBias))
                return;

            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
            var chart = new System.Windows.Forms.DataVisualization.Charting.Chart();
            chartArea1.Name = "ChartArea" + idxNeuron.ToString();
            chartArea1.AxisX.LabelAutoFitMaxFontSize = 5;
            chartArea1.AxisX.Interval = 30.0;
            chartArea1.AxisX.MinorTickMark.Size = 30;
            chartArea1.AxisY.LabelAutoFitMaxFontSize = 5;
            chartArea1.AxisY.Interval = 3.0;
            chartArea1.AxisX.MajorGrid.Enabled = false;
            chartArea1.AxisX.MinorGrid.Enabled = false;
            chartArea1.AxisY.MajorGrid.Enabled = false;
            chartArea1.AxisY.MinorGrid.Enabled = false;
            chart.ChartAreas.Add(chartArea1);
            chart.Location = new System.Drawing.Point(X, Y + 15);
            chart.Name = "chart" + idxNeuron.ToString();
            chart.Size = new System.Drawing.Size(_neuronWidth - 10, _neuronWidth - 10);
            chart.TabIndex = 0;
            chart.Series.Clear();
            var series1 = new System.Windows.Forms.DataVisualization.Charting.Series
            {
                Name = "Series1",
                Color = System.Drawing.Color.LightGray,
                IsVisibleInLegend = false,
                IsXValueIndexed = false,
                ChartType = SeriesChartType.Line
            };
            chart.Series.Add(series1);
            for (double x = -50; x < 50; x++)
                series1.Points.AddXY(x, transferFunc(x));
            var series2 = new System.Windows.Forms.DataVisualization.Charting.Series
            {
                Name = "Series2",
                Color = nn.FirstInputValue < nn.InputValue ? System.Drawing.Color.Red : System.Drawing.Color.Blue,
                IsVisibleInLegend = false,
                IsXValueIndexed = false,
                ChartType = SeriesChartType.Line
            };
            chart.Series.Add(series2);
            double begin = nn.FirstInputValue < nn.InputValue ? nn.FirstInputValue : nn.InputValue;
            double end = nn.FirstInputValue < nn.InputValue ? nn.InputValue : nn.FirstInputValue;
            for (double x = begin; x < end + 1.0; x++)
                series2.Points.AddXY(x, transferFunc(x));
            Controls.Add(chart);
            _neuronUIcontrols.Add(chart);

            var labelW = new Label();
            labelW.AutoSize = true;
            labelW.Location = new System.Drawing.Point(X, Y + _neuronHeight - 15);
            labelW.Name = "labelW" + idxNeuron.ToString();
            labelW.Size = new System.Drawing.Size(_neuronWidth, 13);
            labelW.TabIndex = 0;
            labelW.Font = new Font(labelW.Font.FontFamily, 7.0f);
            foreach(var w in nn.Weights)
                labelW.Text += string.Format("{0:F2};", w.X);
            if (nn.Weights.Count > 0)
                labelW.Text = labelW.Text.Substring(0, labelW.Text.Length - 1);
            Controls.Add(labelW);
            _neuronUIcontrols.Add(labelW);
        }
Ejemplo n.º 3
0
 void updateNeuron(Neuron nn, int X, int Y, int idxNeuron)
 {
     Label labelW = findWeightLabelOrig(idxNeuron);
     if (labelW != null)
     {
         labelW.Text = "";
         foreach (var w in nn.Weights)
             labelW.Text += string.Format("{0:F2};", w.X);
         if (nn.Weights.Count > 0)
             labelW.Text = labelW.Text.Substring(0, labelW.Text.Length - 1);
     }
     Chart chart = findChart(idxNeuron);
     if (chart != null)
     {
         chart.Series["Series2"].Points.Clear();
         chart.Series["Series2"].Color = nn.FirstInputValue < nn.InputValue ? System.Drawing.Color.Red : System.Drawing.Color.Blue;
         double begin = nn.FirstInputValue < nn.InputValue ? nn.FirstInputValue : nn.InputValue;
         double end = nn.FirstInputValue < nn.InputValue ? nn.InputValue : nn.FirstInputValue;
         for (double x = begin; x < end + 1.0; x++)
             chart.Series["Series2"].Points.AddXY(x, transferFunc(x));
     }
 }