示例#1
0
        public NeuralNetworkObj GetTaughtNeuralNetwork(NeuralNetworkObj neuralNetworkObj, double[] inputVector, double[] expectedResultVector)
        {
            double[] resultVector = this.GetResultVector(neuralNetworkObj, inputVector);

            List <EducationLayer> educationNetwork = this.GetEducationNetwork(neuralNetworkObj);

            for (int educationLayerId = educationNetwork.Count - 1; educationLayerId >= 0; educationLayerId--)
            {
                EducationLayer educationLayer = educationNetwork[educationLayerId];
                foreach (EducationNeuron educationNeuron in educationLayer.GetListNeurons())
                {
                    NeuronObj neuron = educationNeuron.NeuronObj;
                    if (neuron.IsInLastLayer())
                    {
                        //deltaWeight0 = (OUT(ideal) - OUT(actual)) * f'(IN)
                        educationNeuron.WeightDelta = (expectedResultVector[neuron.Id] - resultVector[neuron.Id]) * activationFunc.GetDerivativeValue(neuron.GetInputData());
                    }
                    else
                    {
                        //deltaWeightH = f'(IN) * sum(Wi * delataWeighti)
                        double sumWeightDeltaInNextLayer = 0;
                        foreach (EducationSynapse educationSynapse in educationNeuron.GetEducationSynapses())
                        {
                            sumWeightDeltaInNextLayer += educationSynapse.Synapse.Weight * educationSynapse.EducationNeuron.WeightDelta;
                        }

                        educationNeuron.WeightDelta = this.activationFunc.GetDerivativeValue(neuron.GetInputData()) * sumWeightDeltaInNextLayer;

                        foreach (EducationSynapse educationSynapse in educationNeuron.GetEducationSynapses())
                        {
                            //grad(A, B) = deltaWeight(B) * OUT(A)
                            double grad = educationSynapse.EducationNeuron.WeightDelta * educationNeuron.NeuronObj.GetOutputData();
                            educationSynapse.Synapse.Weight += this.learningRate * grad;//todo moment a*deltaWi
                        }
                    }
                }
            }

            return(neuralNetworkObj);
        }
示例#2
0
 public Synapse(NeuronObj neuronObj, double weight)
 {
     NeuronObj = neuronObj;
     Weight    = weight;
 }
示例#3
0
 public EducationNeuron(NeuronObj neuronObj)
 {
     NeuronObj = neuronObj;
 }