www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cglookuptwo/bpopt.m
function [om,OK, msg]=bpopt(LT, sf) %BPOPT % % creates an optimMgr for optimising the breakpoints of LT % [om, OK] = bpopt(LT) % [LT, cost, OK, varargout] = run(om, LT, [], var, expr, range) % varargout contains the spline data that we develop % Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. if ~isfill(LT) OK = 0; msg = 'The table is empty or incomplete.'; om = []; return end tablename = getname(LT); om= contextimplementation(xregoptmgr,LT,@i_bpopt,[],['OptBP_' tablename],@bpopt); eq = get(sf, 'model'); if isempty(eq) om = []; OK = 0; msg = 'This subfeature has no model associated with it.'; return end % are all the variables in the table also in the equation? [tableVariables , problemVar, otherVariables]= getvariables(LT,eq); if ~isempty(problemVar) OK = 0; msg = problemVar; om = []; else Norm = get(LT, 'x'); BP = Norm.get('BreakPoints'); numgridpts = 3*length(BP); tableVarObj = infoarray(tableVariables); for i = 1:length(tableVariables) range = getrange(tableVarObj{i}); omi = omlinspace(tableVarObj{i}, range(1), range(2), numgridpts); om = AddOption(om,['Set_' getname(tableVarObj{i})], omi, 'xregoptmgr', getname(tableVarObj{i})); end % Set other variables to their setpoints varObj = infoarray(otherVariables); for i = 1:length(otherVariables) val = getnomvalue(varObj{i}); omi = omlinspace(varObj{i}, val, val, 1); om= AddOption(om,['Set_' getname(varObj{i})], omi, 'xregoptmgr', getname(varObj{i})); end %non-guisettable option to update the history or not (set to zero when an intermediate step) om= AddOption(om,'UpdateBPHistory',1, 'boolean', [],false); om = AddOption(om,'OptBPOrder',0, 'boolean', 'Reorder Deleted Breakpoints'); om = AddOption(om,'FixEndPoints',1, 'boolean', 'Fixed Endpoints',false); % add a flag to say if we are in an abnormal case or not om= AddOption(om,'AbnormalFlag',0, 'boolean', [], false); OK = 1; msg = ''; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [LT,cost,OK, msg] = i_bpopt(LT,om,~,sf) % % The method proceeds as follows: firstly evaluate the model over the chosen grid and then use this grid and surface % to generate a spline approximation to the surface. To determine whether the current choice of breakpoints is any % good we need to create a lookup table based on the new breakpoints that approximates the model. To do this evaluate % the spline at the new breakpoint positions and use the resulting matrix as the values matrix in the lookup table. % The optimising function then evaluates the lookup table over the chosen grid and subtracts this from the model values % at these values seeking to minimise the difference. % optbporder = get(om, 'OptBPOrder'); abnormalflag = get(om, 'AbnormalFlag'); if optbporder % call the total BP opt routine that reorders breakpoints [LT, cost, OK, msg] = BP_totalopt(LT,om, sf); else if ~abnormalflag % call the basic BP opt routine [LT, cost, OK, msg] = BP_opt(LT,om, sf); else error(message('mbc:cglookup:ObsoleteOption','AbnormalFlag')) end end