-
Notifications
You must be signed in to change notification settings - Fork 5
/
covar_wrapper.m
66 lines (58 loc) · 2.44 KB
/
covar_wrapper.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
function [ out ] = covar_wrapper( phat, cov, covars_list, asa )
%COVAR_WRAPPER Converts covarying parameter inputs
% This wrapper function converts the fit represented in phat and the
% covarying rhythmicity problem represented in cov, covars_list.
%
% [out] = covar_wrapper(phat, cov, covars_list);
% Returns the wrapped output with the standard parameters for
% MLE_RHYTHMICITY, with s dropped if s not in cov
% (noskip=true in mle_rhythmicity). See doc rhythmicity_covar for
% more information
%
% [out] = covar_wrapper(phat,cov,covars_list,asa)
% If asa=true, then phat is formatted for the amplitude of the rhythm
% (a) and not the relative amplitude (r). See doc mle_rhythmicity for
% more information.
%
% See also mle_rhythmicity, cif_generator, rhythmicity_covar
% Copyright 2015-2016 Trustees of Boston University
% All rights reserved.
%
% This file is part of mle_rhythmicity revision 2.0. The last committed
% version of the previous revision is the SHA starting with 93862ac...
%
% This code has been freely distributed by the authors under the BSD
% license (http://opensource.org/licenses/BSD2-Clause). If used or
% modified, we would appreciate if you cited our papers:
%
% Climer JR, DiTullio R, Newman EL, Hasselmo ME, Eden UT. (2014),
% Examination of rhythmicity of extracellularly recorded neurons in the
% entorhinal cortex. Hippocampus, 25:460-473. doi: 10.1002/hipo.22383.
%
% Hinman et al., Multiple Running Speed Signals in Medial Entorhinal
% Cortex, Neuron (2016). http://dx.doi.org/10.1016/j.neuron.2016.06.027
PARAMS = {'tau','b','c','f','s','r'};% List of parameters - used for easier coding
PARAMS = PARAMS(ismember(PARAMS,fields(cov)));
if ~all(ismember(fields(cov),PARAMS))
PARAMS = fields(cov);
end
if ~exist('asa','var')
asa = false;
end
if asa
phat = [phat(numel(cov.r)+1:end) phat(1:numel(cov.r))/(1-phat(numel(cov.r)+numel(cov.tau)+1))];
end
vect = @(x)x(:);
out = cell(size(fields(cov)));
out(cellfun(@(x)isequal(cov.(x),0),PARAMS)) = ...
num2cell(phat(arrayfun(@(i)sum(cellfun(@(s)numel(cov.(s)),...
PARAMS(1:i))),find(cellfun(@(x)isequal(cov.(x),0),PARAMS)))));
out(~cellfun(@(x)isequal(cov.(x),0),PARAMS)) = ...
...
arrayfun(@(i)...
covars_list(:,cov.(PARAMS{i})+1)*...
vect(phat(sum(cellfun(@(s)numel(cov.(s)),PARAMS(1:i-1)))+(1:numel(cov.(PARAMS{i})))))...
,find(~cellfun(@(x)isequal(cov.(x),0),PARAMS))...
,'UniformOutput',false...
);
end