4 using Lib.NeuronModels;
5 using Microsoft.VisualStudio.TestTools.UnitTesting;
7 using System.Collections.Generic;
8 using System.Globalization;
23 const int numInputs = 3;
24 var numNeuronsPerLayer =
new[] { 1, 2 };
26 Assert.IsTrue(network.IsLayered);
27 Assert.IsTrue(
new List<int> { 3 }.SequenceEqual(network.GetNeuronIndicesByLayer(0)));
28 Assert.IsTrue(
new List<int> { 4, 5 }.SequenceEqual(network.GetNeuronIndicesByLayer(1)));
30 Assert.IsFalse(network.IsLayered);
40 const int numInputs = 1;
41 const int numNeurons = 1;
42 const double weightIni = 0.15;
43 const double baselineCurrent = 0.001;
44 var inputSpikeTimes =
new List<Spike>
46 new Spike { Time = 1, NeuronIndex = 0},
49 SpikeTrainTestHelper(numInputs, numNeurons, weightIni, baselineCurrent, inputSpikeTimes);
59 const int numInputs = 2;
60 const int numNeurons = 1;
61 const double weightIni = 0.1;
62 const double baselineCurrent = 0.001;
63 var inputSpikeTimes =
new List<Spike>
65 new Spike { Time = 2, NeuronIndex = 0},
66 new Spike { Time = 1, NeuronIndex = 1},
69 SpikeTrainTestHelper(numInputs, numNeurons, weightIni, baselineCurrent, inputSpikeTimes);
79 const int numInputs = 3;
80 const int numNeurons = 1;
81 const double weightIni = 0.01;
82 const double baselineCurrent = 0.001;
83 var inputSpikeTimes =
new List<Spike>
85 new Spike { Time = 2, NeuronIndex = 0},
86 new Spike { Time = 1, NeuronIndex = 1},
87 new Spike { Time = 2.1, NeuronIndex = 2}
90 SpikeTrainTestHelper(numInputs, numNeurons, weightIni, baselineCurrent, inputSpikeTimes);
100 const int numInputs = 1;
101 const int numNeurons = 1;
102 const double weightIni = -0.15;
103 const double baselineCurrent = -0.001;
104 var inputSpikeTimes =
new List<Spike>
106 new Spike { Time = 0.01, NeuronIndex = 0},
109 SpikeTrainTestHelper(numInputs, numNeurons, weightIni, baselineCurrent, inputSpikeTimes);
119 const int numInputs = 1;
120 const int numNeurons = 1;
121 const double weightIni = -0.15;
122 const double baselineCurrent = -0.001;
123 const int currentNeuron = numInputs + numNeurons - 1;
124 var inputSpikeTimes =
new List<Spike>
126 new Spike { Time = 0.01, NeuronIndex = 0},
129 var thetaNeuronNetwork =
new SpikingNeuronNetwork(numInputs, numNeurons, typeof(
ThetaNeuron), weightIni,
new Dictionary<string, string> { {
"Io", baselineCurrent.ToString(CultureInfo.InvariantCulture)}, {
"Method",
"EventDriven"} });
130 thetaNeuronNetwork.RunSpikingNeuronNetwork(inputSpikeTimes);
131 inputSpikeTimes.First().Time -= 0.005;
132 var neuronFiringHistories = thetaNeuronNetwork.RunSpikingNeuronNetwork(inputSpikeTimes);
134 Assert.AreEqual(1, neuronFiringHistories.Count);
135 Assert.AreEqual(currentNeuron, neuronFiringHistories.First().Key);
136 Assert.AreEqual(-1, neuronFiringHistories.First().Value.StartTime);
137 Assert.AreEqual(-1, neuronFiringHistories.First().Value.EndTime);
138 Assert.AreEqual(0, neuronFiringHistories.First().Value.OutputSpikes.Count);
139 Assert.AreEqual(0, neuronFiringHistories.First().Value.SpikeStats.Count);
146 [ExpectedException(typeof(ArgumentException))]
149 const int numInputs = 2;
150 const int numNeurons = 1;
151 const double weightIni = 0.1;
157 #region Helper Methods
170 private static void SpikeTrainTestHelper(
int numInputs,
int numNeurons,
double weightIni,
double baselineCurrent, List<Spike> inputSpikeTimes)
172 var currentNeuron = numInputs + numNeurons - 1;
173 var thetaNeuronNetwork =
new SpikingNeuronNetwork(numInputs, numNeurons, typeof(
ThetaNeuron), weightIni,
new Dictionary<string, string> { {
"Io", baselineCurrent.ToString(CultureInfo.InvariantCulture)}, {
"Method",
"EventDriven"} });
174 var neuronFiringHistories = thetaNeuronNetwork.RunSpikingNeuronNetwork(inputSpikeTimes);
177 var outputSpikeTimesNetwork = neuronFiringHistories[currentNeuron].OutputSpikes;
179 thetaNeuron.Method = SimulationMethod.Numerical;
180 thetaNeuron.ResetState();
181 var outputSpikeTimesStandAlone = thetaNeuron.RunThetaNeuron(inputSpikeTimes).ToList();
182 TestHelper.CompareSpikeTrains(outputSpikeTimesNetwork, outputSpikeTimesStandAlone, 0.01);
void ThetaNeuronNetworkBasicRunAllInputSpikesComeBeforeNetworkTime()
Tests ability to run a Spiking Neuron Network containing a single neuron and one input that takes pla...
void ThetaNeuronNetworkBasicRunNoOutputSpikesTest()
Tests ability to run a Spiking Neuron Network containing a single neuron and one input which produces...
void ThetaNeuronNetworkLayeredTest()
Tests ability to setup a layered spiking neuron network
Tests ability to run a spiking neuron network
void ThetaNeuronNetworkBasicRunCompareOneInputTest()
Tests ability to run a Spiking Neuron Network containing a single neuron and one input ...
void ThetaNeuronNetworkBadNeuronTypeTest()
Tests that a spiking neuron network is not created with an invalid spiking neuron type ...
Spiking Neuron Network Class
ISpikingNeuron GetStandAloneNeuron(int neuronIndex)
Gets the stand alone neuron.
void ThetaNeuronNetworkBasicRunCompareThreeInputsTest()
Tests ability to run a Spiking Neuron Network containing a single neuron and three inputs ...
void ThetaNeuronNetworkBasicRunCompareTwoInputsTest()
Tests ability to run a Spiking Neuron Network containing a single neuron and two inputs ...