www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xreglinear/minpress.m

    function [om,ok]= minpress(m)
%MINPRESS minimum press least squares fit

%  Copyright 2000-2006 The MathWorks, Inc. and Ford Global Technologies, Inc.

om= contextimplementation(xregoptmgr,m,@i_minpress,[],'Minimize PRESS',@minpress);

om= AddOption(om,'MaxIter',50,{'int',[1 1000]},'Maximum Iterations');% field to maximum number of iterations
om= AddOption(om,'guidisplay',0,'boolean',[],false);% field to store cost (GCV)
om= AddOption(om,'isinitialised',0,'boolean',[],false);% flag to skip initial fit

AllOpts= {@lsqom, @minpress, @forwardselect, @backwardselect, @prune};
om = setAltMgrs(om,AllOpts);

ok=1;

function [m,cost,OK,NewPRESS,B]= i_minpress(m,om,x0,varargin)

disp   = get(om,'guidisplay');
if disp
	ud= x0;
end

OK=1;
maxiter= get(om,'MaxIter');
if ~get(om,'isInitialised')
	[m,OK]= leastsq(m,varargin{:});
end

if OK
	[m,OK,NewPRESS,B]= stepwise(m);
	% Determine Best Next Step
	NextPress= B(:,end);
	[MinPress,PressInd]= nanmin(NextPress);
	count=1;
	% Limit search to a maximum of 50 steps
	while MinPress < NewPRESS && count<maxiter
		% Do step
		[m,OK,NewPRESS,B]= stepwise(m,PressInd);
		% Determine Best Next Step
		if OK
			NextPress= B(:,end);
			[MinPress,PressInd]= nanmin(NextPress);
			% Update History Plot
			if disp
				% intermediate display in stepwise figure
				feval(ud.UpdateHistory, NewPRESS,m,gcbf, ud.Hand.HistAxes);
				% Update Anova and Stats Tables
				gui_diagstats(m, 'display',ud.Stats);
				drawnow
			end
		else
			break;
		end
		count=count+1;
	end
	if ~OK
		% recalculate previous iteration (it was OK)
		[m,OK,NewPRESS,B]= stepwise(m);
	end
	cost= NewPRESS;
else
	cost=Inf;
	NewPRESS=[];
	B=[];
end