26 gui_State =
struct(
" gui_Name ", mfilename, ...
27 " gui_Singleton ", gui_Singleton, ...
28 " gui_OpeningFcn ", @ApproxVisualizer_OpeningFcn, ...
29 " gui_OutputFcn ", @ApproxVisualizer_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);
90 disp(
" Pass a reduced model to ApproxVisualizer. ");
93 if ~isa(varargin[1],
" models.ReducedModel ")
94 error(
" ApproxVisualizer takes only models.ReducedModel subclasses as input. ");
101 error(
" The Approx field of the reduced models full model must not be empty. ");
103 setappdata(handles.main,
" r ",r);
104 setappdata(handles.main,
" atd ",m.Data.ApproxTrainData);
107 modelToGUI(r, handles);
110 if isempty(r.ParamSamples)
111 setappdata(handles.main,
" pidx ",[]);
113 setappdata(handles.main,
" pidx ",1);
115 if m.System.InputCount == 0
116 setappdata(handles.main,
" inidx ",[]);
118 setappdata(handles.main,
" inidx ",m.TrainingInputs(1));
120 setappdata(handles.main,
" fidx ",1);
121 setappdata(handles.main,
" mu ",[]);
124 plotCurrent(handles);
132 pc = size(r.ParamSamples,2);
133 if m.System.ParamCount == 0 || pc <= 1
134 set(h.pslide,
" Enable ",
" off ");
136 set(h.pslide,
" Max ",pc,
" Min ",1,
" Value ",1);
137 set(h.pslide,
" SliderStep ",[1/(pc-1) 10/(pc-1)]);
139 if m.System.InputCount <= 1
140 set(h.islideF,
" Enable ",
" off ");
142 set(h.islideF,
" Max ",m.System.InputCount,
" Min ",1,
" Value ",1);
143 set(h.islideF,
" SliderStep ",[1/m.System.InputCount 10/m.System.InputCount]);
145 if m.TrainingInputCount <= 1
146 set(h.islideS,
" Enable ",
" off ");
148 set(h.islideS,
" Max ",m.TrainingInputCount,
" Min ",1,
" Value ",1);
149 set(h.islideS,
" SliderStep ",[1/m.TrainingInputCount 10/m.TrainingInputCount]);
151 fdims = size(m.Data.ApproxTrainData.fxi,1);
152 set(h.fslide,
" Max ",fdims,
" Value ",1);
153 set(h.fslide,
" SliderStep ",[1/(fdims-1) 10/(fdims-1)]);
154 set(h.txtModel,
" String ",r.Name);
156 set(h.pnlParams,
" Units ",
" pixels ");
157 pos =
get(h.pnlParams,
" Position ");
158 set(h.pnlParams,
" Units ",
" normalized ");
163 for pidx = 1:m.System.ParamCount
164 p = m.System.Params(pidx);
167 top = pos(4)-pcnt*dist-40;
169 label = uicontrol(
" Tag ",[
" runtime_lbl " num2str(pidx)],
" Style ",
" text ",...
170 " Parent ",h.pnlParams,
" HorizontalAlignment ",
" left ");
171 set(label,
" String ",p.Name,
" Units ",
" pixels ",
" Position ",[10 top 50 14]);
172 set(label,
" Units ",
" normalized ");
173 label = uicontrol(
" Tag ",[
" runtime_lbll " num2str(pidx)],
" Style ",
" text ",...
174 " Parent ",h.pnlParams,
" HorizontalAlignment ",
" right ");
175 set(label,
" String ",sprintf(
" %2.3f ",p.MinVal),
" Units ",
" pixels ",...
176 " Position ",[80 top 30 14]);
177 set(label,
" Units ",
" normalized ");
178 label = uicontrol(
" Tag ",[
" runtime_lblr " num2str(pidx)],
" Style ",
" text ",...
179 " Parent ",h.pnlParams,
" HorizontalAlignment ",
" left ");
180 set(label,
" String ",sprintf(
" %2.3f ",p.MaxVal),
" Units ",
" pixels ",...
181 " Position ",[260 top 30 14]);
182 set(label,
" Units ",
" normalized ");
184 tag = [
" runtime_pslide " num2str(pidx)];
185 ctrl = uicontrol(
" Tag ",tag,
" Parent ",...
186 h.pnlParams,
" Style ",
" slider ",
" UserData ",pidx);
189 set(ctrl,
" Units ",
" pixels ",
" Position ",[120 top 130 16]);
190 set(ctrl,
" Units ",
" normalized ");
192 set(ctrl,
" Min ",p.MinVal,
" Max ",p.MaxVal,
" Value ",p.MinVal);
193 set(ctrl,
" SliderStep ",[0.01 0.1]);
195 set(ctrl,
" Callback ",@(hO,e)(updateUserParam(guidata(hO))));
200 warning(
" KerMor:visual ",
" FullData visualization will not work, not yet adopted to the new ATrajectoryData structure. ");
206 r = getappdata(h.main,
" r ");
207 pc = r.FullModel.System.ParamCount;
210 slides = findobj(h.pnlParams,
" Style ",
" slider ");
212 if r.FullModel.System.Params(n).HasRange
213 mu(n) =
get(slides(pc-n+1),
" Value ");
215 mu(n) = r.FullModel.System.Params(n).MinVal;
218 setappdata(h.main,
" mu ",mu);
227 r = getappdata(h.main,
" r ");
228 inidx = getappdata(h.main,
" inidx ");
230 if get(h.rbS,
" Value ") == 1
231 d = r.FullModel.Data;
233 if get(h.chkFullData,
" Value ") == 1
235 if ~isempty(r.V) && ~isempty(r.W)
236 sn(4:end,:) = r.V*(r.W^
t*sn(4:end,:));
239 sn = d.ApproxTrainData;
242 pidx = getappdata(h.main,
" pidx ");
245 psel = sn(1,:) == pidx;
247 psel =
true(1,size(sn,2));
250 isel = sn(2,:) == inidx;
252 isel =
true(1,size(sn,2));
256 if get(h.chkFullData,
" Value ") == 1
257 fx = getappdata(h.main,
" fxall ");
259 fx = d.ApproxfValues;
266 mui = d.getParams(sn(1,:));
269 a = r.FullModel.Approx;
270 if isa(a,
" dscomponents.AKernelCoreFun ")
272 elseif isa(a,
" approx.TPWLApprox ")
278 if ~isempty(centers) && centers(1) == 0
281 setappdata(h.main,
" centers ",centers);
284 mu = getappdata(h.main,
" mu ");
286 [ti,xi] = fm.computeTrajectory(mu,inidx);
290 mui = repmat(mu,1,n);
292 fx = fm.System.f.evaluate(xi,ti,mui);
295 afx = r.FullModel.Approx.evaluate(xi,ti,mui);
296 setappdata(h.main,
" fx ",fx);
297 setappdata(h.main,
" afx ",afx);
298 setappdata(h.main,
" ti ",ti);
299 setappdata(h.main,
" xi ",xi);
300 setappdata(h.main,
" mui ",mui);
307 fidx = getappdata(h.main,
" fidx ");
308 fx = getappdata(h.main,
" fx ");
309 afx = getappdata(h.main,
" afx ");
310 ti = getappdata(h.main,
" ti ");
314 err = sqrt(sum((fxi-afxi).^2));
315 errinf = max(abs(fxi-afxi));
317 plot(ti,fxi,
" r ",ti,afxi,
" b ");
318 legend(
" Orig. Fcn ",
" Approx ");
321 if get(h.rbS,
" Value ") == 1
324 if get(h.chkCenters,
" Value ")
325 centers = getappdata(h.main,
" centers ");
328 plot(ti(idx(centers)),afxi(idx(centers)),
" o ",
" MarkerEdgeColor ",
" black ",...
329 " MarkerFaceColor ",
" r ",
" MarkerSize ",4);
335 title(sprintf(
" f,f "" at dimension %d. Linf-Err:%5.3e, L2-Err:%5.3e ",fidx,errinf,err));
339 currentToGUI(getappdata(h.main,
" r "),h);
344 pidx = getappdata(h.main,
" pidx ");
346 if get(h.rbS,
" Value ") == 1
347 set(h.txtPSampled,
" String ",[
" Param: [ " sprintf(
" %2.3f ",r.ParamSamples(:,pidx))
" ] "]);
349 set(h.txtPFull,
" String ",[
" Param: [ " sprintf(
" %2.3f ",getappdata(h.main,
" mu "))
" ] "]);
352 inidx = getappdata(h.main,
" inidx ");
354 r = getappdata(h.main,
" r ");
355 if get(h.rbS,
" Value ") == 1
357 if inidx > r.FullModel.TrainingInputCount
358 inidx = r.FullModel.TrainingInputs(end);
359 setappdata(h.main,
" inidx ",inidx);
360 set(h.txtISampled,
" Value ",inidx);
362 set(h.txtISampled,
" String ",sprintf(
" Input: %d/%d ",inidx,max(r.FullModel.TrainingInputs)));
364 set(h.txtIFull,
" String ",sprintf(
" Input: %d/%d ",inidx,r.System.InputCount));
367 set(h.txtf,
" String ",sprintf(
" %d ",getappdata(h.main,
" fidx ")));
385 setappdata(handles.main,
" pidx ",round(
get(hObject,
" Value ")));
386 plotCurrent(handles);
394 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
395 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
406 idx = round(
get(hObject,
" Value "));
407 r = getappdata(handles.main,
" r ");
408 idx = r.FullModel.TrainingInputs(idx);
409 setappdata(handles.main,
" inidx ",idx);
410 plotCurrent(handles);
418 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
419 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
430 setappdata(handles.main,
" fidx ",round(
get(hObject,
" Value ")));
431 plotCurrentFxi(handles);
439 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
440 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
447 set(h.rbU,
" Value ",0);
448 set(h.pnlParams,
" Visible ",
" off ");
449 r = getappdata(h.main,
" r ");
450 if size(r.ParamSamples,2) > 1
451 set(h.pslide,
" Enable ",
" on ");
453 if r.FullModel.TrainingInputCount > 1
454 set(h.islideS,
" Enable ",
" on ");
456 set(h.chkGlobal,
" Visible ",
" on ");
457 set([h.islideF h.txtIFull h.txtPFull],
" Enable ",
" off ");
458 set([h.txtISampled h.txtPSampled h.chkCenters h.chkFullData],
" Enable ",
" on ");
464 set(h.rbS,
" Value ",0);
465 set(h.pnlParams,
" Visible ",
" on ");
466 set(h.chkGlobal,
" Visible ",
" off ",
" Value ",0);
467 set([h.txtIFull h.txtPFull],
" Enable ",
" on ");
468 set([h.pslide h.txtISampled h.txtPSampled h.islideS h.chkCenters h.chkFullData],
" Enable ",
" off ");
469 r = getappdata(h.main,
" r ");
470 if r.System.InputCount > 1
471 set(h.islideF,
" Enable ",
" on ");
479 if get(hObject,
" Value ") == 1 && isempty(getappdata(handles.main,
" fxall "))
480 r = getappdata(handles.main,
" r ");
481 d = r.FullModel.Data;
483 atdidx = r.FullModel.Approx.TrainDataSelector.LastUsed;
485 fxall = zeros(size(sn)-[3 0]);
486 fxall(:,atdidx) = d.ApproxfValues;
487 [tocomp, pos] = setdiff(1:size(sn,2),atdidx);
489 fxall(:,pos) = r.FullModel.System.f.evaluate(sn(4:end,tocomp),sn(3,tocomp),...
490 d.getParams(sn(1,tocomp)));
492 setappdata(handles.main,
" fxall ",fxall);
499 plotCurrentFxi(handles)
505 if get(h.rbS,
" Value ") == 1
506 if get(h.chkFullData,
" Value ") == 1
507 showErrors(h,
" Full training data ");
509 showErrors(h,
" Approx training data ");
512 showErrors(h,
" Current trajectory ");
518 r = getappdata(h.main,
" r ");
521 if get(h.rbS,
" Value ") == 1 &&
get(h.chkGlobal,
" Value ") == 1
522 name = [name
" [global] "];
524 if get(h.chkFullData,
" Value ")
525 f = getappdata(h.main,
" fxall ");
529 sn = d.ApproxTrainData;
533 mui = d.getParams(sn(1,:));
535 ti = getappdata(h.main,
" ti ");
536 xi = getappdata(h.main,
" xi ");
537 mui = getappdata(h.main,
" mui ");
538 f = getappdata(h.main,
" fx ");
541 fa = m.Approx.evaluate(xi,ti,mui);
542 if ~isempty(m.SpaceReducer)
543 fap = r.V*r.System.f.evaluate(r.W^
t*xi,ti,mui);
545 fap = r.System.f.evaluate(xi,ti,mui);
548 if get(h.rbLinf,
" Value ")
549 errfun = @getLInftyErr;
551 elseif
get(h.rbL2,
" Value ")
556 [v,i,e] = errfun(f,fa);
558 title(sprintf(
" %s\nFull vs full approx %s-errors\nMax: %5.3e, mean: %5.3e ",name,fun,v,mean(e)));
560 [v,i,e] = errfun(f,fap);
562 title(sprintf(
" %s\nFull vs projected approx %s-errors\nMax: %5.3e, mean: %5.3e ",name,fun,v,mean(e)));
564 [v,i,e] = errfun(fa,fap);
566 title(sprintf(
" %s\nFull approx vs projected approx %s-errors\nMax: %5.3e, mean: %5.3e ",name,fun,v,mean(e)));
579 errs = max(abs(a-b),[],1);
580 [val, idx] = max(errs);
585 errs = sqrt(sum((a-b).^2));
586 [val, idx] = max(errs);
603 setappdata(handles.main,
" inidx ",round(
get(hObject,
" Value ")));
604 plotCurrent(handles);
612 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
613 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
Collection of generally useful functions.
function ApproxVisualizer>islideF_Callback(hObject, eventdata, handles)
function ApproxVisualizer>currentToGUI(r, h)
function ApproxVisualizer>rbU_Callback(hObject, eventdata, h)
static function idx = findVecInMatrix(A, b)
Finds column vectors inside a matrix.
function ApproxVisualizer>fslide_Callback(hObject, eventdata, handles)
function [ val , idx , errs ] = ApproxVisualizer>getL2Err(a, b)
function ApproxVisualizer>chkCenters_Callback(hObject, eventdata, handles)
function ApproxVisualizer>ApproxVisualizer_OpeningFcn(hObject, eventdata, handles, varargin)
function ApproxVisualizer>chkFullData_Callback(hObject, eventdata, handles)
function ApproxVisualizer>plotCurrent(h)
function ApproxVisualizer>plotCurrentFxi(h)
function ApproxVisualizer>islideS_CreateFcn(hObject, eventdata, handles)
function ApproxVisualizer>showErrors(h, name)
function ApproxVisualizer>modelToGUI(r, h)
function varargout = ApproxVisualizer>ApproxVisualizer_OutputFcn(hObject, eventdata, handles)
function ApproxVisualizer>islideF_CreateFcn(hObject, eventdata, handles)
A variable number of input arguments.
function ApproxVisualizer>pslide_CreateFcn(hObject, eventdata, handles)
function ApproxVisualizer>pslide_Callback(hObject, eventdata, handles)
function ApproxVisualizer>updateUserParam(h)
function ApproxVisualizer>islideS_Callback(hObject, eventdata, handles)
function ApproxVisualizer>plotit(e, nr)
function ApproxVisualizer>btnSave_Callback(hObject, eventdata, handles)
function ApproxVisualizer>fslide_CreateFcn(hObject, eventdata, handles)
function ApproxVisualizer>rbS_Callback(hObject, eventdata, h)
function varargout = ApproxVisualizer(varargin)
APPROXVISUALIZER M-file for ApproxVisualizer.fig APPROXVISUALIZER, by itself, creates a new APPROXVIS...
static function saveAxes(handle ax, varargin)
Convenience function. Allows to save a custom axes instead of a whole figure which allows to drop any...
function ApproxVisualizer>btnShowErr_Callback(hObject, eventdata, handles)
A variable number of output arguments.
function [ val , idx , errs ] = ApproxVisualizer>getLInftyErr(a, b)