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
ThetaNeuronTests.cs
Go to the documentation of this file.
1 namespace SpikingNeuronNetwork.Test
2 {
3  using Lib;
4  using Lib.NeuronModels;
5  using Microsoft.VisualStudio.TestTools.UnitTesting;
6  using System;
7  using System.Collections.Generic;
8  using System.Linq;
9 
13  [TestClass]
14  public class ThetaNeuronTests
15  {
16  public static List<Spike> InputSpikeTimes = new List<Spike>
17  {
18  new Spike { Time = 2, NeuronIndex = 0},
19  new Spike { Time = 1, NeuronIndex = 1},
20  new Spike { Time = 1.5, NeuronIndex = 2},
21  new Spike { Time = 4, NeuronIndex = 3},
22  };
23 
28  [TestMethod]
30  {
31  // Construct theta neuron object with randomized weights
32  const int numInputs = 4;
33  var thetaNeuron = new ThetaNeuron(numInputs);
34  TestHelper.CompareNumericalAndEventDrivenSpikeTrains(thetaNeuron, InputSpikeTimes);
35  }
36 
41  [TestMethod]
43  {
44  // Construct theta neuron object with randomized weights
45  const int numInputs = 4;
46  var thetaNeuron = new ThetaNeuron(numInputs, 0.2, 0.01);
47  TestHelper.CompareNumericalAndEventDrivenSpikeTrains(thetaNeuron, InputSpikeTimes);
48  }
49 
50  [TestMethod]
52  {
53  // Construct theta neuron object with randomized weights
54  const int numInputs = 4;
55  var thetaNeuron = new ThetaNeuron(numInputs, -0.001, 0.01);
56  TestHelper.CompareNumericalAndEventDrivenSpikeTrains(thetaNeuron, InputSpikeTimes);
57  }
58 
59  [TestMethod]
61  {
62  // Construct theta neuron object with randomized weights
63  const int numInputs = 4;
64  var thetaNeuron = new ThetaNeuron(numInputs, 1e6, 0.01);
65  TestHelper.CompareNumericalAndEventDrivenSpikeTrains(thetaNeuron, InputSpikeTimes);
66  }
67 
68  [TestMethod]
70  {
71  // Construct theta neuron object with randomized weights
72  const int numInputs = 4;
73  var thetaNeuron = new ThetaNeuron(numInputs, 0.01);
74  TestHelper.CompareNumericalAndEventDrivenSpikeTrains(thetaNeuron, InputSpikeTimes);
75  }
76 
77  [TestMethod]
79  {
80  // Construct theta neuron object with randomized weights
81  const int numInputs = 4;
82  var thetaNeuron = new ThetaNeuron(numInputs, -0.01);
83  TestHelper.CompareNumericalAndEventDrivenSpikeTrains(thetaNeuron, InputSpikeTimes);
84  }
85 
86  [TestMethod]
87  public void ThetaNeuronStackedTest()
88  {
89  for (var j2 = 0; j2 < 1000; j2++)
90  {
91  const int numInputs = 4;
92  const int maxNumOutputSpikes = 3;
93 
94  // Construct theta neuron object with randomized weights
95  var thetaNeuron = new ThetaNeuron(numInputs);
96 
97  // Display Neuron Properties
98  Console.WriteLine(thetaNeuron);
99 
100  //Simulate Theta Neuron with Event-Driven Methodology
101  thetaNeuron.Method = SimulationMethod.EventDriven;
102  var outputSpikeTimesEventDriven =
103  thetaNeuron.RunThetaNeuron(InputSpikeTimes, maxNumOutputSpikes).ToList();
104 
105  //Stack two neurons sequentially
106  if (outputSpikeTimesEventDriven.Count <= 0) return;
107  Console.WriteLine("A second neuron is simulated in connection to the output of the previous neuron");
108  var thetaNeuron2 = new ThetaNeuron(1);
109  var outputSpikeTimesList =
110  outputSpikeTimesEventDriven.Select((t, j) => new Spike {Time = t.Time, NeuronIndex = j}).ToList();
111  var outputSpikeTimesEventDriven2 =
112  thetaNeuron2.RunThetaNeuron(outputSpikeTimesList, maxNumOutputSpikes).ToList();
113  if (outputSpikeTimesEventDriven2.Count > 0)
114  {
115  Assert.IsTrue(outputSpikeTimesEventDriven.First().Time < outputSpikeTimesEventDriven2.First().Time);
116  }
117  }
118  }
119  }
120 }
Tests theta neuron functionality
void ThetaNeuronRandomWeightsMethodTest()
Tests numerical and event-driven results are equivalent for a theta neuron with 4 inputs and random w...
void ThetaNeuronIdenticalPositiveIoPositiveWeightsMethodTest()
Tests numerical and event-driven results are equivalent for a theta neuron with 4 inputs and random w...