1 namespace SpikingNeuronNetwork.Lib
5 using System.Collections.Generic;
24 public double GetError(List<Spike> desiredOutputSpikes, List<Spike> actualOutputSpikes)
26 if (desiredOutputSpikes.Count > actualOutputSpikes.Count)
28 throw new ArgumentException(
"Desired Spikes Count Must Not Be Greater Than The Actual Spike Count To Calculate Error");
31 if (actualOutputSpikes.Count > desiredOutputSpikes.Count)
33 actualOutputSpikes = actualOutputSpikes.Take(desiredOutputSpikes.Count).ToList();
36 desiredOutputSpikes = desiredOutputSpikes.OrderBy(x => x.Time).ToList();
37 desiredOutputSpikes = desiredOutputSpikes.OrderBy(x => x.NeuronIndex).ToList();
38 actualOutputSpikes = actualOutputSpikes.OrderBy(x => x.Time).ToList();
39 actualOutputSpikes = actualOutputSpikes.OrderBy(x => x.NeuronIndex).ToList();
42 for (var j = 0; j < desiredOutputSpikes.Count; j++)
44 if (desiredOutputSpikes[j].NeuronIndex != actualOutputSpikes[j].NeuronIndex)
46 throw new ArgumentException(
"Desired and Actual Spikes Counts On Each Neuron Must Be Equal To Calculate Error");
48 error += Math.Pow(desiredOutputSpikes[j].Time - actualOutputSpikes[j].Time, 2);
61 if (desiredOutputSpikes.Count > actualOutputSpikes.Count)
63 throw new ArgumentException(
"Desired Spike Count Must Not Be Greater Than the Actual Spike Count To Calculate Error");
66 if (actualOutputSpikes.Count > desiredOutputSpikes.Count)
68 actualOutputSpikes = actualOutputSpikes.Take(desiredOutputSpikes.Count).ToList();
71 var errorDerivatives =
new List<double>();
74 const double offset = 1e-4;
75 foreach (var actualOutputSpike
in actualOutputSpikes)
77 actualOutputSpike.Time -= offset;
78 var error1 = GetError(desiredOutputSpikes, actualOutputSpikes);
79 actualOutputSpike.Time += 2*offset;
80 var error2 = GetError(desiredOutputSpikes, actualOutputSpikes);
81 actualOutputSpike.Time -= offset;
82 errorDerivatives.Add((error2-error1)/(2*offset));
87 desiredOutputSpikes = desiredOutputSpikes.OrderBy(x => x.Time).ToList();
88 desiredOutputSpikes = desiredOutputSpikes.OrderBy(x => x.NeuronIndex).ToList();
89 actualOutputSpikes = actualOutputSpikes.OrderBy(x => x.Time).ToList();
90 actualOutputSpikes = actualOutputSpikes.OrderBy(x => x.NeuronIndex).ToList();
92 for (var j = 0; j < desiredOutputSpikes.Count; j++)
94 if (desiredOutputSpikes[j].NeuronIndex != actualOutputSpikes[j].NeuronIndex)
96 throw new ArgumentException(
"Desired and Actual Spikes Counts On Each Neuron Must Be Equal To Calculate Error");
98 errorDerivatives.Add(actualOutputSpikes[j].Time - desiredOutputSpikes[j].Time);
102 return errorDerivatives;
double GetError(List< Spike > desiredOutputSpikes, List< Spike > actualOutputSpikes)
Get the sum of squared spiking error between the desired and actual output spike trains ...
SimulationMethod
Simulation Method Enum
List< double > GetErrorToOutputSpikeTimeDerivative(List< Spike > desiredOutputSpikes, List< Spike > actualOutputSpikes)
Get the error to output spike time derivatives
Sum of Squared Spiking Error Class