diff m-toolbox/classes/+utils/@math/chisquare_ssm_td.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/+utils/@math/chisquare_ssm_td.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,74 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% Compute log-likelihood in time domain for SSM objects
+% 
+% INPUT
+% 
+% - in, a vector of input signals aos
+% - out, a vector of output data aos
+% - parvals, a vector with parameters values
+% - parnames, a cell array with parameters names
+% - model, an ssm model
+% - inNames, A cell-array of input port names corresponding to the
+% different input AOs
+% - outNames, A cell-array of output ports to return
+% - cutbefore, followed by the data samples to cut at the starting of the
+% data series
+% - cutafter, followed by the data samples to cut at the ending of the
+% data series
+%
+% L Ferraioli 10-10-2010
+%
+% $Id: chisquare_ssm_td.m,v 1.1 2010/11/16 16:41:37 luigi Exp $
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function chi2 = chisquare_ssm_td(xp,in,out,parnames,model,inNames,outNames,varargin)
+% xn,in,out,noise,model,params,inNames,outNames
+  cutbefore = [];
+  cutafter = [];
+  if ~isempty(varargin)
+    for j=1:length(varargin)
+      if strcmp(varargin{j},'cutbefore')
+        cutbefore = varargin{j+1};
+      end
+      if strcmp(varargin{j},'cutafter')
+        cutafter = varargin{j+1};
+      end
+    end
+  end
+  
+  xp = double(xp);
+  fs = out(1).fs;
+  
+  % set parameters in the model
+  evalm = model.setParameters(plist('names',parnames,'values',xp));
+  evalm.keepParameters();
+  evalm.modifyTimeStep(plist('newtimestep',1/fs));
+  
+  %%% get expected outputs
+  plsym = plist('AOS VARIABLE NAMES',inNames,...
+    'RETURN OUTPUTS',outNames,...
+    'AOS',in);
+  eo = simulate(evalm,plsym);
+  
+  %%% get measurement noise
+  res = out-eo;
+  resy = res.y;
+  if size(resy,2)>size(resy,1)
+    resy = resy.';
+  end
+  
+  if ~isempty(cutbefore)
+    resy(1:cutbefore) = [];
+  end
+  if ~isempty(cutafter)
+    resy(end-cutafter:end) = [];
+  end
+  
+  chi2 = resy'*resy;
+  chi2 = chi2/(numel(resy)-numel(xp));
+  
+  
+  
+
+end
\ No newline at end of file