www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/setinitialvaluedatafromtablevalues.m
function optim = setinitialvaluedatafromtablevalues(optim, pInp, pTab) %SETINITIALVALUESDATAFROMTABLEVALUES Set initial values from table values. % % OPTIM = SETINITIALVALUEDATAFROMTABLEVALUES(OPTIM, pINP, pTAB) sets % optimization initial values from table values. The required initial % values (pINP) are set to the values of the matched table (pTAB). % % Notes on the matched tables: % 1. The matched tables must all have the same inputs % 2. The inputs used for the matched tables are those specified in the % optimization % % See also CGOPTIM/SETINITIALVALUEDATAFROMTABLEBREAKS % Copyright 2006-2011 The MathWorks, Inc. % If no inputs specified, then return nInp = length(pInp); if ~nInp return end % All table inputs must be dependent on the optimization free/fixed % variables cTabInps = pveceval(pTab, @getinports); pTabInp = unique([cTabInps{:}]); [isIndep, pDepInp] = cgisindependentvars(pTabInp, ... [getfreevalues(optim), getfixedvalues(optim)]); if any(isIndep) error(message('mbc:cgoptim:InvalidArgument37')); end % All dependent inputs must have a common length or be scalar depInpVal = getinitialvaluedata(optim, pDepInp); lenInpVal = cellfun('size', depInpVal, 2); maxLen = max(lenInpVal); if ~all(lenInpVal == 1 | lenInpVal == maxLen) error(message('mbc:cgoptim:InvalidArgument38')); end % Specified inputs must be independent of the table axis inputs if ~all(cgisindependentvars(pInp, pTabInp)) error(message('mbc:cgoptim:InvalidArgument39')); end % Evaluate the tables at the input values specified by the optimization tabData = pveceval(pTab, @evaluatematrix, pDepInp, depInpVal); % Set the table data into the required input for the optimization for n = 1:length(pInp) optim = setinitialvaluedata(optim, pInp(n), ... 1:getNumRuns(optim), tabData{n}); end % OBJ = SETINITIALVALUESDATAFROMTABLES(OBJ, pBASE, pINP, pMATCH, FILTERS) % imports data from a set of tables. pBASE, must be a pointer to a table % in CAGE. pINP must be a vector of pointers to the variables that % initial values should be set for. pMATCH must be a vector of pointers, % the same size as pINP, which gives the source of the data for each % variable. Each element of pMATCH must either be: % % a) A pointer to a table sharing the same grid points and normalizers as % pBASE. The data imported will be the values in the table. % % or % % b) One of the normalizers of pBASE. The data imported will be the % gridded values in the normalizers. % % FILTERS must be a 1-by-4 boolean vector. Each element of FILTERS % indicates whether the data for the following cells (based on the base % table) will be exported % % FILTERS(1): Export data from cells in extrapolation mask % FILTERS(2): Export data from cells not in extrapolation mask % FILTERS(3): Export data from locked cells % FILTERS(4): Export data from unlocked cells % % Note that the number of points exported from the tables after % filtering must match the number of runs in the optimization. % % Determine the grid points to be exported from the tables % extrapMask = pBase.getExtrapolationMask; % lockMask = logical(pBase.get('vlocks')); % extrapCells = false(size(lockMask)); % if Filters(1) % extrapCells(extrapMask) = true; % end % if Filters(2) % extrapCells(~extrapMask) = true; % end % lockedCells = false(size(lockMask)); % if Filters(3) % lockedCells(lockMask) = true; % end % if Filters(4) % lockedCells(~lockMask) = true; % end % exportCells = extrapCells & lockedCells; % % % Is base table 2d? % szBase = size(extrapMask); % if all(szBase > 1) % BASETABLE2D = true; % else % BASETABLE2D = false; % end % % % Initialise match data cell % AllData = cell(1, length(pMatch)); % % % Find any gridded base table normalizer data % pXNorm = pBase.get('x'); % AllData = i_getNormValues(AllData, pXNorm, pMatch, exportCells, szBase, false); % if BASETABLE2D % pYNorm = pBase.get('y'); % AllData = i_getNormValues(AllData, pYNorm, pMatch, exportCells, szBase, true); % end % % % Find any data from table values % AllData = i_getTableValues(AllData, pMatch, exportCells); % % % Set the data in the optimization % RunsToImport = 1:getNumRuns(optim); % for n = 1:length(pMatch) % optim = setinitialvaluedata(optim, pInp(n), RunsToImport, AllData{n}); % end % % %-------------------------------------------------------------------------- % function AllData = i_getNormValues(AllData, pXNorm, pMatch, exportCells, ... % szBase, isyNorm) % %-------------------------------------------------------------------------- % % idxXNorm = findptrs(pXNorm, pMatch); % if idxXNorm % xNorm = pXNorm.get('Breakpoints'); % if isyNorm % xNorm = repmat(xNorm, 1, szBase(2)); % else % xNorm = repmat(xNorm', szBase(1), 1); % end % xNorm = xNorm(exportCells); % xNorm = {xNorm(:)}; % AllData(idxXNorm) = xNorm; % end % % %-------------------------------------------------------------------------- % function AllData = i_getTableValues(AllData, pMatch, exportCells) % %-------------------------------------------------------------------------- % % % Determine which of the matching pointers are tables % istab = parrayeval(pMatch, @istable, {}, mbclogical); % % % Get the data for all the tables % AllData(istab) = pveceval(pMatch(istab), @i_getTableData, exportCells); % % %-------------------------------------------------------------------------- % function TabData = i_getTableData(Table, exportCells) % %-------------------------------------------------------------------------- % % TabData = get(Table, 'values'); % TabData = TabData(exportCells);