-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkModels.cs
More file actions
198 lines (181 loc) · 6.25 KB
/
NetworkModels.cs
File metadata and controls
198 lines (181 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NeuronPerformance.Models
{
public enum NetworkType
{
// line of N neurons
Linear,
// full graph network
MeanField
}
public class NetworkModel : IModel
{
private NetworkType netType { get; set; }
private NeuronType neuType { get; set; }
private NeuronRegime neuReg { get; set; }
public Double ts_per_ms { get; private set; }
public Int32 transient { get; private set; }
public Int32 totalTime { get; private set; }
public Double dt { get; private set; }
public Boolean isNetwork { get; private set; }
private List<GapJunction> synapses { get; set; }
private List<Neuron> neurons { get; set; }
private Int32 nSyn { get; set; }
public Double synG { get; private set; }
public Int32 N { get; private set; }
private Action<NeuronRegime, Int32> CreateNetwork { get; set; }
public NetworkModel(NeuronType neut, NeuronRegime nr, Int32 totalTime, NetworkType nt, Int32 N, Double synG)
{
this.isNetwork = true;
this.netType = nt;
this.neuType = neut;
this.neuReg = nr;
this.totalTime = totalTime;
this.N = N;
this.synG = synG;
if (nt == NetworkType.Linear)
this.CreateNetwork = this.CreateNetworkLinear;
else if (nt == NetworkType.MeanField)
this.CreateNetwork = this.CreateNetworkMeanField;
else
throw new ArgumentOutOfRangeException("Unrecognized NetworkType");
this.Initialize();
}
private void Initialize()
{
this.CreateNeurons(this.neuType, this.neuReg, this.totalTime);
this.CreateNetwork(this.neuReg, this.totalTime);
}
public void CreateNetworkLinear(NeuronRegime nr, Int32 totalTime)
{
this.synapses = new List<GapJunction>();
Int32 i = 1;
while (i < this.N)
{
this.synapses.Add(new GapJunction(this.neurons[i-1], this.neurons[i], this.synG));
this.neurons[i].AddInput(this.synapses.Last());
i++;
}
this.nSyn = this.synapses.Count;
this.neurons.ForEach(n => n.ResetToFP()); // only neuron 0 has activity in t = 0
this.neurons[0].Reset(nr, totalTime);
}
public void CreateNetworkMeanField(NeuronRegime nr, Int32 totalTime)
{
this.synapses = new List<GapJunction>();
Int32 j, i = 0;
while (i < this.N)
{
j = 0;
while (j < this.N)
{
if (i != j)
{
this.synapses.Add(new GapJunction(this.neurons[i], this.neurons[j], this.synG));
this.neurons[j].AddInput(this.synapses.Last());
}
j++;
}
i++;
}
this.nSyn = this.synapses.Count;
Double[] ic = this.neurons[0].ResetToFP();
Random r = new Random();
this.neurons.ForEach(n => n.SetIC(ic.Select(x => x * r.NextDouble()).ToArray())); // randomizing IC for all neurons
}
private void CreateNeurons(NeuronType neut, NeuronRegime nr, Int32 totalTime)
{
this.neurons = new List<Neuron>(this.N);
Int32 i = 0;
while (i < this.N)
{
this.neurons.Add(NeuronFactory.Create(neut, nr, totalTime));
i++;
}
this.ts_per_ms = this.neurons[0].ts_per_ms;
this.transient = this.neurons[0].transient;
this.dt = this.neurons[0].dt;
}
//void TimeStep(Double Iext);
public void TimeStep()
{
// network timestep
Int32 j = 0;
while (j < this.nSyn)
{
this.synapses[j].TimeStep();
j++;
}
j = 0;
while (j < this.N)
{
this.neurons[j].TimeStepNet();
j++;
}
}
public Double GetV()
{
// gets the absolute difference between membrane potential of all neurons
// or the sum of all V??
return this.neurons.Sum(n => n.GetV());
}
public Double[] GetVNet()
{
return this.neurons.Select(n => n.GetV()).ToArray();
}
public void SetBurstingParam()
{
// sets network neurons with bursting param
this.neurons.ForEach(n => n.SetBurstingParam());
}
public void SetExcitableParam()
{
// sets network neurons with excitable params
this.neurons.ForEach(n => n.SetExcitableParam());
}
public void Reset(NeuronRegime nr, Int32 totalTime)
{
// resets network
//this.synapses.ForEach(s => s.Reset());
//this.neurons.ForEach(n => n.Reset(nr, totalTime));
this.neuReg = nr;
this.totalTime = totalTime;
this.Initialize();
}
public override String ToString()
{
return this.netType.ToString() + "_" + this.neuType.ToString() + this.neuReg.ToString();
}
}
public class GapJunction
{
public Neuron preSyn { get; private set; }
public Neuron postSyn { get; private set; }
/// <summary>
/// synaptic conductance (coupling intensity)
/// </summary>
public Double G { get; private set; }
public GapJunction(Neuron nPre, Neuron nPost, Double G)
{
this.preSyn = nPre;
this.postSyn = nPost;
this.G = G;
this.Reset();
}
/// <summary>
/// synaptic current for a given time step
/// </summary>
public Double I { get; private set; }
public void TimeStep()
{
this.I = this.G * (this.preSyn.GetV() - this.postSyn.GetV());
}
public void Reset()
{
this.I = 0.0d;
}
}
}