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); }
public Synapse(NeuronObj neuronObj, double weight) { NeuronObj = neuronObj; Weight = weight; }
public EducationNeuron(NeuronObj neuronObj) { NeuronObj = neuronObj; }