diff m-toolbox/classes/+utils/@math/wfun.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/wfun.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,61 @@
+% WFUN defines weighting factor for fitting procedures ctfit, dtfit.
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION
+% 
+%     Defines the weigthing factor for the fitting procedure performed by
+%     ctfit and dtfit.
+% 
+% CALL:
+% 
+%     weight = wfun(y,weightparam)
+% 
+% INPUT:
+% 
+%     y: are the set of data to be fitted
+%     weightparam: is a parameter for the swhitching procedure. Admitted
+%     values are:
+%       weightparam = 1 --> equal weights (one) for each point. This is the
+%       default option.
+%       weightparam = 2 --> weight with the inverse of absolute value of
+%       data
+%       weightparam = 3 --> weight with square root of the inverse of
+%       absolute value of data
+%       weightparam = 4 --> weight with the inverse of the square mean
+%       spread
+%       
+% 
+% OUTPUT:
+% 
+%     weight: is the set of weighting factors
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% VERSION: $Id: wfun.m,v 1.5 2008/11/17 16:52:23 luigi Exp $
+%
+% HISTORY:     08-10-2008 L Ferraioli
+%                 Creation
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function weight = wfun(y,weightparam)
+
+  [a,b] = size(y);
+
+  opt = 0; % default value
+  if ~isempty(weightparam)
+    opt = weightparam;
+  end
+
+  switch opt
+    case 0
+      disp(' Using external weights... ')
+    case 1
+      weight = ones(a,b); % equal weights for each point
+    case 2
+      weight = 1./abs(y); % weight with the inverse of absolute value of data
+    case 3
+      weight = 1./sqrt(abs(y)); % weight with square of the inverse of absolute value of data
+    case 4
+      my = mean(y,max(a,b));
+      weight = 1./((y-my).^2); % weight with the inverse of the square mean spread
+  end
\ No newline at end of file