www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@modeldev/BestModel.m
function bm=BestModel(mdev,p,Climb) %BESTMODEL return or assign best model for modeldev % % bm= BestModel(mdev); returns % mdev= BestModel(mdev,p); % p is pointer to modeldev object % assigns bestmodel to the model % this copies model, statistics and outliers from p to mdev % Copyright 2000-2006 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin==1 if isa(mdev.BestModel,'xregpointer') if mdev.BestModel==0 % best model is current node bm= mdev.Model; else % get best model from child bm= BestModel(info(mdev.BestModel)); end else bm= mdev.BestModel; end else if nargin<3 Climb=0; end if isa(p,'xregpointer') ch= children(mdev); AssignedBest= false; if p~=0 && ~isempty(p.BestModel) % copy model info up tree NewModel= p.BestModel; mdev.Statistics= p.statistics; OldModelName= name(mdev.Model); if strncmp(OldModelName,name(mdev),length(OldModelName)) % name needs updating if it has the node has the same name % as the old model mdev= name(mdev,name(NewModel)); if isBrowserProject(mdev) mbH= MBrowser; % this updates the node on the modelbrowser tree. try mbH.doDrawTree(address(mdev)); end end end mdev.Model= NewModel; mdev.Outliers= p.outliers; pointer(mdev); if Climb==0 % assign status of p to 2 to indicate it is the best model p.status(2,0); % make current node status 1 - > this will trigger autobest selection if only one child mdev= status(mdev,1); end AssignedBest= true; end % make sure all other children are not best st= children(mdev,@status); st= [st{:}]; if any(st(ch~=p)==2) children(mdev,st==2 & ch~=p,@status,1,0); end if ~AssignedBest && mdev.Status==2 % set status back to one mdev= status(mdev,1,Climb); end end mdev.BestModel= p; pointer(mdev); bm=mdev; end