www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@mdev_local/RemoveOutliersForTest.m
function mdev = RemoveOutliersForTest(mdev,TestNumber, LocalSelectionCriteria,doUpdate) %REMOVEOUTLIERSFORTEST Refit models after removing outliers % % mdev = REMOVEOUTLIERSFORTEST(mdev,TestNumber,LocalSelCriteria,GlobalSelCriteria) % applies the selected outliers and then refits all local models and % response features. % % Inputs % TestNumber - Single test number to refit. % LocalSelectionCriteria - Local outlier selection MATLAB file or indices % doUpdate - Update response feature models after removing outliers % (default= true). This may take some time to run with large % projects. % % Selection rules are implemented by providing a handle to a function % with the interface: % % Indices = func(model, data, factorName) % % The factors are the same as they appear in the scatter plot in the model % browser. 'data' contains the factors as columns of a matrix. % 'factorNames' is a cell array of the names for each factor. % % See also MDEV_LOCAL/REMOVEOUTLIERS, MODELDEV/REMOVEOUTLIERS. % Note it is also possible to use a specical array to do standard types of % outlier removal (available from popmenus in model browser dialog). This % option is not documented because of its complexity % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. L= model(mdev); OutlierIndices= []; if nargin>=3 if ischar(LocalSelectionCriteria) || iscell(LocalSelectionCriteria); if iscell(LocalSelectionCriteria) LocalSelectionCriteria=LocalSelectionCriteria{1}; end set(L,'outliers',LocalSelectionCriteria); mdev= model(mdev,L); else % outlier indices specified OutlierIndices= LocalSelectionCriteria; if islogical(OutlierIndices) OutlierIndices= find(OutlierIndices); end end end if nargin<4 doUpdate = true; end if ~islogical(doUpdate) || ~isscalar(doUpdate) warning(message('mbc:mbcmodel:Obsolete7a10')) GlobalSelectionCriteria = doUpdate; doUpdate = true; else GlobalSelectionCriteria = []; end if isempty( get(L,'outliers') ); set(L,'outliers',DefaultOutliers(L)); mdev= model(mdev,L); end Yall = getdata(mdev); Ns= size(Yall,3); Spos = tstart(Yall); NewOutliers = []; if numel(TestNumber)~=1 || ~isnumeric(TestNumber) || TestNumber<1 || TestNumber>Ns error(message('mbc:mdev_local:InvalidIndex')) end if ~isempty(OutlierIndices) % outlier indices if min(OutlierIndices)<1 || max(OutlierIndices)>size(Yall{TestNumber},1); error(message('mbc:mdev_local:InvalidIndex1')) end % build list of record indices RecInd= Spos(TestNumber) + OutlierIndices-1; NewOutliers = RecInd(:); else % select outliers using rule [~,~,DataOK]= FitData(mdev,TestNumber); DataIndex = find(DataOK); [~,~,~,olIndex] = diagnosticStats(mdev,TestNumber); % build list of record indices RecInd= Spos(TestNumber) + DataIndex(olIndex)-1; NewOutliers = [ NewOutliers ; RecInd(:) ]; end if ~isempty(NewOutliers) % update outliers NewOutliers= unique([outliers(mdev) ; NewOutliers]); mdev= info( outliers(mdev,NewOutliers) ); % fit local model [~,mdev]= fitmodel(mdev,TestNumber); if doUpdate % refit response features mdev = UpdateLinks(mdev,3); else % set status to zero so users don't inadvertently rely on results mdev = ClearLinks(mdev); end if ~isempty(GlobalSelectionCriteria) % remove outliers from response features children(mdev,@RemoveOutliers,GlobalSelectionCriteria); end end