www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@xregdesign/gui_augmethods.m

    function [s,defnum]=gui_augmethods(d)
%GUI_AUGMETHODS  Return structure of augmentation methods
%
%  [S,DEFAULT]=GUI_AUGMETHODS(D)
%
%  See also:  GUI_ADDPOINTS

%  Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.


s=struct('Name',{'Random','User-specified'},...
    'CreateFcn',{@i_createrandom, @i_createuser},...
    'FinaliseFcn',{@i_finaliserandom, @i_finaliseuser},...
    'NPointsFcn',{@iNumPts, @i_NPuser});
defnum=[1 1];

% only provide extend option if design is a Sobol or Halton
if any(strcmp(getstyleinfo(d), {'Sobol Sequence', 'Halton Sequence'}))
    newS = struct('Name', {sprintf('Extend %s', getstyleinfo(d))}, ...
        'CreateFcn',{@i_createExtend},...
        'FinaliseFcn',{@i_finaliseextend},...
        'NPointsFcn',{@iNumPts});
    s = [newS, s];
    defnum = [1, defnum];
end

% add spacefilling if appropriate



%%%%%%%%%%%%%%%%%%%%%%%%%%%
% user-specified settings %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
function L = i_createuser(F,pD)
des=pD.info;
initval=invcode(model(des),midpoint(des));
nf=nfactors(des);

udh=xregGui.RunTimePointer;
udh.LinkToObject(F);

ud.nfactors=nf;
ud.initval=initval;

ud.Npts=xregGui.labelcontrol('parent',F,...
   'visible','off',...
   'string','Number of points:',...
   'labelsizemode','absolute',...
   'labelsize',100,...
   'controlsizemode','absolute',...
   'controlsize',60,...
   'gap',5,...
   'Control',mbcgui.widget.Spinner('Parent',F,...
   'Value',1,...
   'ClickIncrement',1,...
   'Min',1,...
   'Max',1000,...
   'Rule','int',...
   'Visible','off',...
   'Callback',{@i_user_numpts,udh}));

ud.table=xregtable(F,...
   'position',[0 0 300 70],...
   'frame.visible','off',...
   'frame.hborder',[0 0],...
   'frame.vborder',[0 0],...
   'cols.size',60,...
   'cells.defaultbackgroundcolor',[1 1 1],...
   'rows.number',2,...
   'cols.number',nf,...
   'rows.fixed',1,...
   'cells.rowselection',[1 1],...
   'cells.colselection',[1 nf],...
   'cells.type','uiemuedit0',...
   'cells.enable','inactive',...
   'cells.string',factors(des)',...
   'cells.rowselection',[2 2],...
   'cells.value',initval,...
   'zeroindex',[2 1]);

L=xreggridbaglayout(F,'dimension',[2 1],...
   'rowsizes',[20 -1],...
   'gapy',10,...
   'elements',{ud.Npts,ud.table},...
   'userdata',udh);

udh.info=ud;



function i_user_numpts(src,~,udh)
ud=udh.info;
val=get(src,'Value');
rowsnow=ud.table.rows.number-1;
if val<rowsnow
   % remove rows   
   ud.table.rows.number=val+1;    
elseif val>rowsnow
   % add rows
   ud.table.rows.number=val+1;
   initval=ud.initval;
   initval=repmat(initval,val-rowsnow,1);
   % populate with values
   ud.table.value(rowsnow+1:end,:)=initval;
end



function i_finaliseuser(L,pD,sel)
udh = get(L,'UserData');
ud=udh.info;
data=ud.table(:,:);
des=pD.info;
data=code(model(des),data);
des=augment(des,data,'points');
pD.info=des;



function np=i_NPuser(L,pD,np)
udh = get(L,'UserData');
ud=udh.info;
if nargin>2
   ud.Npts.Control.Value=np;
   i_user_numpts(ud.Npts.Control,[],udh);  % redraw table
else
   np=ud.Npts.Control.Value;
end





%%%%%%%%%%%%%%%%%%%%%%%%%%
% Random points settings %
%%%%%%%%%%%%%%%%%%%%%%%%%%
function L = i_createrandom(F,pD)
ud.Npts=xregGui.labelcontrol('parent',F,...
   'visible','off',...
   'string','Number of points:',...
   'labelsizemode','absolute',...
   'labelsize',110,...
   'controlsizemode','absolute',...
   'controlsize',50,...
   'gap',5,...
   'Control',mbcgui.widget.Spinner('Parent',F,...
   'Value',1,...
   'ClickIncrement',1,...
   'Visible','off',...
   'Min',1,...
   'Max',1000,...
   'Rule','int'));

L=xreggridbaglayout(F,'dimension',[1 1],...
   'rowsizes',20,...
   'packstatus','off',...
   'elements',{ud.Npts},...
   'userdata',ud);







