26 gui_State =
struct(
" gui_Name ", mfilename, ...
27 " gui_Singleton ", gui_Singleton, ...
28 " gui_OpeningFcn ", @DEIMEstimatorAnalyzer_OpeningFcn, ...
29 " gui_OutputFcn ", @DEIMEstimatorAnalyzer_OutputFcn, ...
30 " gui_LayoutFcn ", [] , ...
31 " gui_Callback ", []);
32 if nargin && ischar(varargin[1])
33 gui_State.gui_Callback= str2func(varargin[1]);
37 [
varargout[1:nargout]] = gui_mainfcn(gui_State, varargin[:]);
39 gui_mainfcn(gui_State, varargin[:]);
80 handles.output= hObject;
83 guidata(hObject, handles);
87 ip.addRequired(
'Model',@(r)isa(r,
" models.ReducedModel "));
89 ip.parse(varargin[:]);
92 setappdata(handles.main,
" startidx ",res.StartIdx);
96 mu = r.ParamSamples(:,1);
98 setappdata(handles.main,
" mu ",mu);
100 if r.System.InputCount > 0
103 setappdata(handles.main,
" inputidx ",in);
106 e = r.ErrorEstimator;
107 if ~isempty(e) && e.JacSimTransMaxSize > 0 && e.JacSimTransSize == 0
108 e.JacSimTransSize= 1;
110 setappdata(handles.main,
" r ",r);
111 createModelParamSliders(handles,r);
112 modelToGUI(handles, r);
115 sr = r.FullModel.SpaceReducer;
116 if sr.IncludeTrajectoryFxiData
117 extra =
" InclFxiData:yes ";
119 if sr.IncludeFiniteDifferences
120 extra = [extra
" InclFinDiff:yes "];
122 n = sprintf(
" Model '%s', %d-dim, reduced %d-dim, %s ",...
123 r.Name,r.FullModel.Dimension,size(r.V,2),extra);
124 set(hObject,
" Name ",n);
125 set(handles.rbgAlpha,
" SelectionChangeFcn ",@(s,e)rbgAlpha_SelectionChanged(handles,s,e));
126 set(handles.rbgBeta,
" SelectionChangeFcn ",@(s,e)rbgBeta_SelectionChanged(handles,s,e));
127 set(handles.rbg_Param,
" SelectionChangeFcn ",@(s,e)rbgParam_SelectionChanged(handles,s,e));
134 if r.System.ParamCount > 0
136 set(h.slTrainParam,
" Min ",1,
" Max ",size(r.ParamSamples,2),
" Value ",1);
138 parent = h.rbg_Param;
139 set(parent,
" Units ",
" pixels ");
140 pos =
get(parent,
" Position ");
141 set(parent,
" Units ",
" normalized ");
146 pdata.sl= zeros(r.System.ParamCount,1);
147 pdata.lbl= zeros(r.System.ParamCount,1);
148 mu = getappdata(h.main,
" mu ");
149 for pidx = 1:r.System.ParamCount
150 p = r.System.Params(pidx);
153 top = pos(4)-pcnt*dist-40-2*dist;
156 label = uicontrol(
" Tag ",sprintf(
" lblP%d ",pidx),
" Style ",
" text ",...
157 " Parent ",parent,
" HorizontalAlignment ",
" left ");
158 set(label,
" String ",[p.Name
" : "],
" Units ",
" pixels ",...
159 " Position ",[10 top 60 14]);
160 set(label,
" Units ",
" normalized ");
163 label = uicontrol(
" Tag ",[
" runtime_lbll " num2str(pidx)],
" Style ",
" text ",...
164 " Parent ",parent,
" HorizontalAlignment ",
" right ");
165 set(label,
" String ",sprintf(
" %g ",p.MinVal),
" Units ",
" pixels ",...
166 " Position ",[70 top 40 14]);
167 set(label,
" Units ",
" normalized ");
168 label = uicontrol(
" Tag ",[
" runtime_lblr " num2str(pidx)],
" Style ",
" text ",...
169 " Parent ",parent,
" HorizontalAlignment ",
" left ");
170 set(label,
" String ",sprintf(
" %g ",p.MaxVal),
" Units ",
" pixels ",...
171 " Position ",[290 top 40 14]);
172 set(label,
" Units ",
" normalized ");
175 ctrl = uicontrol(
" Tag ",sprintf(
" slP%d ",pidx),
" Parent ",...
176 parent,
" Style ",
" slider ",
" UserData ",pidx);
178 set(ctrl,
" Units ",
" pixels ",
" Position ",...
180 set(ctrl,
" Units ",
" normalized ");
182 set(ctrl,
" Min ",p.MinVal,
" Max ",p.MaxVal,
" Value ",mu(pidx));
183 set(ctrl,
" SliderStep ",[0.01 0.1]);
185 set(ctrl,
" Callback ",@(~,~)(updateUserParam(h)));
186 pdata.sl(pidx) = ctrl;
189 label = uicontrol(
" Tag ",sprintf(
" lblPV%d ",pidx),
" Style ",
" text ",...
190 " Parent ",parent,
" HorizontalAlignment ",
" left ");
191 set(label,
" String ",sprintf(
" %g ",mu(pidx)),
" Units ",
" pixels ",...
192 " Position ",[340 top 40 14]);
193 set(label,
" Units ",
" normalized ");
194 pdata.lbl(pidx) = label;
200 setappdata(h.main,
" pdata ",pdata);
206 r = getappdata(h.main,
" r ");
207 pdata = getappdata(h.main,
" pdata ");
208 pc = r.System.ParamCount;
210 set(h.rbCustomParam,
" Value ",1);
213 if r.FullModel.System.Params(pidx).HasRange
214 mu(pidx) =
get(pdata.sl(pidx),
" Value ");
216 mu(pidx) = r.FullModel.System.Params(pidx).MinVal;
218 s = sprintf(
" %g ",r.System.Params(pidx).Name,mu(pidx));
219 set(pdata.lbl(pidx),
" String ",s);
221 setappdata(h.main,
" mu ",mu);
229 set(h.slM,
" Min ",1,
" Max ",r.System.f.MaxOrder,
" Value ", r.System.f.Order(1));
230 set(h.lblM,
" String ",sprintf(
" %d ",r.System.f.Order(1)));
233 e = r.ErrorEstimator;
234 if ~isempty(e) && e.UseTrueDEIMErr
235 set(h.rbTrueDEIM,
" Value ",1);
237 set(h.rbMD,
" Value ",1);
239 mv = r.System.f.MaxOrder-r.System.f.Order(1);
240 if mv ~= 0, en=
" on ";
else en=
" off "; end
241 set(h.slMD,
" Min ",0,
" Max ",max(mv,1),
" Enable ",en,
" Value ", r.System.f.Order(2));
242 set(h.lblMD,
" String ",sprintf(
" %d ",r.System.f.Order(2)));
246 set(h.slJM,
" Min ",1,
" Max ",e.JacMatDEIMMaxOrder,
" Value ", e.JacMatDEIMOrder);
247 set(h.lblJM,
" String ",sprintf(
" %d ",e.JacMatDEIMOrder));
249 set(h.slK,
" Min ",0,
" Max ",e.JacSimTransMaxSize,
" Value ", e.JacSimTransSize);
250 set(h.lblK,
" String ",sprintf(
" %d ",e.JacSimTransSize));
251 if e.UseTrueLogLipConst
252 set(h.rbtrueloclip,
" Value ",1);
253 elseif e.UseJacobianLogLipConst
254 set(h.rbjacloclip,
" Value ",1);
255 elseif e.UseFullJacobian
256 set(h.rbfulljac,
" Value ",1);
258 set(h.rbjmst,
" Value ",1);
266 fprintf(
" Simulating... ");
267 r = getappdata(h.main,
" r ");
268 mu = getappdata(h.main,
" mu ");
269 in = getappdata(h.main,
" inputidx ");
271 [~, s.y, s.tf, s.x] = r.FullModel.simulate(mu,in);
272 [s.t, s.yr, s.tr, s.xr] = r.simulate(mu,in);
273 setappdata(h.main,
" s ",s);
279 fprintf(
" plotting... ");
280 r = getappdata(h.main,
" r ");
281 s = getappdata(h.main,
" s ");
282 esterr = zeros(size(r.Times));
283 if get(h.rbOutput,
" Value ")
285 Cn = normest(r.FullModel.System.C.C);
286 err = Cn*1e-7*
Norm.
L2(s.x-r.V*s.xr);
290 if ~isempty(r.ErrorEstimator)
291 esterr = r.ErrorEstimator.OutputError;
295 err =
Norm.
L2(s.x-r.V*s.xr);
297 if ~isempty(r.ErrorEstimator)
298 esterr = r.ErrorEstimator.StateError;
301 doPlot(h.axerr,r.Times,err,
" b ");
302 doPlot(h.axrel,r.Times,err./trajnorm,
" b ");
303 if ~isempty(r.ErrorEstimator) && r.ErrorEstimator.Enabled
304 hold(h.axerr,
" on ");
305 doPlot(h.axerr,r.Times,esterr,
" r ");
306 hold(h.axerr,
" off ");
308 hold(h.axrel,
" on ");
309 doPlot(h.axrel,r.Times,esterr./trajnorm,
" r ");
310 hold(h.axrel,
" off ");
312 doPlot(h.axeff,r.Times,esterr./err,
" g ");
318 str = sprintf(
" Times: Full %gs, Red.: %gs, Speedup: %g\n ",s.tf,s.tr,s.tf/s.tr);
319 str = [str sprintf(
" Errors(T=%g): True: %g, Est.: %g,\nRel: %g, Est.Rel.: %g, Eff.:%g ",...
320 r.Times(end),err(end),eest,err(end)/trajnorm(end),eest/trajnorm(end),eest/err(end))];
321 set(h.lblRes,
" String ",str);
322 if ~isempty(r.ErrorEstimator)
323 doPlot(h.axhlp,r.Times,r.ErrorEstimator.LastAlpha,
" m ");
324 doPlot(h.axhlp2,r.Times,r.ErrorEstimator.LastBeta,
" c ");
325 axis(h.axerr,
" tight ");
326 if r.ErrorEstimator.Enabled
327 axis(h.axeff,
" tight ");
328 axis(h.axhlp,
" tight ");
329 axis(h.axhlp2,
" tight ");
332 fprintf(
" done.\n ");
337 startidx = getappdata(
get(h,
" Parent "),
" startidx ");
343 r = getappdata(h.main,
" r ");
344 s = getappdata(h.main,
" s ");
345 mu = getappdata(h.main,
" mu ");
346 [ef,er,fxno] = testing.DEIM.getApproxErrorFullRed(r, s.xr, s.t, mu, r.V);
349 ax = pm.nextPlot(
" deimerr ",
" True and projected approximation error on current trajectory ",
" time ",
" error ");
350 if max(ef)/min(ef) < 100 || max(er)/min(er) < 100
355 plotfun(ax,r.Times,ef,
" b ",r.Times,er,
" r ");
356 legend(
" Full ",
" Projected ");
370 rb =
get(source,
" SelectedObject ");
371 r = getappdata(h.main,
" r ");
372 e = r.ErrorEstimator;
373 switch get(rb,
" UserData ")
375 e.UseTrueDEIMErr=
true;
378 e.UseTrueDEIMErr=
false;
385 rb =
get(source,
" SelectedObject ");
386 r = getappdata(h.main,
" r ");
387 e = r.ErrorEstimator;
388 e.UseTrueLogLipConst=
false;
389 e.UseJacobianLogLipConst=
false;
390 e.UseFullJacobian=
false;
391 e.UseJacobianNorm=
false;
392 switch get(rb,
" UserData ")
394 e.UseTrueLogLipConst=
true;
396 e.UseJacobianLogLipConst=
true;
398 e.UseFullJacobian=
true;
400 e.UseJacobianNorm=
true;
407 rb =
get(source,
" SelectedObject ");
408 switch get(rb,
" UserData ")
410 slTrainParam_Callback(h.slTrainParam, [], h);
419 r = getappdata(handles.main,
" r ");
420 md = round(
get(hObject,
" Value "));
421 if r.System.f.Order(2) ~= md
422 fprintf(
" Setting m "" =%d... ",md);
423 r.System.f.Order= [r.System.f.Order(1) md];
424 r.ErrorEstimator.Enabled= md > 0;
425 set(handles.lblMD,
" String ",sprintf(
" %d ",md));
426 set(handles.rbMD,
" Value ",1);
434 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
435 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
443 r = getappdata(handles.main,
" r ");
444 jm = round(
get(hObject,
" Value "));
445 if r.ErrorEstimator.JacMatDEIMOrder ~= jm
446 fprintf(
" Setting m_j=%d... ",jm);
447 r.ErrorEstimator.JacMatDEIMOrder= jm;
448 set(handles.lblJM,
" String ",sprintf(
" %d ",jm));
456 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
457 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
464 r = getappdata(handles.main,
" r ");
465 k = round(
get(hObject,
" Value "));
466 if r.ErrorEstimator.JacSimTransSize ~=
k
467 fprintf(
" Setting k=%d... ",
k);
468 r.ErrorEstimator.JacSimTransSize=
k;
469 set(handles.lblK,
" String ",sprintf(
" %d ",
k));
477 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
478 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
486 r = getappdata(handles.main,
" r ");
487 m = round(
get(hObject,
" Value "));
488 if r.System.f.Order(1) ~= m
489 fprintf(
" Setting m=%d... ",m);
490 r.System.f.Order= [m min(r.System.f.Order(2),r.System.f.MaxOrder-m)];
491 set(handles.lblM,
" String ",sprintf(
" %d ",m));
494 mv = r.System.f.MaxOrder-m;
495 if mv ~= 0, en=
" on ";
else en=
" off "; end
496 set(handles.slMD,
" Min ",0,
" Max ",max(mv,1),
" Enable ",en,
" Value ", r.System.f.Order(2));
497 set(handles.lblMD,
" String ",sprintf(
" %d ",r.System.f.Order(2)));
505 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
506 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
514 getDEIMErrorsOnTraj(handles);
521 r = getappdata(h.main,
" r ");
523 pm = ma.plotReductionOverview;
524 pm.setFigureNames(sprintf(
" Reduction summary of '%s' ",
get(h.main,
" Name ")));
534 r = getappdata(h.main,
" r ");
535 pidx = round(
get(hObject,
" Value "));
536 mu = r.ParamSamples(:,pidx);
537 if ~isequal(getappdata(h.main,
" mu "),mu)
538 setappdata(h.main,
" mu ",mu);
539 set(h.rbTrainParam,
" Value ",1);
540 pdata = getappdata(h.main,
" pdata ");
541 for pidx = 1:length(mu)
542 set(pdata.sl(pidx),
" Value ",mu(pidx));
543 set(pdata.lbl(pidx),
" String ",sprintf(
" %g ",mu(pidx)));
555 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
556 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
564 r = getappdata(h.main,
" r ");
566 s = getappdata(h.main,
" s ");
568 if get(h.rbOutput,
" Value ")
573 pfun = @(
t,y)r.plot(
t,y,pm);
574 pfunm = @(
t,y)m.plot(
t,y,pm);
579 pfunm = @r.plotState;
581 if get(h.chkAbsErr,
" Value ")
583 set(gcf,
" Name ",
" Results of reduced simulation ");
584 pfunm(s.t,abs(v-vr));
585 set(gcf,
" Name ",
" Absolute errors ");
588 set(gcf,
" Name ",
" Results of full simulation ");
590 set(gcf,
" Name ",
" Results of reduced simulation ");
601 r = getappdata(h.main,
" r ");
602 s = getappdata(h.main,
" s ");
603 v =
Norm.
L2(s.x-r.V*(r.V^
t*s.x));
606 h = pm.nextPlot(,
" Trajectory subspace projection L2(state) error ",
" time ",
" error ");
615 r = getappdata(h.main,
" r ");
617 s = getappdata(h.main,
" s ");
620 sel = round(linspace(1,size(x,2),min(use,size(x,2))));
622 mui = r.getRandomParam(400,1);
623 res = testing.LogNorm.getApproxLogNormsAtPos(r, x, r.scaledTimes(sel),mui);
626 testing.LogNorm.getApproxLogNormsAtPos_plots(res, pm);
634 if get(hObject,
" Value ")
635 set(h.rbOutput,
" Value ",0);
643 if get(hObject,
" Value ")
644 set(h.rbState,
" Value ",0);
ModelAnalyzer: Analysis tools for reduced models and approximations.
function varargout = DEIMEstimatorAnalyzer(varargin)
DEIMESTIMATORANALYZER MATLAB code for DEIMEstimatorAnalyzer.fig DEIMESTIMATORANALYZER, by itself, creates a new DEIMESTIMATORANALYZER or raises the existing singleton*.
function DEIMEstimatorAnalyzer>slM_Callback(hObject, eventdata, handles)
LogPlot: Class with static functions for logarithmic plotting.
function DEIMEstimatorAnalyzer>reSimulate(h)
function DEIMEstimatorAnalyzer>rbOutput_Callback(hObject, eventdata, h)
function DEIMEstimatorAnalyzer>createModelParamSliders(h, r)
function varargout = DEIMEstimatorAnalyzer>DEIMEstimatorAnalyzer_OutputFcn(hObject, eventdata, handles)
function DEIMEstimatorAnalyzer>slM_CreateFcn(hObject, eventdata, handles)
function DEIMEstimatorAnalyzer>rbState_Callback(hObject, eventdata, h)
function DEIMEstimatorAnalyzer>slMD_Callback(hObject, eventdata, handles)
function DEIMEstimatorAnalyzer>slK_CreateFcn(hObject, eventdata, handles)
function DEIMEstimatorAnalyzer>modelToGUI(h, r)
function DEIMEstimatorAnalyzer>getDEIMErrorsOnTraj(h)
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
function DEIMEstimatorAnalyzer>btnDEIMErr_Callback(hObject, eventdata, handles)
function DEIMEstimatorAnalyzer>slK_Callback(hObject, eventdata, handles)
function DEIMEstimatorAnalyzer>doPlot(h,colvec< double > x,matrix< double > y, varargin)
static function handle p = cleverPlot(handle ax,rowvec< double > x,rowvec< double > y, varargin)
Calls corresponding plot routines depending on the scale of data.
function DEIMEstimatorAnalyzer>updateUserParam(h)
logical LeaveOpen
Flag indicating if the plots should be left open once the PlotManager is deleted (as variable) ...
A variable number of input arguments.
function DEIMEstimatorAnalyzer>DEIMEstimatorAnalyzer_OpeningFcn(hObject, eventdata, handles, varargin)
function DEIMEstimatorAnalyzer>slTrainParam_CreateFcn(hObject, eventdata, handles)
function DEIMEstimatorAnalyzer>slTrainParam_Callback(hObject, unused1, h)
function DEIMEstimatorAnalyzer>btnApproxLogNorm_Callback(hObject, eventdata, h)
function DEIMEstimatorAnalyzer>btnVisResult_Callback(hObject, eventdata, h)
function DEIMEstimatorAnalyzer>rbgBeta_SelectionChanged(h, source, eventdata)
function DEIMEstimatorAnalyzer>slJM_CreateFcn(hObject, eventdata, handles)
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
function DEIMEstimatorAnalyzer>rbgAlpha_SelectionChanged(h, source, unused1)
static function rowvec< double > n = L2(matrix< double > x)
Returns the discrete norm for each column vector in x.
function DEIMEstimatorAnalyzer>rbgParam_SelectionChanged(h, source, unused1)
function DEIMEstimatorAnalyzer>btnRedSummary_Callback(hObject, eventdata, h)
Norm: Static class for commonly used norms on sets of vectors.
function DEIMEstimatorAnalyzer>slJM_Callback(hObject, eventdata, handles)
function DEIMEstimatorAnalyzer>slMD_CreateFcn(hObject, eventdata, handles)
function DEIMEstimatorAnalyzer>rePlot(h)
function DEIMEstimatorAnalyzer>pushbutton5_Callback(hObject, eventdata, h)
A variable number of output arguments.