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
Program.cs
Go to the documentation of this file.
1 namespace SpikingNeuronNetwork.Console
2 {
3  using Lib;
4  using Lib.NeuronModels;
5  using System;
6  using System.Collections.Generic;
7  using System.Linq;
8 
52  public class Program
56  {
57  static void Main()
58  {
59  const int numInputs = 4;
60  const int maxNumOutputSpikes = 3;
61  var inputSpikeTimes = new List<Spike>
62  {
63  new Spike { Time = 2, NeuronIndex = 0},
64  new Spike { Time = 1, NeuronIndex = 2},
65  new Spike { Time = 1.5, NeuronIndex = 2},
66  new Spike { Time = 4, NeuronIndex = 3},
67  };
68 
69  // Construct theta neuron object with randomized weights
70  var thetaNeuron = new ThetaNeuron(numInputs, 0.01);
71 
72  // Display Neuron Properties
73  Console.WriteLine(thetaNeuron);
74 
75  // Simulate Theta Neuron Numerically
76  thetaNeuron.Method = SimulationMethod.Numerical;
77  var outputSpikeTimes = thetaNeuron.RunThetaNeuron(inputSpikeTimes, maxNumOutputSpikes).ToList();
78 
79  //Simulate Theta Neuron with Event-Driven Methodology
80  thetaNeuron.ResetState();
81  thetaNeuron.Method = SimulationMethod.EventDriven;
82  var outputSpikeTimes2 = thetaNeuron.RunThetaNeuron(inputSpikeTimes, maxNumOutputSpikes).ToList();
83 
84  //Find Mean-Squared in Spike Times Between the Different Methods
85  if (outputSpikeTimes.Count != outputSpikeTimes2.Count)
86  {
87  Console.WriteLine("The Two Simulation Methods Produced Different Numbers of Output Spikes!");
88  Console.WriteLine();
89  }
90  else if (outputSpikeTimes.Count == 0)
91  {
92  Console.WriteLine("The Two Simulation Methods Produced No Output Spikes!");
93  Console.WriteLine();
94  }
95  else
96  {
97  double meanSquaredError = 0;
98  meanSquaredError += outputSpikeTimes.Select((t, j) => Math.Pow(t.Time - outputSpikeTimes2[j].Time, 2)).Sum();
99  meanSquaredError /= outputSpikeTimes.Count;
100  Console.WriteLine("Output Spike Mean-Squared Error Between Simulation Methods: ");
101  Console.WriteLine("\t" + meanSquaredError);
102  Console.WriteLine();
103  }
104 
105  //Stack two neurons sequentially
106  if (outputSpikeTimes.Count > 0)
107  {
108  Console.WriteLine("A second neuron is simulated in connection to the output of the previous neuron");
109  var thetaNeuron2 = new ThetaNeuron(1);
110  var outputSpikeTimesList = outputSpikeTimes.Select((t, j) => new Spike{Time = t.Time, NeuronIndex = j}).ToList();
111  thetaNeuron2.RunThetaNeuron(outputSpikeTimesList, maxNumOutputSpikes);
112  }
113 
114  Console.ReadKey();
115  }
116  }
117 }
Console Program Class
Definition: Program.cs:55