46 gui_State =
struct(
" gui_Name ", mfilename, ...
47 " gui_Singleton ", gui_Singleton, ...
48 " gui_OpeningFcn ", @FunVis2D_OpeningFcn, ...
49 " gui_OutputFcn ", @FunVis2D_OutputFcn, ...
50 " gui_LayoutFcn ", [] , ...
51 " gui_Callback ", []);
52 if nargin && ischar(varargin[1])
53 gui_State.gui_Callback= str2func(varargin[1]);
57 [
varargout[1:nargout]] = gui_mainfcn(gui_State, varargin[:]);
59 gui_mainfcn(gui_State, varargin[:]);
184 handles.output= hObject;
187 guidata(hObject, handles);
194 ranges =
struct(
" xrange ",[],
" trange ",[],
" murange ",[]);
198 if isa(varargin[1],
" models.BaseFullModel ")
201 [x,
X] = m.Data.getBoundingBox;
202 ranges.xrange= [x
X];
203 ranges.trange= [0 m.T];
204 if m.System.ParamCount > 0
205 if isempty(m.Data.ParamSamples)
206 stop(h,
" No param samples available yet. Have you run model.off1_generateParamSamples? ");
209 ranges.murange= [mu MU];
211 elseif isa(varargin[1],
" models.ReducedModel ")
214 conf.td= r.FullModel.Data.ApproxTrainData;
215 ranges = rangesFromATD(conf.td);
216 conf.fun2= r.FullModel.System.f;
220 if isa(fun,
" function_handle ")
226 fun = dscomponents.PointerCoreFun(fun);
227 elseif ~ismethod(fun,
" evaluate ")
228 stop(h,
" If the first argument is not a function pointer it must be a class with an 'evaluate' method. ");
234 if isfield(sec,
" xrange ")
236 ranges.xrange= sec.xrange;
237 if isfield(sec,
" trange ")
238 ranges.trange= sec.trange;
240 if isfield(sec,
" murange ")
241 ranges.murange= sec.murange;
243 if length(varargin) > 2 && isa(varargin[3],
" data.ATrajectoryData ")
244 conf.td= varargin[3].ApproxTrainData;
246 elseif isa(sec,
" data.ApproxTrainData ")
248 ranges = rangesFromATD(sec);
250 elseif isa(sec,
" double ")
253 stop(h,
" The second argument has to be a ranges struct or a struct with the fields xrange (+trange,murange if given). ");
261 conf.hasparams=
false;
263 if ~isempty(ranges.trange)
265 conf.timeoff= size(ranges.xrange,1)+1;
266 box = [box; ranges.trange];
268 if ~isempty(ranges.murange)
269 conf.hasparams=
true;
270 conf.paroff= size(ranges.xrange,1)+1;
272 conf.paroff= conf.paroff+1;
274 box = [box; ranges.murange];
277 conf.xdim= size(ranges.xrange,1);
278 conf.dims= size(box,1);
280 conf.const= find(max(box,[],2) == min(box,[],2));
285 if length(varargin) > 3
287 if isa(fun2,
" function_handle ")
288 fun2 = dscomponents.PointerCoreFun(fun2,conf.xdim,
true);
289 elseif ~isempty(fun2) && ~ismethod(fun2,
" evaluate ")
290 stop(h,
" Any second function-class must have an "" evaluate "" -method ");
292 if length(varargin) > 4
294 if ~isfield(lbl,
" x ") || ~isfield(lbl,
" fx ")
295 stop(h,
" Custom labels must have the struct fields x and fx ");
308 for i=setdiff(1:conf.xdim,conf.const)
309 lbl.x[end+1] = [
" x_{ " num2str(i)
" } "];
311 args[1] = zeros(conf.xdim,1);
312 if conf.hastime &&
all(conf.const ~= conf.timeoff)
313 lbl.x[end+1] =
" t ";
316 args[2] =
double.empty(0,1);
319 munum = 1:size(conf.ranges.murange,1);
320 [diff, idx] = setdiff(conf.paroff+munum-1,conf.const);
322 lbl.x[end+1] = [
" mu_{ " num2str(munum(idx(i)))
" } "];
324 args[3] = zeros(munum,1);
326 args[3] =
double.empty(0,1);
330 fdim = size(conf.td.fxi,1);
333 fdim = size(conf.fun.evaluate(args[:]),1);
336 lbl.fx[end+1] = [
" f(x_{ " num2str(i)
" }) "];
344 if isa(fun,
" kernels.KernelExpansion ")
346 set(h.lblCenters,
" Visible ",
" on ");
347 set(h.lblNumCenters,
" Visible ",
" on ");
348 set(h.slCenters,
" Visible ",
" on ");
350 set(h.slCenters,
" Value ",conf.cperc);
352 if isa(fun,
" kernels.ParamTimeKernelExpansion ")
357 if ~isempty(conf.fun2)
358 set(handles.lbl2nd,
" Visible ",
" on ");
359 set(handles.rbAdd,
" Visible ",
" on ");
360 set(handles.rbErr,
" Visible ",
" on ");
364 [~, conf.idxmap] = setdiff(1:conf.dims,conf.const);
366 conf.d1= 1; conf.d2= 2;
371 conf.basex= (box(:,1)+box(:,2))/2;
377 set(h.slPerc,
" Value ",conf.tperc);
380 set(h.slPerc,
" Visible ",
" off ");
381 set(h.lblTP,
" Visible ",
" off ");
382 set(h.lblPerc,
" Visible ",
" off ");
385 setappdata(h.main,
" conf ",conf)
387 rotate3d(h.ax,
" on ");
391 set(h.dim1,
" String ",lbl.x,
" Value ",conf.d1);
392 set(h.dim2,
" String ",lbl.x,
" Value ",conf.d2);
393 set(h.dout,
" String ",lbl.fx,
" Value ",conf.dout);
394 set(h.slRefine,
" Value ",conf.gridpts);
398 updateATDPoints(h,conf);
399 conf = updateCenterPoints(h, conf);
405 ranges =
struct(
" xrange ",[],
" trange ",[],
" murange ",[]);
407 ranges.xrange= [x
X];
408 if isprop(atd,
" ti ") || isfield(atd,
" ti ")
409 ranges.trange= [min(atd.
ti) max(atd.
ti)];
411 if isprop(atd,
" mui ") || isfield(atd,
" mui ")
413 ranges.murange= [mu MU];
420 error(errmsg,varargin[:]);
425 xsel = c.idxmap([c.d1 c.d2]);
426 x1 = linspace(c.box(xsel(1),1), c.box(xsel(1),2), c.gridpts);
427 x2 = linspace(c.box(xsel(2),1), c.box(xsel(2),2), c.gridpts);
429 [X1,X2] = meshgrid(x1,x2);
430 setappdata(h.main,
" X1 ",X1);
431 setappdata(h.main,
" X2 ",X2);
438 X1 = getappdata(h.main,
" X1 ");
439 X2 = getappdata(h.main,
" X2 ");
440 x = [X1(:)
" ; X2(:) "];
441 xf = repmat(c.basex,1,size(x,2));
442 xsel = c.idxmap([c.d1 c.d2]);
447 if c.hastime && c.hasparams
448 fx = c.fun.evaluate(xf(1:c.timeoff-1,:),...
452 fx2 = c.fun2.evaluate(xf(1:c.timeoff-1,:),...
457 fx = c.fun.evaluate(xf(1:c.timeoff-1,:),...
460 fx2 = c.fun2.evaluate(xf(1:c.timeoff-1,:),...
464 fx = c.fun.evaluate(xf(1:c.paroff-1,:),[],...
467 fx2 = c.fun2.evaluate(xf(1:c.paroff-1,:),[],...
471 fx = c.fun.evaluate(xf,[],[]);
473 fx2 = c.fun2.evaluate(xf,[],[]);
479 c.err.l2= sqrt(n*sum((fx-fx2).^2,2));
480 c.err.rel_l2_1= c.err.l2 ./ sqrt(n*sum(fx.^2,2));
481 c.err.rel_l2_2= c.err.l2 ./ sqrt(n*sum(fx2.^2,2));
482 c.err.linf= max(abs(fx-fx2),[],2);
483 setappdata(h.main,
" conf ",c);
485 setappdata(h.main,
" fx ",fx);
486 setappdata(h.main,
" fx2 ",fx2);
494 cent = c.fun.Centers;
497 C = [C; cent.ti; cent.mui];
500 d = C - repmat(c.basex,1,size(C,2));
501 xsel = c.idxmap([c.d1 c.d2]);
503 d = sqrt(sum(d.^2,1));
504 md = min(d); Md = max(d);
505 if md == Md && c.cperc > 0
508 sel = d < md + (Md-md)*(c.cperc/100)*1.001;
510 set(h.lblNumCenters,
" String ",sprintf(
" %d/%d ",sum(sel),size(C,2)));
513 c.curCenterSelInATD= [];
516 if any(c.curCenterSelInATD == 0)
517 c.curCenterSelInATD= [];
520 xf = repmat(c.basex,1,size(C,2));
521 xsel = c.idxmap([c.d1 c.d2]);
522 xf(xsel,:) = C(xsel,:);
524 c.curCenterFx= c.fun.evaluate(xf(1:c.timeoff-1,:),...
528 c.curCenterFx= c.fun.evaluate(xf,[],[]);
531 if ~isempty(c.fun2) &&
get(h.rbErr,
" Value ") == 1
532 if c.hastime || c.hasparams
533 error(
" Error plots with centers for param/time kernel expansions not yet implemented ");
535 c.curCenterFx= c.curCenterFx - c.fun2.evaluate(xf,[],[]);
537 setappdata(h.main,
" conf ",c);
544 xsel = c.idxmap([c.d1 c.d2]);
545 C = c.td.xi.toMemoryMatrix;
546 if c.isptke || isa(c.fun,
" dscomponents.ACoreFun ")
547 C = [C; c.td.ti; c.td.mui];
550 d = C - repmat(c.basex,1,size(C,2));
552 d = sqrt(sum(d.^2,1));
553 md = min(d); Md = max(d);
554 if md == Md && c.tperc > 0
557 sel = d < md + (Md-md)*(c.tperc/100)*1.001;
559 set(h.lblPerc,
" String ",sprintf(
" %d/%d ",sum(sel),size(C,2)));
560 setappdata(h.main,
" selATDPoints ",sel);
569 fx = getappdata(h.main,
" fx ");
570 X1 = getappdata(h.main,
" X1 ");
571 X2 = getappdata(h.main,
" X2 ");
572 cap = sprintf(
" Plot of %s against %s and %s ",c.lbl.fx[c.dout],c.lbl.x[c.d1],c.lbl.x[c.d2]);
578 if get(h.chkPlotFun,
" Value ") == 1
580 fx = reshape(fx(c.dout,:),size(X1,1),[]);
584 fx2 = getappdata(h.main,
" fx2 ");
585 if ~isempty(fx2) &&
get(h.rbErr,
" Value ") == 1
586 fx2 = reshape(fx2(c.dout,:),size(X1,1),[]);
588 cap = sprintf(
" Error f_1-f_2 at output %s against %s and %s ",c.lbl.fx[c.dout],c.lbl.x[c.d1],c.lbl.x[c.d2]);
591 txt = sprintf(
" L2:%.2e, Linf:%.2e\nrL21:%.2e, rL22:%.2e ",c.err.l2(c.dout),c.err.linf(c.dout),...
592 c.err.rel_l2_1(c.dout),c.err.rel_l2_2(c.dout));
594 fprintf(
" Warning, current output %s contains NaNs. Not plotting error.\n ",c.lbl.fx[c.dout]);
597 set(h.lblErr,
" String ",txt);
601 if mi == 0 && Ma == 0
603 elseif mi ~= 0 && abs((mi-Ma) / mi) < 1e-14
605 mi = (1-.001*s)*mi; Ma=(1+.001*s)*Ma;
609 s1 = surf(h.ax,X1,X2,fx,
" FaceColor ",
" interp ");
611 if ~isempty(fx2) &&
get(h.rbAdd,
" Value ") == 1
612 fx2 = reshape(fx2(c.dout,:),size(X1,1),[]);
614 mi = min(mi,min(fx2(:)));
615 Ma = max(Ma,max(fx2(:)));
616 cap = sprintf(
" Plot of %s against %s and %s, both functions ",c.lbl.fx[c.dout],c.lbl.x[c.d1],c.lbl.x[c.d2]);
617 s2 = surf(h.ax,X1,X2,fx2);
622 if get(h.rbErr,
" Value ") == 1
623 s3 = surf(h.ax,X1,X2,zeros(size(X1)));
628 if get(h.chkGrid,
" Value ") == 1
631 set(s1,
" EdgeColor ",mode);
634 xsel = c.idxmap([c.d1 c.d2]);
637 if ~isempty(c.td) &&
get(h.rbErr,
" Value ") == 0
638 C = c.td.xi.toMemoryMatrix;
640 C = [C; c.td.ti; c.td.mui];
643 sel = getappdata(h.main,
" selATDPoints ");
644 hlpfx = c.td.fxi(c.dout,sel);
651 plot3(h.ax,C(1,sel),C(2,sel),hlpfx,
" red. ",
" MarkerSize ",12);
658 if get(h.rbErr,
" Value ") == 0 && ~isempty(c.curCenterSelInATD)
660 orig = c.td.fxi(c.dout,c.curCenterSelInATD);
661 plot3(h.ax,C(xsel(1),:),C(xsel(2),:),orig,
" black. ",
" MarkerSize ",13);
663 if get(h.chkPlotCenterLines,
" Value ") == 1
664 plot3(h.ax,[C(xsel(1),:); C(xsel(1),:)],[C(xsel(2),:); C(xsel(2),:)],[c.curCenterFx(c.dout,:); orig],
" black ");
665 plot3(h.ax,C(xsel(1),:),C(xsel(2),:),c.curCenterFx(c.dout,:),
" blackx ",
" MarkerSize ",5);
668 plot3(h.ax,C(xsel(1),:),C(xsel(2),:),c.curCenterFx(c.dout,:),
" black. ",
" MarkerSize ",13);
672 axis(h.ax,[X1(1,1) X1(1,end) X2(1,1) X2(end,1) mi Ma]);
673 xlabel(h.ax,c.lbl.x[c.d1]);
674 ylabel(h.ax,c.lbl.x[c.d2]);
675 zlabel(h.ax,c.lbl.fx[c.dout]);
683 val = 1-
get(h.panelslide,
" Value ");
684 c = getappdata(h.main,
" conf ");
686 ctrls = getappdata(h.main,
" ctrls ");
688 delete(ctrls.labels);
689 delete(ctrls.slides);
693 set(h.pnlBS,
" Units ",
" pixels ");
694 pos =
get(h.pnlBS,
" Position ");
698 dims([c.d1 c.d2]) = [];
705 dispsliders = min(length(dims), floor(pnlh / eh)-1);
706 totalheight = (length(dims)-dispsliders) * eh;
707 if totalheight > pnlh
708 curoffset = totalheight * val;
709 firstidx = floor(curoffset / eh);
711 set(h.panelslide,
" Visible ",
" off ");
717 for idx = 1:dispsliders
718 dim = dims(firstidx+idx);
719 top = pnlh-15-idx*eh;
724 tooltip = sprintf(
" Range [%1.5e - %1.5e] ",m,M);
726 label = uicontrol(
" Tag ",[
" runtime_lbl_ " name],
" Style ",
" text ",...
727 " Parent ",h.pnlBS,
" HorizontalAlignment ",
" left ");
728 set(label,
" String ",[name
" : "],
" Units ",
" pixels ",
" Position ",[10 top 40 14],...
729 " TooltipString ",tooltip);
730 ctrls.labels(end+1) = label;
733 label = uicontrol(
" Tag ",sprintf(
" runtime_lbl_val_%d ",idx),
" Style ",
" text ",...
734 " Parent ",h.pnlBS,
" HorizontalAlignment ",
" left ",...
735 " TooltipString ",[
" Value of " name
" for current plot "]);
736 set(label,
" String ",sprintf(
" %2.4e ",c.basex(dim)),
" Units ",
" pixels ",
" Position ",[60 top 90 14],...
737 " TooltipString ",tooltip);
738 ctrls.labels(end+1) = label;
749 ctrl = uicontrol(
" Tag ",sprintf(
" runtime_slide_%d ",idx),
" Parent ",...
750 h.pnlBS,
" HorizontalAlignment ",
" left ");
751 set(ctrl,
" Style ",
" slider ",
" Value ", c.basex(dim),...
752 " Min ", m,
" Max ", M);
753 set(ctrl,
" Units ",
" pixels ",
" Position ",[160 top 250 16],
" UserData ",dim,...
754 " TooltipString ",tooltip);
755 set(ctrl,
" Callback ",@(h,e)(baseSliderChanged(h,guidata(h),valuelabel)));
756 ctrls.slides(end+1) = ctrl;
765 setappdata(h.main,
" ctrls ", ctrls);
770 dim =
get(hObj,
" UserData ");
771 conf = getappdata(h.main,
" conf ");
772 conf.basex(dim) =
get(hObj,
" Value ");
773 set(label,
" String ",sprintf(
" %2.4e ",conf.basex(dim)));
774 setappdata(h.main,
" conf ",conf);
776 updateATDPoints(h,conf);
777 conf = updateCenterPoints(h,conf);
790 conf = getappdata(handles.main,
" conf ");
791 if get(hObject,
" Value ") ~= conf.d2
793 conf.d1=
get(hObject,
" Value ");
794 setappdata(handles.main,
" conf ",conf);
796 setDimSliders(handles);
797 newMesh(handles, conf);
803 if ispc && isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
804 set(hObject,
" BackgroundColor ",
" white ");
810 conf = getappdata(handles.main,
" conf ");
811 if get(hObject,
" Value ") ~= conf.d1
813 conf.d2=
get(hObject,
" Value ");
814 setappdata(handles.main,
" conf ",conf);
816 setDimSliders(handles);
817 newMesh(handles, conf);
826 if ispc && isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
827 set(hObject,
" BackgroundColor ",
" white ");
838 c = getappdata(handles.main,
" conf ");
839 c.gridpts= round(
get(hObject,
" Value "));
840 set(handles.lblRef,
" String ",num2str(c.gridpts));
841 setappdata(handles.main,
" conf ",c);
850 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
851 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
862 conf = getappdata(handles.main,
" conf ");
863 conf.dout=
get(hObject,
" Value ");
864 setappdata(handles.main,
" conf ",conf);
865 plotCurrent(handles, conf);
874 if ispc && isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
875 set(hObject,
" BackgroundColor ",
" white ");
883 conf = getappdata(handles.main,
" conf ");
884 conf.tperc=
get(hObject,
" Value ");
885 set(handles.lblTP,
" String ",sprintf(
" Select %2.2f%% nearest training points ",conf.tperc));
887 setappdata(handles.main,
" conf ",conf);
888 updateATDPoints(handles, conf);
889 plotCurrent(handles,conf);
897 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
898 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
914 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
915 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
929 c = getappdata(handles.main,
" conf ");
930 c.cperc=
get(hObject,
" Value ");
931 set(handles.lblCenters,
" String ",sprintf(
" Include %2.2f%% nearest centers ",c.cperc));
932 setappdata(handles.main,
" conf ",c);
933 c = updateCenterPoints(handles, c);
934 plotCurrent(handles,c);
941 if isequal(
get(hObject,
" BackgroundColor "),
get(0,
" defaultUicontrolBackgroundColor "))
942 set(hObject,
" BackgroundColor ",[.9 .9 .9]);
948 set(handles.rbErr,
" Value ",0);
949 c = updateCenterPoints(handles, getappdata(handles.main,
" conf "));
950 plotCurrent(handles,c);
955 set(handles.rbAdd,
" Value ",0);
956 c = updateCenterPoints(handles, getappdata(handles.main,
" conf "));
957 plotCurrent(handles,c);
965 plotCurrent(handles,getappdata(handles.main,
" conf "));
971 plotCurrent(handles,getappdata(handles.main,
" conf "));
978 plotCurrent(handles,getappdata(handles.main,
" conf "));
Collection of generally useful functions.
function FunVis2D>slPerc_Callback(hObject, unused1, handles)
data.FileMatrix xi
The state space samples , stored row-wise in a data.FileMatrix instance.
function FunVis2D>slRefine_Callback(hObject, eventdata, handles)
function ranges = FunVis2D>rangesFromATD(data.ApproxTrainData atd)
function FunVis2D>newMesh(h, c)
function FunVis2D>dout_Callback(hObject, eventdata, handles)
static function idx = findVecInMatrix(A, b)
Finds column vectors inside a matrix.
function FunVis2D>FunVis2D_OpeningFcn(hObject, eventdata, handles, varargin)
function FunVis2D>setDimSliders(h)
function FunVis2D>chkGrid_Callback(hObject, eventdata, handles)
function FunVis2D>slCenters_CreateFcn(hObject, eventdata, handles)
function FunVis2D>rbAdd_Callback(hObject, eventdata, handles)
function FunVis2D>slPerc_CreateFcn(hObject, eventdata, handles)
function varargout = FunVis2D(varargin)
User interface to visualize highdimensional functions using two input dimensions and one output dimen...
function FunVis2D>dout_CreateFcn(hObject, eventdata, handles)
function varargout = FunVis2D>FunVis2D_OutputFcn(hObject, eventdata, handles)
rowvec ti
The time samples .
function FunVis2D>slCenters_Callback(hObject, unused1, handles)
A variable number of input arguments.
function FunVis2D>rbErr_Callback(hObject, eventdata, handles)
function FunVis2D>dim1_Callback(hObject, eventdata, handles)
function FunVis2D>stop(h, errmsg, varargin)
function FunVis2D>panelslide_CreateFcn(hObject, eventdata, handles)
function FunVis2D>panelslide_Callback(hObject, eventdata, h)
function FunVis2D>slRefine_CreateFcn(hObject, eventdata, handles)
function c = FunVis2D>updateCenterPoints(h, c)
matrix mui
The parameter samples used computing the parent trajectories of .
function FunVis2D>uipushtool2_ClickedCallback(hObject, eventdata, handles)
function FunVis2D>chkPlotCenterLines_Callback(hObject, unused1, handles)
function FunVis2D>baseSliderChanged(hObj, h, label)
ApproxTrainData: Data class for approximation training data, containing several useful bounding box p...
function A = toMemoryMatrix()
Converts this FileMatrix to a full double matrix.
function FunVis2D>chkPlotFun_Callback(hObject, eventdata, handles)
function FunVis2D>updateFX(h, c)
function FunVis2D>dim1_CreateFcn(hObject, eventdata, handles)
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 FunVis2D>dim2_CreateFcn(hObject, eventdata, handles)
static function [ double bmin , double bmax ] = getBoundingBox(double vectors)
Gets the bounding box for a matrix containing column vectors.
A variable number of output arguments.
function FunVis2D>updateATDPoints(h, c)
function FunVis2D>dim2_Callback(hObject, eventdata, handles)
function FunVis2D>plotCurrent(h, c)