📄 patterns.m
字号:
Ni=10; % Inhibitory neurons as output neurons
Ne=15; % 3by5 pattern i.e., 15 Excitatory neurons as input neurons
a1=0.02; a2=0.06; %1 for exc. and 2 for inh.
b1=0.2; b2=0.22;
c1=-55; c2=-65;
d1=4; d2=2;
w=[];%initalize the weight from input neuron to output neuron
I=[];%Initialize the current Input for all neurons
firings=[]; % spike timings initialization
%%%%%%%%%%%% Training starts%%%%%%%%%%%%%%%
Input(:,1)=[0 30 0 0 30 0 0 30 0 0 30 0 0 30 0]; % First Input Pattern--1 for exc. inputs
Input(:,2)=[30 30 30 0 0 30 30 30 30 30 0 0 30 30 30]; % Second Input Pattern--2 for exc. inputs
Input(:,3)=[30 30 30 0 0 30 0 30 30 0 0 30 30 30 30]; % Third Input Pattern--3 for exc. inputs
Input(:,4)=[0 0 30 0 30 30 30 0 30 30 30 30 0 0 30]; % Forth Input Pattern--4 for exc. inputs
Input(:,5)=[30 30 30 30 0 0 30 30 30 0 0 30 30 30 30]; % Fifth Input Pattern--5 for exc. inputs
Input(:,6)=[0 30 30 30 0 0 30 30 30 30 0 30 30 30 30]; % Sixth Input Pattern--6 for exc. inputs
Input(:,7)=[30 30 30 0 0 30 0 30 0 30 0 0 30 0 0]; % seventh Input Pattern--7 for exc. inputs
Input(:,8)=[30 30 30 30 0 30 0 30 0 30 0 30 30 30 30]; % Eighth Input Pattern--8 for exc. inputs
Input(:,9)=[30 30 30 30 0 30 30 30 30 0 0 30 30 30 0]; % Eighth Input Pattern--9 for exc. inputs
Input(:,10)=[30 30 30 30 0 30 30 0 30 30 0 30 30 30 30]; % Eighth Input Pattern--0 for exc. inputs
%it is assumed that, for simplicity, for pattern A- 1st neuron fires,
%pattern B- 2nd neruon fires,C-3rd fires and D-4th fires, so you have to
%preselect initial weights for it.
for i=1:15
for j=1:10
if Input(i,j)==0
w(i,j)=-10;
else
w(i,j)=4.5;
end
end
end
w=w'; % Because if one input neuron fires, we can use one col. of w to add with 4 o/p neurons
firings=[]; % spike timings initialization
for in=1:10 %for 8 patterns
initial=1+(in-1)*10;
v=-65*ones(Ne+Ni,1); % Initial values of v for each input patterns
u=[];% variable delcaration, otherwise it will mix with other u of other programs
u(1:15,1)=b1*v(1:15); % Initial values of u for exc. neurons for each input
u(16:25,1)=b2*v(16:25,1);% Initial values of u for inh. neurons for each input
for t=initial:initial-1+10 % simulation of 10 ms with one input
I(16:25,1)=zeros(10,1);%At every time-step you have to initialize it to zero
I(1:15,1)=Input(1:15,in); %Specify the input for the exc. neuron
v(1:15,1)=v(1:15,1)+0.5*(0.04*v(1:15,1).^2+5*v(1:15,1)+140-u(1:15,1)+I(1:15,1));
% Excitatory neurons are upgraded with extern. inputs patterns
for i=1:15 % for excitatory input neurons, if fires, it is updated and produce input I for output neruons
if v(i,1)>30 % one input neuron fires,
firings=[firings; t, i];
v(i,1)=c1; %it is updated
u(i,1)=u(i,1)+d1; %it is updated
I(16:25,1)=I(16:25,1) + w(1:10,i);%weight from the firing neurons add with the all output neurons
end
end
t;
for j=16:25 % for output neruons, if it fires, then you have to upgrade---it, other o/p neurons and weights
if ( v(j,1)==max(v(16:23,1)) )&& ( v(j,1)>25 )
firings=[firings; t, j];
v(j,1)=c2; %it is updated
u(j,1)=u(j,1)+d2; %it is updated
for k=16:25 % -ve contribution from this firing neuron to other inhibitory output neurons
if k~=j
I(k,1)=I(k,1)-50;
% -ve contribution from this firing neuron to other inhibitory output neurons
end
end
for m=1:10
x=find((firings(:,2)==m)&(firings(:,1)>initial));
if ~isempty(x)
%if v(m,1)>30 % it means both pre and post fired, and pre is first to fire
w(j-15,m)= w(j-15,m) + .2; % the weight is strenthened as STDP rule
else % it means pre does not fire but post fire
w(j-15,m)= w(j-15,m) - 15; % the weight is weakened as STDP rule
end
end
end
end
% for i=1:3 % for excitatory input neurons, if fires, it is updated and produce input I for output neruons
% if v(i,1)>30 % input one neuron fires,
% v(i,1)=c1; %it is updated
% u(i,1)=u(i,1)+d1; %it is updated
% end
% end
% Now you have to upgrade all the output neurons (input neurons are upgraded beginning of the cycle)
% v(16:19,1)=v(16:19,1)+0.5*(0.04*v(16:19,1).^2+5*v(16:19,1)+140-u(16:19,1)+I(16:19,1));
v(16:25,1)=v(16:25,1)+0.5*(0.04*v(16:25,1).^2+5*v(16:25,1)+140-u(16:25,1)+I(16:25,1));
x(1:10,1)=v(16:25,1);
w;
u(16:25,1)=u(16:25,1)+a2*(b2*v(16:25,1)-u(16:25,1));
t;
w;
end
end
plot(firings(:,1),firings(:,2),'.');
axis([0 101 0 30.5])
%%%%%%%%%%%% Testing starts%%%%%%%%%%%%%%%
% firings=[];
% v=-65*ones(Ne+Ni,1); % Initial values of v for each input patterns
% u=[];% variable delcaration, otherwise it will mix with other u of other programs
% u(1:15,1)=b1*v(1:15); % Initial values of u for exc. neurons for each input
% u(16:23,1)=b2*v(16:23);% Initial values of u for inh. neurons for each input
%
% for t=1:10 % simulation of 10 ms with one input
% I(16:23,1)=zeros(8,1);%At every time-step you have to initialize it to zero
% I(1:15,1)=Input(1:15,pattern_input); %Specify the input for the exc. neuron
% v(1:15,1)=v(1:15,1)+0.5*(0.04*v(1:15,1).^2+5*v(1:15,1)+140-u(1:15,1)+I(1:15,1));
% % Excitatory neurons are upgraded with extern. inputs patterns
% for i=1:15 % for excitatory input neurons, if fires, it is updated and produce input I for output neruons
% if v(i,1)>30 % one input neuron fires,
% firings=[firings; t, i];
% v(i,1)=c1; %it is updated
% u(i,1)=u(i,1)+d1; %it is updated
% I(16:23,1)=I(16:23,1) + w(1:8,i);%weight from the firing neurons add with the all output neurons
% end
% end
% t
% for j=16:23 % for output neruons, if it fires, then you have to upgrade---it, other o/p neurons and weights
% if ( v(j,1)==max(v(16:23,1)) )&& ( v(j,1)>30 )
% firings=[firings; t, j];
% v(j,1)=c2; %it is updated
% u(j,1)=u(j,1)+d2; %it is updated
% for k=16:23 % -ve contribution from this firing neuron to other inhibitory output neurons
% if k~=j
% I(k,1)=I(k,1)-50;
% % -ve contribution from this firing neuron to other inhibitory output neurons
% end
% end
%
% % for m=1:8
% % x=find((firings(:,2)==m)&(firings(:,1)>initial));
% % if ~isempty(x)
% % %if v(m,1)>30 % it means both pre and post fired, and pre is first to fire
% % w(j-15,m)= w(j-15,m) + .2; % the weight is strenthened as STDP rule
% % else % it means pre does not fire but post fire
% % w(j-15,m)= w(j-15,m) - 15; % the weight is weakened as STDP rule
% % end
% % end
%
% end
% end
% % for i=1:3 % for excitatory input neurons, if fires, it is updated and produce input I for output neruons
% % if v(i,1)>30 % input one neuron fires,
% % v(i,1)=c1; %it is updated
% % u(i,1)=u(i,1)+d1; %it is updated
% % end
% % end
% % Now you have to upgrade all the output neurons (input neurons are upgraded beginning of the cycle)
% % v(16:19,1)=v(16:19,1)+0.5*(0.04*v(16:19,1).^2+5*v(16:19,1)+140-u(16:19,1)+I(16:19,1));
% v(16:23,1)=v(16:23,1)+0.5*(0.04*v(16:23,1).^2+5*v(16:23,1)+140-u(16:23,1)+I(16:23,1));
% x(1:8,1)=v(16:23,1)
% w
% u(16:23,1)=u(16:23,1)+a2*(b2*v(16:23,1)-u(16:23,1));
% t;
% w;
% end
% figure;
% %plot(firings(1,1),firings(1,2),'.');
% plot(firings(:,1),firings(:,2),'.');
% axis([0 21 0 25.5])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -