Example #1
0
        private double[] GetResultVector(NeuralNetworkObj neuralNetworkObj)
        {
            double[] result = new double[neuralNetworkObj.GetLastLayer().GetCountNeurons()];

            List <NeuronObj> neurons = neuralNetworkObj.GetLastLayer().GetListNeurons();

            for (int i = 0; i < neurons.Count; i++)
            {
                result[i] = neurons[i].GetOutputData();
            }

            return(result);
        }
        public int GetAnswer(double[] inputVector)
        {
            if (inputVector.Length != INPUT_VECTOR_LENGTH)
            {
                throw new Exception("Invalid input vector length.");
            }

            NeuralNetworkObj neuralNetwork = this.GetNeuralNetwork();

            neuralNetwork.SetInputVector(inputVector);
            neuralNetwork.Process();

            if (neuralNetwork.GetLastLayer().GetNeuronById(1).GetOutputData() >= MIN_CORRECT_ANSWER)
            {
                return(1);
            }

            return(0);
        }
Example #3
0
        private void educateNetworkButton_Click(object sender, EventArgs e)
        {
            UncertaintyPropagationMethod  uncertaintyPropagationMethod  = new UncertaintyPropagationMethod(LEARNING_RATE);
            NumberRecognizerNeuralNetwork numberRecognizerNeuralNetwork = new NumberRecognizerNeuralNetwork(this.neuralNetwork);

            MachineLearning.NeuralNetwork.Report.Manager reportManager = new MachineLearning.NeuralNetwork.Report.Manager();

            NeuralNetworkObj neuralNetworkObj = numberRecognizerNeuralNetwork.GetNeuralNetwork();

            var prepareData = this.GetPrepareData(neuralNetworkObj.GetLastLayer().GetCountNeurons());
            int countEpoch  = Convert.ToInt16(educateNetworkNumericUpDown.Value);

            for (int epoch = 0; epoch < countEpoch; epoch++)
            {
                reportManager.AddDataBeforeEducate(neuralNetworkObj, prepareData);

                for (int iteration = 0; iteration < COUNT_ITERATION; iteration++)
                {
                    foreach (var entity in prepareData)
                    {
                        double[] inputVector          = entity.Key;
                        double[] expectedResultVector = entity.Value;

                        neuralNetworkObj = uncertaintyPropagationMethod.GetTaughtNeuralNetwork(
                            numberRecognizerNeuralNetwork.GetNeuralNetwork(),
                            inputVector,
                            expectedResultVector
                            );
                    }
                }

                educateNetworkProgressBar.Value = Convert.ToInt16((epoch + 1.0) / countEpoch * 100);

                reportManager.AddDataAfterEducate(neuralNetworkObj, prepareData);
                reportManager.SaveReport(neuralNetworkObj);

                neuralNetworkObj.EpochPassed();
            }

            numberRecognizerNeuralNetwork.UpdateNeuralNetwork(neuralNetworkObj);
        }
        public int GetNumberFromImgVector(double[] inputVector)
        {
            if (inputVector.Length != this.countNeuronsInFirstLayer)
            {
                throw new Exception("Invalid input vector length.");
            }

            NeuralNetworkObj neuralNetworkObj = this.GetNeuralNetwork();

            neuralNetworkObj.Clear();
            neuralNetworkObj.SetInputVector(inputVector);
            neuralNetworkObj.Process();

            foreach (NeuronObj neuron in neuralNetworkObj.GetLastLayer().GetListNeurons())
            {
                if (neuron.GetOutputData() > MINIMUM_OUTPUT_DATA_FOR_SUCCESS_RESULT)
                {
                    return(neuron.Id);
                }
            }

            return(-1);
        }