1 ## Copyright (C) 2008 Jonathan Stickel <jonathan.stickel@nrel.gov>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{cve} =} rgdtsmcorewrap (@var{log10lambda}, @var{x}, @var{y}, @var{d}, @var{mincell}, @var{options})
18 ## @deftypefnx {Function File} {@var{stdevdif} =} rgdtsmcorewrap (@var{log10lambda}, @var{x}, @var{y}, @var{d}, @var{mincell}, @var{options})
20 ## Wrapper function for rgdtsmcore in order to minimize over
21 ## @var{lambda} w.r.t. cross-validation error OR the squared difference
22 ## between the standard deviation of (@var{y}-@var{yhat}) and the given
23 ## standard deviation. This function is called from regdatasmooth.
24 ## @seealso{regdatasmooth}
27 function out = rgdtsmcorewrap (log10lambda, x, y, d, mincell, varargin)
33 lambda = 10^(log10lambda);
35 if ( length(mincell) == 2 ) # using stdev to find optimal lambda
37 yhat = rgdtsmcore (x, y, d, lambda, varargin{:});
41 for i = 1:length(varargin)
42 if strcmp(varargin{i},"relative")
44 elseif strcmp(varargin{i},"xhat")
51 idx = interp1(xhat,1:length(xhat),x,"nearest");
53 stdevd = std((y-yhat(idx))./y);
55 stdevd = std(y-yhat(idx));
59 stdevd = std((y-yhat)./y);
65 out = (stdevd - stdev)^2;
67 else # use gcv to find optimal lambda
68 [yhat, out] = rgdtsmcore (x, y, d, lambda, varargin{:});