Ejemplo n.º 1
0
        public double[,] matrixSum(double[,] mat1, double[,] mat2)
        {
            int rowMatr1 = mat1.GetLength(0);
            int colMatr1 = mat1.GetLength(1);
            int rowMatr2 = mat2.GetLength(0);
            int colMatr2 = mat2.GetLength(1);

            //Console.WriteLine("MatrixSum Matrix1[" + rowMatr1+","+colMatr1+"]");
            //Console.WriteLine("MatrixSum Matrix2[" + rowMatr2 + "," + colMatr2 + "]");

            double[,] resMatr = new double[rowMatr1, colMatr2];
            if (rowMatr1 == rowMatr2 && colMatr1 == colMatr2)
            {
                for (int i = 0; i < rowMatr1; i++)
                {
                    for (int j = 0; j < colMatr1; j++)
                    {
                        resMatr[i, j] = mat1[i, j] + mat2[i, j];
                    }
                }
            }
            else
            {
                errorForm = new ErrorForm();
                errorForm.setError("Matrix kann nicht Addiert werden!");
                //Console.WriteLine("Matrix können nicht addiert werden! 1");
                errorForm.Visible = true;
            }
            return(resMatr);
        }
Ejemplo n.º 2
0
        public double[] vectoradd_sub(double[] vec1, double[] vec2, bool addition)
        {
            int colVec1 = vec1.GetLength(0);
            int colVec2 = vec2.GetLength(0);

            //Console.WriteLine("vectoradd_sub Vec1[" + colVec1 + "]");
            //Console.WriteLine("vectoradd_sub Vec2[" + colVec2 + "]");
            double[] resVec = new double[colVec1];
            if (colVec1 == colVec2)
            {
                for (int i = 0; i < colVec1; i++)
                {
                    if (addition == true)
                    {
                        resVec[i] = vec1[i] + vec2[i];
                    }
                    else
                    {
                        resVec[i] = vec1[i] - vec2[i];
                    }
                }
            }
            else
            {
                errorForm = new ErrorForm();
                errorForm.setError("Vektoren können nicht addiert werden!");
                //Console.WriteLine("Vektoren können nicht addiert werden! 1");
                errorForm.Visible = true;
            }
            return(resVec);
        }
Ejemplo n.º 3
0
        public double[] matrixMult(double[,] matr1, double[] matr2)
        {
            int rowMatr1 = matr1.GetLength(0);
            int colMatr1 = matr1.GetLength(1);
            int rowMatr2 = matr2.GetLength(0);
            //Console.WriteLine("MatrixMult Matrix1[" + rowMatr1+","+ colMatr1+"]");
            //Console.WriteLine("MatrixMult Matix2[" + rowMatr2+"]");
            double temp = 0;

            double[] resMatr = new double[rowMatr1];
            if (colMatr1 != rowMatr2)
            {
                errorForm = new ErrorForm();
                errorForm.setError("2 Matrix kann nicht multipliziert werden!");
                //Console.WriteLine("2 Matrix kann nicht multipliziert werden!");
                errorForm.Visible = true;
            }
            else
            {
                for (int i = 0; i < rowMatr1; i++)
                {
                    temp = 0;
                    for (int k = 0; k < rowMatr2; k++)
                    {
                        temp += matr1[i, k] * matr2[k];
                    }
                    resMatr[i] = temp;
                }
            }
            return(resMatr);
        }
Ejemplo n.º 4
0
        private void readInputs()
        {
            inputs = new double[inodes];
            string input;
            bool   error = false;

            for (int i = 0; i < inodes; i++)
            {
                if (dataGridView1.Rows[i].Cells[0].Value != null)
                {
                    input     = dataGridView1.Rows[i].Cells[0].Value.ToString();
                    inputs[i] = Convert.ToDouble(input);
                    //Console.WriteLine("input : " + inputs[i]);
                }
                else
                {
                    error = true;
                }
            }
            if (error == true)
            {
                errorForm = new ErrorForm();
                errorForm.setError("Kein Inputs vorhanden");
                errorForm.Visible = true;
            }
        }
