private string GetNeuronInfo(int layerID, int positionID) { AnnNeuron neuron = Net.NetLayers[layerID][positionID]; string message = "Neuron" + "\n"; message += "Layer / NeuronID: " + layerID + " / " + positionID + "\n"; message += "Input: " + neuron.Input + "\n"; message += "Output: " + neuron.Output + "\n"; message += "Activation Function: " + neuron.ActivationFunction.ActivationFunctionType + "\n"; return(message); }
private double BackPropSingleDataSet(double[] sampleDataSet, double[] targetDataSet) { AnnFeedForward feedForwardModel = new AnnFeedForward(net); feedForwardModel.FeedForward(sampleDataSet); int outputLayerID = net.NetLayers.Length - 1; double[] errors = new double[net.NetLayers[outputLayerID].Length]; // calculate output deltas for (int outNeuronID = 0; outNeuronID < net.NetLayers[outputLayerID].Length; outNeuronID++) { AnnNeuron neuron = net.NetLayers[outputLayerID][outNeuronID]; double derivAFOutput = neuron.ActivationFunction.GetAFDerivValue(neuron.Input); double outputScalar = neuron.ActivationFunction.Scalar; double derivError = -(targetDataSet[outNeuronID] / outputScalar - neuron.Output / outputScalar); if (targetDataSet[outNeuronID] != 0) { errors[outNeuronID] += (targetDataSet[outNeuronID] - neuron.Output) / targetDataSet[outNeuronID]; } else { errors[outNeuronID] += 0; } neuron.BackPropDelta = derivAFOutput * derivError; } // calculate remaining deltas for (int layerID = outputLayerID - 1; layerID > 0; layerID--) { for (int neuronID = 0; neuronID < net.NetLayers[layerID].Length; neuronID++) { net.NetLayers[layerID][neuronID].BackPropDeltaUpdate(); } } // add delta * input neuron output to the synapse deltainput list for (int synapseID = 0; synapseID < net.SynapsesAll.Count; synapseID++) { AnnSynapse synapse = net.SynapsesAll[synapseID]; synapse.DeltaInputAdd(synapse.OutputNeuron.BackPropDelta * synapse.InputNeuron.Output); } return(MaxPercentageError(errors)); }