Spiking Neuron Network Simulator  1.0
Simulation and training of spiking neuron networks, primarily theta neurons
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Pages
SumOfSquaredSpikingErrorTests.cs
Go to the documentation of this file.
1 namespace SpikingNeuronNetwork.Test
2 {
3  using Lib;
4  using Microsoft.VisualStudio.TestTools.UnitTesting;
5  using System;
6  using System.Collections.Generic;
7 
11  [TestClass]
13  {
18  [TestMethod]
20  {
21  var desiredSpikeTimes = new List<Spike>
22  {
23  new Spike {NeuronIndex = 0, Time = 1}
24  };
25  var actualSpikeTimes = new List<Spike>
26  {
27  new Spike {NeuronIndex = 0, Time = 1.1}
28  };
29 
30  SumOfSquareSpikingErrorTestHelper(desiredSpikeTimes, actualSpikeTimes, 0.005);
31  }
32 
37  [TestMethod]
39  {
40  var desiredSpikeTimes = new List<Spike>
41  {
42  new Spike {NeuronIndex = 0, Time = 1},
43  new Spike {NeuronIndex = 1, Time = 3}
44  };
45  var actualSpikeTimes = new List<Spike>
46  {
47  new Spike {NeuronIndex = 0, Time = 1.1},
48  new Spike {NeuronIndex = 1, Time = 2.8}
49  };
50 
51  SumOfSquareSpikingErrorTestHelper(desiredSpikeTimes, actualSpikeTimes, 0.025);
52  }
53 
54  #region Helper Methods
55 
62  private static void SumOfSquareSpikingErrorTestHelper(List<Spike> desiredSpikeTimes, List<Spike> actualSpikeTimes, double expectedError)
63  {
64  var errorCalculator = new SumOfSquaredSpikingError();
65  var error = errorCalculator.GetError(desiredSpikeTimes, actualSpikeTimes);
66  Assert.IsTrue(Math.Abs(error - expectedError) < TestHelper.Epsilon);
67  errorCalculator.SimulationMethod = SimulationMethod.EventDriven;
68  var errorDerivativesEventDriven = errorCalculator.GetErrorToOutputSpikeTimeDerivative(desiredSpikeTimes, actualSpikeTimes);
69  errorCalculator.SimulationMethod = SimulationMethod.Numerical;
70  var errorDerivativesNumerical = errorCalculator.GetErrorToOutputSpikeTimeDerivative(desiredSpikeTimes, actualSpikeTimes);
71  Assert.AreEqual(errorDerivativesEventDriven.Count, errorDerivativesNumerical.Count);
72  for (var j = 0; j < errorDerivativesEventDriven.Count; j++)
73  {
74  Assert.IsTrue(Math.Abs(errorDerivativesEventDriven[j] - errorDerivativesNumerical[j]) < TestHelper.Epsilon);
75  }
76  }
77 
78  #endregion
79  }
80 }
Tests the sum of squared error calculation between spike trains
void SumOfSquaredSpikingErrorOneOutputNeuronTest()
Tests the sum of squared error calculation between spike trains containing one spike ...
static double Epsilon
Small value is used when comparing floats in various tests
Definition: TestHelper.cs:18
Set of helper methods for various spiking neuron network tests
Definition: TestHelper.cs:13
void SumOfSquaredSpikingErrorTwoOutputNeuronsTest()
Tests the sum of squared error calculation between spike trains containing two spikes ...