Ejemplo n.º 5
0
        public double[] vectorMult(double[] vec1, double[] vec2)
        {
            int colVec1 = vec1.GetLength(0);
            int colVec2 = vec2.GetLength(0);

            //Console.WriteLine("Vector1[" + colVec1 + "]");
            //Console.WriteLine("Vector2[" + colVec2 + "]");
            double[] resVec = new double[colVec1];

            if (colVec1 == colVec2)
            {
                for (int i = 0; i < colVec1; i++)
                {
                    resVec[i] = vec1[i] * vec2[i];
                }
            }
            else
            {
                errorForm = new ErrorForm();
                errorForm.setError("Vektoren können nicht multipliziert werden!");
                //Console.WriteLine("Vektoren können nicht multipliziert werden!");
                errorForm.Visible = true;
            }
            return(resVec);
        }
Ejemplo n.º 6
0
 // Train Network
 private void button2_Click(object sender, EventArgs e)
 {
     if (nn3SO == null)
     {
         errorForm = new ErrorForm();
         errorForm.setError("Kein Netz gefunden");
         errorForm.Visible = true;
     }
     else
     {
         targets = new double[onodes];
         string target;
         bool   error = false;
         if (checkBox1.Checked)
         {
             for (int i = 0; i < onodes; i++)
             {
                 if (dataGridView1.Rows[i].Cells[6].Value != null)
                 {
                     target     = dataGridView1.Rows[i].Cells[6].Value.ToString();
                     targets[i] = Convert.ToDouble(target);
                     // Console.WriteLine("input : " + targets[i]);
                 }
                 else
                 {
                     error = true;
                 }
             }
             readInputs();
             if (error == false)
             {
                 nn3SO.train(inputs, targets);
                 displayResults();
             }
             else
             {
                 errorForm = new ErrorForm();
                 errorForm.setError("Keine Targets gefunden");
                 errorForm.Visible = true;
             }
         }
         else
         {
             if (Properties.Settings.Default.ReadAsync == true)
             {
                 //Console.WriteLine("Async");
                 _ = ProcessReadAsync(true);
             }
             else
             {
                 for (int i = 0; i < (int)numericUpDown1.Value; i++)
                 {
                     readData(true);
                     displayResults();
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
        // Query Network
        private void button3_Click(object sender, EventArgs e)
        {
            if (nn3SO == null)
            {
                errorForm = new ErrorForm();
                errorForm.setError("Kein Netz gefunden");
                errorForm.Visible = true;
            }
            else
            {
                if (checkBox1.Checked)
                {
                    if (checkBox3.Checked)
                    {
                        zeichnen.queryZeichnung();
                        if (zeichnen.Input != null)
                        {
                            if (zeichnen.CheckColor == true)
                            {
                                int target = readInputs(zeichnen.Input, true);
                                for (int i = 0; i < onodes; i++)
                                {
                                    targets[i] = 0.01;
                                }

                                targets[target] = 0.99;
                                nn3SO.queryNN(inputs);
                                displayResults();
                                performance(target);
                                zeichnen.CheckColor = false;
                            }
                            else
                            {
                                errorForm = new ErrorForm();
                                errorForm.setError("Es wurde kein Zeichen im Zeichenfeld gefunden!");
                                errorForm.Visible = true;
                            }
                        }
                        else
                        {
                            errorForm = new ErrorForm();
                            errorForm.setError("Kein Bild gefunden!");
                            errorForm.Visible = true;
                        }
                    }
                    else
                    {
                        readInputs();
                        nn3SO.queryNN(inputs);
                        displayResults();
                    }
                    anzahlquery++;
                }
                else
                {
                    readData(false);
                }
            }
        }
Ejemplo n.º 8
0
        private async Task ProcessReadAsync(bool train)
        {
            if (File != null)
            {
                for (int n = 0; n < (int)numericUpDown1.Value; n++)
                {
                    StreamReader sr = new StreamReader(File);
                    string       line;
                    int          intTarget;

                    progressBar1.Maximum = System.IO.File.ReadAllLines(File).Length;
                    // Console.WriteLine(System.IO.File.ReadAllLines(File).Length);
                    progressBar1.Visible = true;
                    progressBar1.Step    = 1;
                    progressBar1.Value   = 0;
                    int uj = 0;
                    while ((line = await sr.ReadLineAsync()) != null && (line != ""))
                    {
                        //Console.WriteLine(uj);
                        uj++;
                        //Console.WriteLine(line);
                        intTarget = readInputs(line, false);
                        for (int i = 0; i < onodes; i++)
                        {
                            targets[i] = 0.01;
                        }
                        targets[intTarget] = 0.99;

                        if (train == true)
                        {
                            nn3SO.train(inputs, targets);
                            displayResults();
                        }
                        else
                        {
                            nn3SO.queryNN(inputs);
                            displayResults();
                        }

                        if (checkBox2.Checked)
                        {
                            MessageBox.Show("Next");
                        }
                        progressBar1.PerformStep();
                    }
                    progressBar1.Visible = false;
                    progressBar1.Value   = 0;
                }
            }
            else
            {
                errorForm = new ErrorForm();
                errorForm.setError("Keine Daten vorhanden!");
                errorForm.Visible = true;
            }
        }
Ejemplo n.º 9
0
 private void weightMatritzenToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (nn3SO != null)
     {
         weightForm = new WeightMatrForm();
         weightForm.viewMatr(nn3SO.WIH, nn3SO.WHO, nn3SO.WeightList);
         weightForm.Visible = true;
     }
     else
     {
         errorForm = new ErrorForm();
         errorForm.setError("Kein Netz gefunden");
         errorForm.Visible = true;
     }
 }
Ejemplo n.º 10
0
        private void readMatrData()
        {
            if (matrFile != null)
            {
                StreamReader  sr = new StreamReader(matrFile);
                string        line;
                List <string> inputlist = new List <string>();
                int           i, j;
                double[,] matrix;

                progressBar1.Maximum = System.IO.File.ReadAllLines(matrFile).Length;
                // Console.WriteLine(System.IO.File.ReadAllLines(matrFile).Length);
                progressBar1.Visible = true;
                progressBar1.Step    = 1;
                progressBar1.Value   = 0;
                while ((line = sr.ReadLine()) != null && (line != ""))
                {
                    string[] input;
                    input = line.Split('.');
                    for (i = 0; i < input.Length; i++)
                    {
                        //Console.WriteLine(input[i]);
                        inputlist.Add(input[i]);
                    }
                    progressBar1.PerformStep();
                }
                if (inputlist[0].Equals("Neuronales Netz von Arne Brandt: Matritzen"))
                {
                    hiddenLayers = Convert.ToInt32(inputlist[1]);
                    //  Console.WriteLine("hidden " + hiddenLayers);
                    hnodes = Convert.ToInt32(inputlist[2]);
                    //  Console.WriteLine("hnodes " + hnodes);
                    inodes = Convert.ToInt32(inputlist[3]);
                    onodes = Convert.ToInt32(inputlist[4]);
                    createNetwork();
                    // Console.WriteLine("count " + inputlist.Count());
                    targets = new double[onodes];

                    int z = 6;

                    progressBar1.Maximum = hnodes * inodes;
                    progressBar1.Value   = 0;
                    for (i = 0; i < hnodes; i++)
                    {
                        for (j = 0; j < inodes; j++)
                        {
                            nn3SO.WIH[i, j] = Convert.ToDouble(inputlist[z]);
                            z++;
                            progressBar1.PerformStep();
                        }
                    }
                    progressBar1.Maximum = onodes * hnodes;
                    progressBar1.Value   = 0;
                    for (i = 0; i < onodes; i++)
                    {
                        for (j = 0; j < hnodes; j++)
                        {
                            nn3SO.WHO[i, j] = Convert.ToDouble(inputlist[z]);
                            z++;
                            progressBar1.PerformStep();
                        }
                    }

                    progressBar1.Value = 0;
                    if (hiddenLayers != 0)
                    {
                        nn3SO.WeightList.Clear();
                        progressBar1.Maximum = hnodes * hnodes * hiddenLayers;
                    }
                    else
                    {
                        progressBar1.Maximum = hnodes * hnodes;
                    }

                    for (int k = 0; k < hiddenLayers; k++)
                    {
                        matrix = new double[hnodes, hnodes];
                        for (i = 0; i < hnodes; i++)
                        {
                            for (j = 0; j < hnodes; j++)
                            {
                                matrix[i, j] = Convert.ToDouble(inputlist[z]);
                                z++;
                                progressBar1.PerformStep();
                            }
                        }
                        nn3SO.WeightList.Add(matrix);
                    }

                    progressBar1.Value   = 0;
                    progressBar1.Visible = false;
                }
                else
                {
                    progressBar1.Value   = 0;
                    progressBar1.Visible = false;
                    errorForm            = new ErrorForm();
                    errorForm.setError("Die ausgewählte Datei hat ein falsches Format!");
                    errorForm.Visible = true;
                }
            }
        }