www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/+mbcboundary/Model.m

    classdef Model < mbcboundary.AbstractBoundary
    %MBCBOUNDARY.MODEL boundary model class
    %    The mbcboundary.Model class represents the basic boundary model types
    %    in the Model-Based Calibration toolbox software. Boundary models can
    %    be fitted in mbcmodel projects using the boundary tree class
    %    mbcboundary.Tree or can be fitted directly to data.
    %
    %    mbcboundary.Model properties:
    %        Name           - name of boundary model (read only)
    %        NumberOfInputs - number of inputs (read only)
    %        Type           - boundary model type (read only)
    %        Inputs         - boundary model inputs
    %        FitAlgorithm   - fit algorithm for boundary model
    %        Fitted         - indicates whether boundary model has been fitted (read only)
    %        ActiveInputs   - active inputs for boundary model
    %
    %    mbcboundary.Model methods:
    %        CreateBoundary      - create a new boundary model
    %        getAlternativeTypes - list of alternative boundary model types
    %        Evaluate            - evaluate boundary model
    %        designconstraint    - convert boundary model to a design constraint
    %        Fit                 - fit boundary with data
    %
    %    Boundary models can be combined using the logical operators &, | and ~.
    %
    %See also Tree, mbcboundary.CreateBoundary, mbcboundary.Fit, getAlternativeTypes 

%  Copyright 2009-2011 The MathWorks, Inc.

    properties (Dependent)
        %ACTIVEINPUTS active inputs for boundary model
        %    ActiveInputs is a logical row vector indicating which inputs
        %    are used to fit a boundary. You may find it useful to build
        %    boundary models using subsets of input factors. You can then
        %    combine them for the most accurate boundary. This approach can
        %    be more effective than including all inputs.  
        ActiveInputs
    end        
    
   methods (Hidden)
       function B = Model(con,varargin)
           %Model - constructor not intended for public calls
           if nargin==0
              con = constar; 
           end
           B = B@mbcboundary.AbstractBoundary(con,varargin{:});
       end
   end
   methods 
       % public methods
       function B = Fit(B,data)
           %FIT fit a boundary model to data
           %    B = Fit(B,data);
           %    The data must be a matrix with one column for each input to
           %    the boundary model.
           
           narginchk(1,2)
           mbcboundary.AbstractBoundary.assertScalar(B);
           
          if ~isa(data,'double') || size(data,2)~=B.NumberOfInputs
              error('mbc:mbcboundary:model:InvalidValue',...
                  'The data be a double matrix with %d columns.',B.NumberOfInputs)
          end
          
           % main call to fit
           if ~isempty(B.FitAlgorithm)
               opts = getObject(B.FitAlgorithm);
           else
               opts = [];
           end
           if isempty(opts)
               % use default fit options
               opts = getFitOptions(B.Object,'all');
           end
           [B.Object,Status] = ...
               fit(B.Object,'all',opts,data,[],[]);
           B.Fitted = Status~=0;
       end
       
       function v = get.ActiveInputs(B)
           v = false(1,B.NumberOfInputs);
           v(getActiveIndices(B.Object)) = true;
       end

       function B = set.ActiveInputs(B,ActiveInputs)
           if islogical(ActiveInputs) && isequal(size(ActiveInputs),[1 B.NumberOfInputs])
               indices = find(ActiveInputs);
               [mn, mx] = nActiveFactorsAllowed( B.Object );
               if length(indices)<mn
                     error(message('mbc:mbcboundary:model:InvalidValue1', B.Type, mn( 1 )))
               end
               if length(indices)>mx
                     error(message('mbc:mbcboundary:model:InvalidValue2', B.Type, mn( 1 )))
               end
               if ~isequal(B.ActiveInputs,ActiveInputs)
                   B.Object = setActiveIndices(B.Object,indices);
                   % refresh algorithm
                   B = resetAlgorithm(B);
               end
           else
               error(message('mbc:mbcboundary:model:InvalidValue3', B.NumberOfInputs))
           end
       end       

       function [OptionNames,ObjectIndex,OptionObjects] = getAlternativeTypes(obj)
           %GETALTERNATIVETYPES list of boundary model types
           %    Types = getAlternativeTypes(obj);
           %    Types is a list of boundary model types which could be
           %    used as alternative boundary model types for the current
           %    boundary model.
           %
           %See also Type

           % undocumented
           % [OptionNames,ObjectIndex,OptionObjects] = getAlternativeTypes(obj)

           mbcboundary.AbstractBoundary.assertScalar(obj);

           c = obj.Object;
           if ~isempty(c)
               opts = {'conrange','conellipsoid','constar','conconvexhull'};
               [OptionObjects, OptionNames, ObjectIndex] = pGenerateObjectList(c, opts);
               OptionNames = OptionNames(:);
           else
               error(message('mbc:mbcboundary:model:InvalidState', class( obj )))
           end
       end
       
   end
       
   methods (Access=protected)
       
       function B = Reset(B)
           %RESET clear out private fit results properties
           B.Fitted = false;
       end
       function B = pInitialise(B,con)
           %PINITIALISE initialise with a con* object
           if isempty(B.Object) || ~isequal(con,B.Object)
               OldObject = B.Object;
               if ~isempty(OldObject )
                   AF = B.ActiveInputs;
                   B.Object = con;
                   % copy active inputs from old object
                   B.ActiveInputs= AF;
               else
                   B.Object = con;
               end
               B = resetAlgorithm(B);
           end
       end
       
   end

end % classdef