function i_finaliserandom(L,pD,sel)
ud = get(L,'UserData');
des=pD.info;

Np=get(ud.Npts.Control,'Value');

% push in new candidate set and use that new design to generate points for the original one
% (This will make sure the constraints are used).

cs=candspace(des);
lims=limits(cs);
nf=nfactors(des);
lvls=cell(nf,1);
for n=1:nf
   lvls{n}=linspace(lims(n,1),lims(n,2),21);
end
des_temp=candspace(des,'fullgrid',lvls);

des=augment(des,randcand(des_temp,Np),'points');
pD.info=des;


function np=iNumPts(L,pD,np)
ud = get(L,'UserData');
if nargin>2
   ud.Npts.Control.Value=np;
else
   np=ud.Npts.Control.Value;
end



function L = i_createExtend(F,pD)

des = pD.info;
ud.tabbedPreview = mbcgui.graph.TabbedGraphs(F, min(3,des.nfactors));
factorNames=get(des.model, 'symbol');
ud.tabbedPreview.setFactors(factorNames);
if des.nfactors>1
    ud.tabbedPreview.selectTab(2);
end

ud.NumPts=uicontrol('parent',F,...
   'visible','off',...
   'String', sprintf('Total Constrained Points: %d', des.npoints), ...
   'Style', 'text');

ud.Spinner = mbcgui.widget.Spinner('Parent',F,...
   'Value',1,...
   'ClickIncrement',1,...
   'Visible','off',...
   'Min',0,...
   'Max',1000,...
   'Rule','int', ...
   'Callback', {@iUpdatePreview, pD, ud}, ...
   'Tag', 'AddPointsSpinner');
ud.Npts=xregGui.labelcontrol('parent',F,...
   'visible','off',...
   'string','Number of points:',...
   'labelsizemode','absolute',...
   'labelsize',110,...
   'controlsizemode','absolute',...
   'controlsize',50,...
   'gap',5,...
   'Control',ud.Spinner);

iUpdatePreview(ud.Spinner,[],pD, ud, false);


L=xreggridbaglayout(F,'dimension',[2 2],...
   'rowsizes',20,...
   'packstatus','off',...
   'rowsizes',[18 -1], ...
   'colsizes',[-1 150], ...
   'gapy', 2, ...
   'mergeblock', {[2 2],[1 2]}, ...
   'elements',{ud.Npts, ud.tabbedPreview, ud.NumPts},...
   'userdata',ud);
   
function i_finaliseextend(L,pD,sel)
ud = get(L,'UserData');

% push in new candidate set and use that new design to generate points for the original one
% (This will make sure the constraints are used).

newdes = get(ud.Npts, 'UserData');
if isempty(newdes)
    des=pD.info;
    newdes = extendDesign(des,ud.Npts.Control,false);
end
pD.info=newdes;


function des = extendDesign(des,spinnerControl,showDlg)
fig = ancestor(spinnerControl,'figure');
oldpointer = get(fig, 'pointer');
set(fig, 'pointer', 'watch')
drawnow;

numPointsToAdd = get(spinnerControl, 'Value');
pointsInDesign = des.npoints;
targetPoints = pointsInDesign+numPointsToAdd;
try
    des = generateConstrainedSpaceFill(des,[],targetPoints);
    set(fig, 'pointer', oldpointer)
catch ME
    set(fig, 'pointer', oldpointer)
    switch ME.identifier
        case 'mbc:xregdesign:ExceededMaxIter'
            if showDlg
                errordlg(sprintf('Generating design failed: %s', ME.message), 'Points not found', 'modal')
            end
            set(spinnerControl, 'Value', des.npoints-pointsInDesign)
        otherwise
          rethrow(ME)
    end
end


function iUpdatePreview(src, evt, pD, ud, showDlg)
if nargin<5
    showDlg = true;
end

des=pD.info;
newDes = extendDesign(des,src,showDlg);
set(src, 'UserData', newDes);

set(ud.NumPts, 'String', sprintf('Total Constrained Points: %d', newDes.npoints))

iUpdatePlot(ud.tabbedPreview, newDes, des.npoints);


function iUpdatePlot(tabbedPreview, des, origPoints)

% get design points
data=des.design;
lims=limits(des.candset);
if ~isempty(data)
    % check data isn't outside limits and adjust limits if necessary
    lims(:,1)=min(lims(:,1),min(data,[],1)');
    lims(:,2)=max(lims(:,2),max(data,[],1)');
end

% invcode data
data=invcode(des.model,data);
lims=num2cell(invcode(des.model,lims')',2);


numRows = size(data, 1);
highlight = true(numRows,1);
for i=1:origPoints
    highlight(i) = false;
end
tabbedPreview.setData(data,lims,highlight)