Home > matutils > logl.m

logl

PURPOSE ^

logl = logl(pars,func,n,x...)

SYNOPSIS ^

function logl = logl(pars,func,n,varargin)

DESCRIPTION ^

 logl = logl(pars,func,n,x...)

 Calculate -2 times the log of the joint probability of a 
 set of observations n at values x if they are Poisson deviates from
 mean values described by function func with parameters
 pars.

 eg: [x,n]=hfill(randn(1,1000),100,-3,3);
     p=fminsearch('logl',[30,0,1],[],'gauss',n,x)
     [p,pe]=matmin('logl',[30,0,1],[],'gauss',n,x)

 See also chisq

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function logl = logl(pars,func,n,varargin)
0002 % logl = logl(pars,func,n,x...)
0003 %
0004 % Calculate -2 times the log of the joint probability of a
0005 % set of observations n at values x if they are Poisson deviates from
0006 % mean values described by function func with parameters
0007 % pars.
0008 %
0009 % eg: [x,n]=hfill(randn(1,1000),100,-3,3);
0010 %     p=fminsearch('logl',[30,0,1],[],'gauss',n,x)
0011 %     [p,pe]=matmin('logl',[30,0,1],[],'gauss',n,x)
0012 %
0013 % See also chisq
0014 
0015 % table of log factorials
0016 persistent LFACTS
0017 
0018 % Ensure table is big enough for this data set
0019 % A bit wasteful to test every time and don't need to recalc
0020 % whole table just because max value changes...
0021 maxn=max(n);
0022 if(length(LFACTS)<maxn+1)
0023   LFACTS=cumsum([0,log(1:maxn)]);
0024 end
0025 
0026 mu=feval(func,pars,varargin{:});
0027 
0028 logl=-2*sum(n.*log(mu)-mu-LFACTS(n+1));

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005