Code covered by the BSD License  

Highlights from
Greyboxeval - Model quality evaluation

image thumbnail
from Greyboxeval - Model quality evaluation by Bill Whiten
For models residues=model(data,parameters) with data sets at different experimental conditions

[p,pscale,pbase,c]=parcalc(condfn,data,idata,A)
function [p,pscale,pbase,c]=parcalc(condfn,data,idata,A)
% parcalc Internal function for use in greybox functions
%  2013-01-19  Matlab2013a  Copyright (c) 2013, W J Whiten  BSD License
%
% [par,pscale,pbase]=parcalc(condfn,data,idata,A)
%  condfn  Condition function  
%           [c,pscale,pbase,pvalue]=condfn(data,idata)
%            data  User supplied data in any form
%            idata Data set number for this calculation
%             c      Experimental condition vector or matrix
%             pscale Vector of scale (ie typical nonzero size) values 
%                     for parameters (optional if optn.Amat given)
%                     if optn.Amat not given, initial parameter values
%             pbase  Vector of base values for parameters (optional:
%                     default zero)
%  data    Data for use by cndfn
%  idata   Data set number
%  A       Matrix relating c to p
%
%  p       Parameter vector or matrix
%  pscale  Scale values for p
%  pbase   Base value or values for p
%  c       Condition vector or matrix

pbase=0;

ncondfn=nargout(condfn);

% get condition and parameter vakues
if(ncondfn==1)
    c=condfn(data,idata);
    pscale=abs(A)*abs(c(:))+abs(pbase);
elseif(ncondfn==2)
    [c,pscale]=condfn(data,idata);
elseif(ncondfn==3)
    [c,pscale,pbase]=condfn(data,idata);
end

% convert vectors or matrices to consistent sizes
if(isvector(c))
    c=c(:);
    pscale=pscale(:);
    pbase=pbase(:);
else
    nc2=size(c,2);
    if(isvector(pscale))
        pscale=repmat(pscale,nc2);
    end
    if(~isscalar(pbase) && isvector(pbase))
        pbase=repmat(pbase,nc2);
    end
end

% calculate parameter values
if(~isempty(A))
    p=A*c+pbase(:);
    pscale=pscale+abs(A)*abs(c)+abs(pbase);
else
    p=pscale;
end
pscale(pscale==0)=1;

return
end
    

Contact us