1 namespace SpikingNeuronNetwork.Test
5 using Microsoft.VisualStudio.TestTools.UnitTesting;
7 using System.Collections.Generic;
18 public static double Epsilon = 1e-4;
28 public static void CompareSpikeTrains(IReadOnlyCollection<Spike> spikeTrain1, IReadOnlyList<Spike> spikeTrain2,
double threshold)
31 Assert.AreEqual(spikeTrain1.Count, spikeTrain2.Count,
32 "The Two Spike Trains Contain Different Numbers of Spikes! Unable to Compare.\n\tTrain 1: " + String.Join(
", ", spikeTrain1) +
"\n\tTrain 2: " + String.Join(
", ", spikeTrain2));
34 if (spikeTrain1.Count == 0)
36 Console.WriteLine(
"The Two Spike Trains Produced No Output Spikes!");
41 double meanSquaredError = 0;
43 spikeTrain1.Select((t, j) => Math.Pow(t.Time - spikeTrain2[j].Time, 2)).Sum();
44 meanSquaredError /= spikeTrain1.Count;
45 Assert.IsTrue(meanSquaredError < threshold,
46 "Output Spike Mean-Squared Error Between The Two Spike Trains is greater than " + threshold);
47 Console.WriteLine(
"Output Spike Mean-Squared Error Between The Two Spike Trains: ");
48 Console.WriteLine(
"\t" + meanSquaredError);
63 inputSpikeTimes.RemoveAll(x => x.NeuronIndex >= neuron.NumInputs);
66 Console.WriteLine(neuron);
69 neuron.Method = SimulationMethod.Numerical;
70 var outputSpikeTimesNumerical = neuron.RunThetaNeuron(inputSpikeTimes, maxNumOutputSpikes).ToList();
74 neuron.Method = SimulationMethod.EventDriven;
75 var outputSpikeTimesEventDriven = neuron.RunThetaNeuron(inputSpikeTimes, maxNumOutputSpikes).ToList();
76 CompareSpikeTrains(outputSpikeTimesNumerical, outputSpikeTimesEventDriven, 0.01);
static void CompareNumericalAndEventDrivenSpikeTrains(ISpikingNeuron neuron, List< Spike > inputSpikeTimes, int maxNumOutputSpikes=3)
For a single spiking neuron, compares the output spikes (up to maxNumOutputSpikes) produced by runnin...
Set of helper methods for various spiking neuron network tests
static void CompareSpikeTrains(IReadOnlyCollection< Spike > spikeTrain1, IReadOnlyList< Spike > spikeTrain2, double threshold)
Finds the mean squared error in spike times between two spike trains. Asserts that the MSE is within ...