Mercurial > forge
changeset 9546:895d2ab9c724 octave-forge
data-smoothing: implemented input check for functions. Bumped requirements for octave 3.6.0 since requires iscolumn
author | carandraug |
---|---|
date | Thu, 01 Mar 2012 17:18:34 +0000 |
parents | 3f35247262c1 |
children | 1f41798c5d3f |
files | main/data-smoothing/DESCRIPTION main/data-smoothing/NEWS main/data-smoothing/inst/ddmat.m main/data-smoothing/inst/regdatasmooth.m main/data-smoothing/inst/rgdtsmcore.m main/data-smoothing/inst/rgdtsmcorewrap.m |
diffstat | 6 files changed, 25 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/main/data-smoothing/DESCRIPTION Thu Mar 01 16:53:32 2012 +0000 +++ b/main/data-smoothing/DESCRIPTION Thu Mar 01 17:18:34 2012 +0000 @@ -6,7 +6,7 @@ Title: Data smoothing Description: Algorithms for smoothing noisy data Categories: Data-smoothing -Depends: octave (>= 3.0.0), optim (>= 1.0.3) +Depends: octave (>= 3.6.0), optim (>= 1.0.3) Autoload: no License: GPL version 3 or later Url: http://octave.sf.net
--- a/main/data-smoothing/NEWS Thu Mar 01 16:53:32 2012 +0000 +++ b/main/data-smoothing/NEWS Thu Mar 01 17:18:34 2012 +0000 @@ -5,3 +5,5 @@ ** code has been cleaned to remove warnings about "possible Matlab-style short-circuit operator" + + ** Minimal input check for all functions has been implemented
--- a/main/data-smoothing/inst/ddmat.m Thu Mar 01 16:53:32 2012 +0000 +++ b/main/data-smoothing/inst/ddmat.m Thu Mar 01 17:18:34 2012 +0000 @@ -37,7 +37,9 @@ ## added error check that x is a column vector; JJS 4/13/09 function D = ddmat(x, d) - if ( size(x,2) != 1 ) + if (nargin != 2) + print_usage; + elseif ( !iscolumn (x) ) error("x should be a column vector") endif m = length(x);
--- a/main/data-smoothing/inst/regdatasmooth.m Thu Mar 01 16:53:32 2012 +0000 +++ b/main/data-smoothing/inst/regdatasmooth.m Thu Mar 01 17:18:34 2012 +0000 @@ -63,12 +63,20 @@ function [yhat, lambda] = regdatasmooth (x, y, varargin) + if (nargin < 2) + print_usage; + elseif ( length(x) != length(y) ) + error("x and y must be equal length vectors") + endif + if ( isrow(x) ) x = x'; endif + if ( isrow(y) ) y = y'; endif + ## defaults d = 2; lambda = 0; stdev = 0; guess = 0; - + ## parse options for d, lambda, stdev, gcv, lguess; ## remaining options (gridx, Nhat, range, relative, midpointrule) ## will be sent directly to the core function @@ -98,19 +106,8 @@ endif varargin(idx) = []; options = varargin; - ## add warning if more than one gcv, lambda, or stdev options provided? - if ( length(x) != length(y) ) - error("x and y must be equal length vectors") - endif - if ( size(x,1) == 1 ) - x = x'; - endif - if ( size(y,1) == 1 ) - y = y'; - endif - maxiter = 50; if (lambda) ## do nothing and use the provided lambda @@ -145,7 +142,6 @@ endfunction - %!demo %! npts = 100; %! x = linspace(0,2*pi,npts)';
--- a/main/data-smoothing/inst/rgdtsmcore.m Thu Mar 01 16:53:32 2012 +0000 +++ b/main/data-smoothing/inst/rgdtsmcore.m Thu Mar 01 17:18:34 2012 +0000 @@ -48,6 +48,10 @@ function [yhat, v] = rgdtsmcore (x, y, d, lambda, varargin) + if (nargin < 4) + print_usage; + endif + ## Defaults if not provided xhatprov = 0; xhat = x;
--- a/main/data-smoothing/inst/rgdtsmcorewrap.m Thu Mar 01 16:53:32 2012 +0000 +++ b/main/data-smoothing/inst/rgdtsmcorewrap.m Thu Mar 01 17:18:34 2012 +0000 @@ -24,12 +24,15 @@ ## @seealso{regdatasmooth} ## @end deftypefn +function out = rgdtsmcorewrap (log10lambda, x, y, d, mincell, varargin) -function out = rgdtsmcorewrap (log10lambda, x, y, d, mincell, varargin) + if (nargin < 5) + print_usage; + endif lambda = 10^(log10lambda); - if ( length(mincell) == 2 ) # using stdev to find optimal lambda + if ( length(mincell) == 2 ) # using stdev to find optimal lambda stdev = mincell{2}; yhat = rgdtsmcore (x, y, d, lambda, varargin{:}); @@ -58,7 +61,7 @@ stdevd = std(y-yhat); endif endif - + out = (stdevd - stdev)^2; else # use gcv to find optimal lambda