www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@modeldev/childstats.m
function [Stats,List,Width] = childstats(mdev) %CHILDSTATS Return the statistics for all child models % % [STATS, NAMES, WIDTH] = CHILDSTATS(MDEV) returns the information for all % statistics that are common to all of the child model nodes of MDEV. % STATS is a matrix of statistics values, with each row corresponding to a % child model node. NAMES is a cell array of statistic names, one for % each column in STATS. WIDTH is a vector of suggested listview column % widths and is the same length as STATS. % Copyright 2000-2008 The MathWorks, Inc. and Ford Global Technologies, Inc. Stats= children(mdev,@statistics); ch= children(mdev); N= numChildren(mdev); % find out whether comparisons are ok DataType= i_FindDataType(mdev); switch N case 0 % no submodels List={}; s= zeros(N,0); Width=s; case 1 % only 1 submodel [List,Width]= colhead( info( ch(1) ) ); s= Stats{1}; otherwise % more than 1 sub model % Set up Summary stats for the first child [~,Width]= colhead( info(ch(1)) ); [List,ind]= i_StatsList(info(ch(1)),DataType); if isempty(Stats{1})|| all(isnan(Stats{1})) % stats is wrong size so make everything NaN s= NaN(size(List)); else s= Stats{1}(ind); end Width= Width(ind); for i=2:N % List for current submodel [CurrentList,ind]= i_StatsList(info(ch(i)),DataType); % stats for current model (could exclude some stats for data) if isempty(Stats{i}) || all(isnan(Stats{i})) % stats is wrong size so make everything NaN sCurrent= NaN*zeros(size(CurrentList)); else sCurrent= Stats{i}(ind); end % check if used in previous lists [ok,loc]= ismember(List,CurrentList); % keep common List and Width Items List= List(ok); Width= Width(ok); % concantenate stats s= [s(:,ok) ; sCurrent(loc(loc~=0))]; end % Normalise Width Width= Width/sum(Width); end Stats= s; % add validation stats RMSE=iGetValidationRMSE(mdev); if ~isempty(RMSE) % add validation RMSE List= [List 'Validation RMSE']; Stats= [Stats RMSE]; Width= [Width Width(end)]; % Normalise Width Width= Width/sum(Width); end function [List,ind]= i_StatsList(mdev,Type) %STATSLIST if nargin<2 Type= 'summary'; end if nargout>1 && ~strcmp(Type,'summary'); List= StatsList(mdev.Model,Type); SummaryList= StatsList(mdev.Model,'summary'); [~,ia,~]= intersect(SummaryList,List); ind= sort(ia); else List= colhead(mdev); ind= 1:length(List); end function DataType= i_FindDataType(mdev) N= numChildren(mdev); SameData= true; if N>1 && any(strcmp(class(mdev),{'modeldev','mdevmlerf'}) ) && ~isa(mdev.Model,'xregtwostage') Ydata= children(mdev,@getdata,'Y'); Stats= children(mdev,@statistics); Status = children(mdev,@status); bc=Stats{1}(3); % check if outliers the same ga = getGuids(Ydata{1}(isbad(Ydata{1}))); for i=2:N % check that same data and transform is used for all children % ignore children where model is not fitted SameData = SameData && ... (Status{i}==0 || (isequal( ga, getGuids( Ydata{i}(isbad(Ydata{i})) ) ) && ... % Same outliers Stats{i}(3)==bc)); % box-cox transform is the same end end if SameData DataType= 'summary'; else DataType= 'data'; end function RMSE=iGetValidationRMSE(mdev) ch = children(mdev); RMSE= []; if ~isempty(ch) [Xdata,Ydata]= getValidationData(ch(1).info); if ~isempty(Xdata); if isa(mdev,'mdevtestplan') RMSE= children(mdev,@ValidationRMSE); else RMSE= children(mdev,@ValidationRMSE,Xdata,Ydata); end RMSE= [RMSE{:}]'; end end