-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhist_dep.m
45 lines (37 loc) · 1.48 KB
/
hist_dep.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% hist_dep.m
%
% This function creates the matrix of covariates to be used in glmfit when
% spike history is included in the model.
%
% Inputs: timesteps - an array of time steps counted in reverse used for
% history dependence (i.e. 1 is the most recent,
% followed by 2...)
% spikes - vector of spikes for this neuron
% varargin - vectors of the non-spike history covariates to be
% included
%
% Output: covariate_matrix - the matrix of covariates. Use this with glmfit
%
% Function by: Lim Jing Xuan (adapted from hist_dependence.m)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [spikes_trunc,covar_m] = hist_dep(timesteps,spikes,varargin)
n_cov = length(varargin); % Number of non-spike covariates
n_timesteps = length(timesteps); % Number of spike convariates
tot_cov = n_cov + n_timesteps % Total number of covariates
spikes_trunc = spikes(max(timesteps)+1:end);
% Preallocate for speed
covar_m = zeros(length(spikes_trunc),tot_cov);
% Add non-spike covariates to matrix
for i = 1:n_cov
covar_m(:,i) = varargin{i}(max(timesteps)+1:end);
end
% Add spike history dependent covariates to matrix
for n = 1:numel(timesteps)
time = timesteps(n);
covar_m(:,n_cov+n) = spikes(max(timesteps)-time+1:end-time);
end
if length(spikes_trunc) ~= size(covar_m,1);
warning('Dataset size mis-match')
end
end