Esempio n. 1
0
        private void learnFromData()
        {
            int    nbError   = 1;
            int    totalErr  = 0;
            int    totalTest = 0;
            int    count     = 0;
            int    cste      = 1;
            double w1        = sP.getWeightEntry(0);
            double w2        = sP.getWeightEntry(1);
            double w3        = sP.getWeightEntry(2);

            while (nbError != 0 && ++count < 1000000)
            {
                nbError = 0;
                for (int i = 0; i < data[0].Count; i += 2)
                {
                    totalTest++;
                    double sA = sP.calculOut(data[0][i], data[0][i + 1], cste);
                    double sB = sP.calculOut(data[1][i], data[1][i + 1], cste);
                    if (sA < 1)
                    {
                        sP.addWeightEntry(0, data[0][i]);
                        sP.addWeightEntry(1, data[0][i + 1]);
                        sP.addWeightEntry(2, cste);
                        nbError++;
                    }
                    if (sB > 0)
                    {
                        sP.addWeightEntry(0, -data[1][i]);
                        sP.addWeightEntry(1, -data[1][i + 1]);
                        sP.addWeightEntry(2, -cste);
                        nbError++;
                    }
                }
                drawData();
                totalErr += nbError;
            }
            lRes.Text  = "\r\nLearning\r\nNb Error : " + totalErr + "/" + totalTest + "\r\nNb iterations : " + count;
            lRes.Text += "\r\nW1 = " + w1.ToString(doublePrecision) + " -> " + sP.getWeightEntry(0).ToString(doublePrecision) +
                         "\r\nW2 = " + w2.ToString(doublePrecision) + " -> " + sP.getWeightEntry(1).ToString(doublePrecision) +
                         "\r\nW3 = " + w3.ToString(doublePrecision) + " -> " + sP.getWeightEntry(2).ToString(doublePrecision);
            double test1 = sP.calculOut(data[0][0], data[0][1], cste);
            double test2 = sP.calculOut(data[1][0], data[1][1], cste);
        }