-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSynchrony_probability_Ising_model.m
109 lines (92 loc) · 3.65 KB
/
Synchrony_probability_Ising_model.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
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
clear all;
clf
CM = hsv(3);
% Choose between Matlab optimization = 1
% or minimize.m minimization function = 2.
alg_choice = 1;
% Number of neurons.
N = 100;
% Load data from a file.
% The file.dat has the form:
% p(x_1) p(x_2) ... p(x_N) mu rho % trial number 1
% p(x_1) p(x_2) ... p(x_N) mu rho % trial number 2
% We keep mu and rho fixed over trials. We have multiple
% trials so that we can get an average and smooth out
% some of the inherent noise.
M{1} = importdata('figure_2a_0.325.dat',' ');
M{2} = importdata('figure_2a_0.49.dat',' ');
M{3} = importdata('figure_2a_0.73.dat',' ');
% List the possible states, using the symmetry argument.
% Symmetry argument can be found in Macke 2011.
% Essentially says that the parameters in the Ising model h_i, J_ij
% using symmetry conditions can be reduced to just 2 parameters. The
% symmetry condition means that we talk about population spike
% counts rather than particular probabilities. i.e P(101101) becomes
% just P(4) as 4 spikes occurred.
% Here we list the possible states which are just 1...N and at the
% same time we list their squares as needed in the Ising model.
states = [(0:N)',(0:N)'.^2];
% Generate a list of binomial coefficients.
warning off;
binom = zeros(N+1,1);
for i=0:N
binom(i+1) = nchoosek(N,i);
end
% An initial guess at the parameters to be minimized:
param_list_init = [0;0];
for j=1:3
% PP is a matrix where each row is a prob dist.
PP = M{j}(:,1:N+1);
mu = M{j}(:,N+2);
rho = M{j}(:,N+3);
% Take the mean of the input p(x).
% i.e we average over the trials
% p(x_1) p(x_2) ... p(x_N) mu rho % trial number 1
% p(x_1) p(x_2) ... p(x_N) mu rho % trial number 2
P = mean(PP,1)';
% Output mean firing rate and corr coefficient.
mean_mu = mean(mu);
mean_rho = mean(rho);
% Calculate the means and moments i.e. the quantities
% sum(k*P_k) and sum(k^2*P_k).
mean_feature = P'*states;
% Choose the algorithm to use.
if alg_choice == 1
% MATLAB Optimization Toolbox minimization function.
% Uses Optimization toolbox unconstrained minimization function.
options = optimset('GradObj','on','LargeScale','on',...
'Display','off',...
'MaxFunEvals',1000,'MaxIter',1000,'TolFun',1e-10,'TolX',1e-10);
% We set GradObj = on as we supply the gradient.
% We set LargeScale = on as that is the algorithm that uses the
% user supplied gradient.
% Display just shows some accuracy output.
% The final options are tolerances etc.
% The minimization function
[param_list] =...
fminunc(@(x)neg_log_like_binom...
(x,states,mean_feature,P,binom),param_list_init,options);
elseif alg_choice == 2
% Eric's minimization function, based on conjugate gradient.
param_list = minimize(param_list_init,...
'neg_log_like_binom',200,...
states,mean_feature,P,binom);
end
% Use the parameters found via minimization to calculate the probability
% distribution from the Ising model.
% The binomial prefactor is explained in Macke 2011.
Q_unnormalized = binom.*exp(states*param_list);
% Normalize this Q.
% This gives us a probability distribution Q(k), the probability of
% finding a population with count k.
Q = Q_unnormalized/sum(Q_unnormalized);
% Plot output.
semilogy(Q,'color',CM(j,:));
hold on
end
title('Ising Model Prediction','fontsize',18)
fig2b_leg = legend('\rho = 0.05','\rho = 0.1','\rho = 0.25');
set(fig2b_leg,'FontSize',16);
xlabel('Population spike count i.e synchrony','fontsize',16)
ylabel('Probability','fontsize',16)
axis([0 N 1e-4 1]);