-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResonate-and-Fire (RAF) Neuron Model Cortical Modelling Assignment
212 lines (152 loc) · 3.87 KB
/
Resonate-and-Fire (RAF) Neuron Model Cortical Modelling Assignment
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
%% Simulator - Resonate-and-Fire (RAF) Neuron Model
%% D. Bernal-Casas
%% Version 10: 2019 - Adapted from the literature
%% Main Sources:
%% [1] Trappenberg
%% [2] Dayan and Abbot
%% [3] Churchland and Sejnowski
%% [4] Rolls and Deco
%% [5] Izhikevich
%% [6] Wilson
%% [7] Gerstner
%% Numerical Integration with the Euler method
clear all;
close all;
hold off;
clc;
%% Setting parameters
%Samples
Nsamp = 300;
%Damping factor
damp_1 = 2.5;
%Natural frequency, make oscillations of 1.1Hz
w_1 = 1.1*2*pi;
%Time-step
dt = 0.1;
times = 0:dt:(Nsamp*dt - dt);
%% Set up neurons
dv_1 = zeros(2, Nsamp);
v_1 = zeros(2, Nsamp);
dv_2 = zeros(2, Nsamp);
v_2 = zeros(2, Nsamp);
dv_3 = zeros(2, Nsamp);
v_3 = zeros(2, Nsamp);
%% Initialize weights
%Pos weight
n1 = randi([1 20],1,1);
n2 = randi([1 20],1,1);
n3 = randi([1 20],1,1);
n4 = randi([1 20],1,1);
%Neg weight
n5 = (randi([1 20],1,1))*-1;
n6 = (randi([1 20],1,1))*-1;
%Excitatory Neuron one to three and one to two excites:
w12 = n1;
w13 = n2;
%Excitatory Neuron two to one excites and two to three excites:
w21 = n3;
w23 = n4;
%Inhibitory: Neuron three to one inhibits and three to two inhibits:
w31 = n5;
w32 = n6;
%% Inputs
I_0 = zeros(1, Nsamp);
%With a single input, the neuron does not fire
%I_0(1,10) = 37;
%With two-consecutive inputs, you have a coincidence detector
%I_0(1,10) = 37;
% I_0(1,11) = 37;
spike_1 = zeros(1, Nsamp);
spike_2 = zeros(1, Nsamp);
spike_3 = zeros(1, Nsamp);
I_0 = zeros(1, Nsamp);
for in = 10:10:Nsamp
I_0(1,in) = 37;
%if in < 290
%I_0(1,in+1) = 37;
%end
end
%Neuron 1
for it=2:Nsamp
%1 Neuron
dv_1(1,it) = v_1(2,it-1);
dv_1(2,it) = -(w_1^2)*v_1(1,it-1) - 2*damp_1*v_1(2,it-1) + I_0(1,it-1) + w21*spike_2(1,it-1)+w31*spike_3(1,it-1);
v_1(1,it) = v_1(1,it-1) + dt*dv_1(1,it);
v_1(2,it) = v_1(2,it-1) + dt*dv_1(2,it);
if (v_1(1,it) >= 1.0)
spike_1(1,it) = 1;
else
spike_1(1,it) = 0;
end
%Neuron 2
%2 Neuron
dv_2(1,it) = v_2(2,it-1);
dv_2(2,it) = -(w_1^2)*v_2(1,it-1) - 2*damp_1*v_2(2,it-1) + I_0(1,it-1) + w12*spike_1(1,it-1)+w32*spike_3(1,it-1);
v_2(1,it) = v_2(1,it-1) + dt*dv_1(1,it);
v_2(2,it) = v_2(2,it-1) + dt*dv_1(2,it);
if (v_2(1,it) >= 1.0)
spike_2(1,it) = 1;
else
spike_2(1,it) = 0;
end
%Neuron 3
%3 Neuron
dv_3(1,it) = v_3(2,it-1);
dv_3(2,it) = -(w_1^2)*v_3(1,it-1) - 2*damp_1*v_3(2,it-1) + I_0(1,it-1) + w23*spike_2(1,it-1)+w13*spike_1(1,it-1);
v_3(1,it) = v_3(1,it-1) + dt*dv_3(1,it);
v_3(2,it) = v_3(2,it-1) + dt*dv_3(2,it);
if (v_3(1,it) >= 1.0)
spike_3(1,it) = 1;
else
spike_3(1,it) = 0;
end
end
%%
figure('name','Excitatory neuron 1, Spikes, Membrane Potential, and Input Current')
subplot(3, 1, 1)
stem(times, spike_1(1,:))
subplot(3, 1, 2)
plot(times, v_1(1,:))
hold on
plot(times, ones(1,Nsamp), 'r')
subplot(3, 1, 3)
stem(times, I_0(1,:))
%%
figure('name','Excitatory neuron 2, Spikes, Membrane Potential, and Input Current')
title('Excitatory Neuron 2')
subplot(3, 1, 1)
stem(times, spike_2(1,:))
subplot(3, 1, 2)
plot(times, v_2(1,:))
hold on
plot(times, ones(1,Nsamp), 'g')
subplot(3, 1, 3)
stem(times, I_0(1,:))
%%
figure('name','Inhibitory neuron 1, Spikes, Membrane Potential, and Input Current')
subplot(3, 1, 1)
stem(times, spike_3(1,:))
subplot(3, 1, 2)
plot(times, v_3(1,:))
hold on
plot(times, ones(1,Nsamp), 'b')
subplot(3, 1, 3)
stem(times, I_0(1,:))
%%
figure('name','Combined interactions, Spikes, Membrane Potential, and Input Current')
subplot(3, 1, 1)
hold on
stem(times, spike_1(1,:),'r')
stem(times, spike_2(1,:),'g')
stem(times, spike_3(1,:),'b')
subplot(3, 1, 2)
hold on
plot(times, v_1(1,:))
plot(times, v_2(1,:))
plot(times, v_3(1,:))
hold on
plot(times, ones(1,Nsamp), 'r')
subplot(3, 1, 3)
stem(times, I_0(1,:))
%stem(times, I_0(1,:))
%stem(times, I_0(1,:))