www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimrunner/evaluateObjective.m

    function [varargout] = evaluateObjective(obj, X, ItemNames, varargin)
%EVALUATEOBJECTIVE Evaluate optimization objectives 
%
%   Y = EVALUATEOBJECTIVE(OBJ, X) evaluates all of the optimization
%   objectives at the free variable values X.  X must be a
%   (NPoints-by-NFreeVar) matrix where NPoints is the number of points to
%   be evaluated and NFreeVar is the number of free variables in the
%   optimization. The values of the objectives are returned in Y, which is
%   of size (NPoints-by-NItems) where NItems is the number of objectives in
%   the optimization.
%
%   Y = EVALUATEOBJECTIVE(OBJ, X, ITEMNAMES) evaluates the objectives
%   specified in the cell array of strings, ITEMNAMES, at the free variable
%   values X.  The values of the objectives are returned in Y, which is of
%   size (NPoints-by-NItems) where NItems is the number of objectives
%   listed in ITEMNAMES.
%
%   Y = EVALUATEOBJECTIVE(..., 'EvaluationType', EVALTYPE) specifies the
%   quantity to be evaluated.  The available evaluation quantities  and the
%   default setting depend on whether the object was constructed for
%   running or for the optimization output.
%
%   Y = EVALUATEOBJECTIVE(..., 'FixedValueSource', FIXEDARGS) specifies
%   how the fixed value data is generated.  FIXEDARGS is a cell array
%   containing an option type and a variable number of option parameters.
%   The valid settings for FIXEDARGS are:
%
%      {'currentrun'}     : Use the current run's fixed values for each 
%                           free value.
%      {'runs', RUNIDX}   : Use the specified runs' fixed values, matching
%                           values from each successive run to each
%                           successive free value.
%
%   [Y, YG] = EVALUATEOBJECTIVE(...) also evaluates the gradient of the
%   specified objectives in YG (if ITEMNAMES is not specified, then the
%   gradient of all objectives is returned). YG is of size
%   NFreeVar-by-NItems-by-NPoints, where NFreeVar is the number of free
%   variables in the optimization.

%  Copyright 2005 The MathWorks, Inc.


% Parse optional arguments
FixedValArgs = {};
EvalType = obj.DefaultEvaluationType;
for n = 1:2:length(varargin)
    switch lower(varargin{n})
        case 'evaluationtype'
            EvalType = varargin{n+1};
        case 'fixedvaluesource'
            FixedValArgs = varargin{n+1};   
    end
end

ItemData = pGetItemDataFor(obj.Objectives, EvalType);

if nargin>2 && ~isempty(ItemNames)
    ItemInd = getObjectiveIndex(obj.Setup, ItemNames);    
else
    ItemInd = [];
end

[varargout{1:nargout}] = pEvaluateItems(obj, ItemData, X, ItemInd, FixedValArgs{:});