//Back Propagate for Hidden Neuron public int BackPropag(main.Network net, int mPos, double learnRate) { this.dE_over_dOut = 0; if (this.actFunc == actFuncType.logistic) { for (int i = 0; i < net.numNeuronsEachLayer[layer + 1]; i++) { //if (net[i, this.layer + 1].weights[mPos] != 0) //{ Neuron outNeuron = net.nNarray[i, this.layer + 1]; this.dE_over_dOut += outNeuron.dE_over_dOut * outNeuron.dOut_over_dNet * outNeuron.weights[mPos]; //} } this.dOut_over_dNet = this.postActOutput * (1 - this.postActOutput); for (int i = 0; i < this.inputs.Count; i++) { this.dNet_over_dW.Add(this.inputs[i]); this.dE_over_dW.Add(this.dE_over_dOut * this.dOut_over_dNet * this.dNet_over_dW[i]); this.newWeights.Add(this.weights[i] - learnRate * this.dE_over_dW[i]); } return(0); } else { //return -1; throw new Exception("Activation function not ready for back propagation."); } }
//Minimal Hidden or Output Neuron Initializing Constructor public Neuron(main.Network inNet, List <List <int> > inInputNs, int inLayer) { this.inputNeurons = inInputNs; this.layer = inLayer; this.weights = new List <double>(); for (int i = 0; i < inNet.numNeuronsEachLayer[inLayer - 1]; i++) { if (inNet.nNarray[i, inLayer - 1] != null) { this.weights.Add(DEFAULT_WEIGHT); } else { this.weights.Add(0f); } } }