-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlca_inhib.m
67 lines (57 loc) · 2.31 KB
/
lca_inhib.m
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
function [a varargout] = lca_inhib(s, Phi, U_p, U_n, Sigma, V_p, ...
V_n, S_p, G_E, pars, varargin)
% LCA with inhibitory interneuron dynamics
%% Parse inputs
u_init = zeros(size(Phi,2),1);
a_init = u_init;
a_I1 = ones(size(Sigma,1), 1);
a_I2 = a_I1;
% $$$ a_I1 = u_init;
% $$$ a_I2 = u_init;
a_S = u_init;
% $$$ options = struct('init', [u_init a_init a_I1 a_I2 a_S] ,'energy', ...
% $$$ 0);
options = struct('init', [u_init a_init] ,'energy', 0, 'inhibTauScale', ...
1);
options = parse_inputs(options, varargin);
%% LCA
u = options.init(:,1);
a = options.init(:,2);
% $$$ a_I1 = options.init(:,3);
% $$$ a_I2 = options.init(:,4);
% $$$ a_S = options.init(:,5);
for n = 1:pars.itr
if options.energy
rl2e(n) = norm(s-Phi * a)/norm(s);
sparsity(n) = nnz(a);
energy(n) = 0.5*norm(s-Phi * a)^2 + pars.threshold*sum(abs(a));
end
%Euler's method to solve difference eqn
% $$$ u = u*(1-pars.delta/pars.tau) + pars.delta/pars.tau*(Phi' * s - (U_p * Sigma * V_p' + (-U_n) ...
% $$$ * Sigma * (-V_n') + S_p ) * a ...
% $$$ + (eye(size(G_E)) ...
% $$$ - G_E) * a);
c_inhib = options.inhibTauScale*(pars.delta/pars.tau); % delta/tau
% $$$ a_I1 = a_I1 * (1-c_inhib) + c_inhib * (Sigma * V_p' * a);
% $$$ a_I2 = a_I2 * (1-c_inhib) + c_inhib * (Sigma * (-V_n') * ...
% $$$ a);
% $$$ a_S = a_S * (1-c_inhib) + c_inhib * a;
% exponential decay to the solution
a_I1 = a_I1 * exp(-n*c_inhib) + Sigma * V_p' * a;
a_I2 = a_I2 * exp(-n*c_inhib) + Sigma * (-V_n') * a;
a_S = a_S * exp(-n*c_inhib) + a;
u = u*(1-pars.delta/pars.tau) + pars.delta/pars.tau*(Phi' * s - (U_p * a_I1 + (-U_n) ...
* a_I2 + S_p * a_S) ...
+ (eye(size(G_E)) ...
- G_E) * a);
if isnan(u)
error('NaN encountered in LCA.')
end
a = T_lambda(u, pars);
end
%% Outputs
if options.energy
varargout = {u, rl2e, sparsity, energy};
else
varargout = {u};
end