forked from samuellab/mindcontrol-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogLikelihood.m
56 lines (52 loc) · 1.93 KB
/
logLikelihood.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
% Copyright 2010 Andrew Leifer et al <[email protected]>
% This file is part of Mindcontrol-analysis.
%
% Mindcontrol-analysis is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Mindcontrol-analysis is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with mindcontrol-analysis. If not, see <http://www.gnu.org/licenses/>.
function ll=logLikelihood(a,b,c,t,r)
% This takes the natural log of the probability of
% a binary event occouring, given an exponentialy decaying weighting factor.
% This is the model I use for habituation. r reprosents a response to a
% stimuli at time t and is either 0 or 1.
%
% The probability of of an event is related to an exponentialy decaying
% weight factor w:
% P(r,w) = w if r==1; or P(r,w) = 1-w if r==0
%
% alternatively,
% P(r,w)=1+w(2r-1)-r
%
% Where,
% w = a + b* exp(-c*t)
% Thus
%
% P(r,a,b,c,d,t) = 1- r + 2(r-1) * ( a + b * exp(-c*t))
%
% Here we take the natural log of this expression
%
%
% by Andrew Leifer
% Inspired by discussions with Benjamin Schwartz and Subhy Lahiri
%
%
% For the most up to date version of this software, see:
% http://github.com/samuellab/mindcontrol
%
% NOTE: If you use any portion of this code in your research, kindly cite:
% Leifer, A.M., Fang-Yen, C., Gershow, M., Alkema, M., and Samuel A. D.T.,
% "Optogenetic manipulation of neural activity with high spatial resolution
% in freely moving Caenorhabditis elegans," Nature Methods, Submitted
% (2010).
%
ll = log ( 1-r+(2*r-1).*(a+b*exp(-c*t)) );