public void preparePointList(TrainingResultP trainingResult, TrainingSetings.ActiviationFunction activationFunction)
        {
            float x1 = 0.01f;
            float x2 = 0.01f;

            for (int x = 0; x <= 100; x++)
            {
                x2 = 0.01f;
                for (int y = 0; y <= 100; y++)
                {
                    PointInfo point = preparePoint(trainingResult, x1, x2, activationFunction);

                    if (point.color == 0.00f)
                    {
                        list0.Add(point);
                    }
                    else
                    {
                        list1.Add(point);
                    }

                    x2 += 0.01f;
                }

                x1 += 0.01f;
            }
        }
Example #2
0
        private void TrainingStartButton_Click(object sender, EventArgs e)
        {
            Debug.WriteLine("Click");
            try
            {
                trainingSetings.learningRate = float.Parse(LearningRateTB.Text, CultureInfo.InvariantCulture);
                trainingSetings.maxError     = float.Parse(MaxErrorTB.Text, CultureInfo.InvariantCulture);

                Debug.WriteLine("Jestem w try");

                if (trainingSetings.gateType == TrainingSetings.GateType.XOR)
                {
                    Debug.WriteLine("Xor training in Form1");
                    xorTrResult = trainingService.trainXOR(trainingSetings, gateTrValuesContainer);
                    showTrainingRaport(xorTrResult.raport);
                }
                else
                {
                    trainingResult = trainingService.train(trainingSetings, gateTrValuesContainer);
                    showTrainingRaport(trainingResult.raport);
                }
            }
            catch (NotImplementedException exception)
            {
                MessageBox.Show(exception.Message);
            }
            catch (ArgumentException exception)
            {
                MessageBox.Show(exception.Message);
            }
            catch (FormatException exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        public void showChart(TrainingResultP trainingResult, TrainingSetings trainSettings)
        {
            list0 = new List <PointInfo>();
            list1 = new List <PointInfo>();
            activatonFunctions.maxError = trainSettings.maxError;

            preparePointList(trainingResult, trainSettings.activiationFunction);

            float[,] table0 = changeListToArray(list0);
            float[,] table1 = changeListToArray(list1);

            ChartForm chartForm = new ChartForm(table0, table1);

            chartForm.Show();
        }
        public PointInfo preparePoint(TrainingResultP trainingResult, float x, float y, TrainingSetings.ActiviationFunction activiationFunction)
        {
            float e      = x * trainingResult.w1 + y * trainingResult.w1 + trainingResult.biasI;
            float result = 0.00f;


            if (activiationFunction == TrainingSetings.ActiviationFunction.JUMP)
            {
                result = activatonFunctions.jumpActivationFuntion(e);
            }
            else
            {
                result = activatonFunctions.sigmoidActivationFunction(e);
                result = activatonFunctions.correctionForSigmoid(result);
            }

            return(new PointInfo(x, y, result));
        }
        private void trainByOneNeuron(ActivatonFunctions.Del activationFunction)
        {
            if (trainingSetings.gateType == TrainingSetings.GateType.XOR)
            {
                throw new NotImplementedException("Brak możliwości trenowanie XOR jednym nuronem");
            }

            tResult = new TrainingResultP();
            firstLineBuilder.Append(" pojedynczy neuron.");

            tResult.raport.Add(firstLineBuilder.ToString());

            bool   isWeightChanged = true;
            Random random          = new Random();

            float w1   = (float)random.NextDouble();
            float w2   = (float)random.NextDouble();
            float bias = 1.00f;
            float e    = 0.00f;
            float y    = 0.00f;

            tResult.raport.Add("Początkowe w1: " + w1);
            tResult.raport.Add("Początkowe w2: " + w2);
            tResult.raport.Add("Początkowy bias: " + bias);


            List <float> desireResults = valuesContainer.results[trainingSetings.gateType.ToString()];

            if (desireResults == null)
            {
                Debug.WriteLine("DesireResults jest nullem");
            }
            else
            {
                Debug.WriteLine("desireResults");
                foreach (float result in desireResults)
                {
                    Debug.WriteLine(result);
                }
            }

            Debug.WriteLine("Typ bramki do szkolenia: " + trainingSetings.gateType);
            Debug.WriteLine("Funkcja aktywacyjna: " + trainingSetings.activiationFunction);


            int epochs = 0;

            while (isWeightChanged)
            {
                isWeightChanged = false;
                epochs++;

                for (int i = 0; i < valuesContainer.x1Values.Count; i++)
                {
                    e = w1 * valuesContainer.x1Values[i] + w2 * valuesContainer.x2Values[i] + bias;
                    y = activationFunction(e);
                    y = activationFunctions.correctionForSigmoid(y);

                    if (y != desireResults[i])
                    {
                        tResult.raport.Add("");
                        tResult.raport.Add("desire = " + desireResults[i] + ", y = " + y + ", e: " + e);
                        tResult.raport.Add("Zmiana w1, w2, bias");

                        w1   = w1 + trainingSetings.learningRate * (desireResults[i] - y) * valuesContainer.x1Values[i];
                        w2   = w2 + trainingSetings.learningRate * (desireResults[i] - y) * valuesContainer.x2Values[i];
                        bias = bias + trainingSetings.learningRate * (desireResults[i] - y);

                        tResult.raport.Add("w1: " + w1);
                        tResult.raport.Add("w2: " + w2);
                        tResult.raport.Add("bias: " + bias);

                        isWeightChanged = true;
                    }
                }
            }

            tResult.w1    = w1;
            tResult.w2    = w2;
            tResult.biasI = bias;

            tResult.raport.Add("Finalne w1: " + w1);
            tResult.raport.Add("Finalene w2: " + w2);
            tResult.raport.Add("Finalne bias: " + bias);
            tResult.raport.Add("Liczba epok: " + epochs);
        }