228 this.
ModelData=
struct(
" Name ",[],
" ErrT ",[],
" RelErrT ",[]);
236 if isa(model,
" models.ReducedModel ")
237 this.
Model= model.FullModel;
262 est(end+1).Name =
" True error ";
263 e = error.DefaultEstimator;
265 est(end).Estimator = e.prepareForReducedModel(this.
ReducedModel);
266 est(end).Estimator.Enabled=
true;
267 est(end).MarkerStyle =
" o ";
268 est(end).LineStyle =
" - ";
269 est(end).Color = [0 0 1];
294 this.
ModelData(end).MinErr = min(errs(:));
295 this.
ModelData(end).OverestT = (errs(:,end)/errs(1,end))^
t;
296 this.
ModelData(end).RelErrT = relerrs(:,end)^
t;
297 this.
ModelData(end).MinRelErr = min(relerrs(:));
334 num = length(this.
Est);
335 ctimes = zeros(1,num);
342 str = ; compplot = [];
350 if isfield(el,
" Callback ") && ~isempty(el.Callback)
351 el.Callback(el.Estimator);
354 fprintf(
" Performing estimation %d of %d: %s...\n ",idx,num,el.Name);
362 if ~isa(el.Estimator,
" error.ExpensiveBetaEstimator ")
363 str = [str sprintf(
" errs(%d,end),ctimes(%d), "" %s "" , ",idx,idx,el.MarkerStyle)];
365 compplot(end+1) = idx;
377 if any(abs(errs(1,1) - errs(2:end,1))/errs(1,1) > 1e-4)
378 warning(
" KerMor:EstimatorAnalyzer ",...
379 " Relative difference in initial errors over 1e-4 detected. ");
380 figure; semilogy(errs(:,1));
396 yfullnorm = sqrt(sum(yf.*(
this.Model.G*yf),1));
397 relerrs = errs ./ repmat(yfullnorm,size(errs,1),1);
422 ax = pm.nextPlot(
" abserr ",[
" Error estimations for model: " this.
Model.
Name],...
423 " Time ",
" Error estimates ");
425 this.doPlots(errs, ax);
427 axis(ax,[this.
Model.
Times(
this.PlotStartIndex) this.
Model.
T this.getYMin(errs) 3*max(errs(:))]);
432 ax = pm.nextPlot(
" relerr ",[
" Relative error estimations e(t)/||y||, \Delta x(t)/||y|| for model: " ...
433 this.
Model.
Name],
" Time ",
" Relative error estimates ");
435 this.doPlots(relerrs, ax);
438 re(isinf(re)) = -Inf;
439 axis(ax,[this.
Model.
Times(
this.PlotStartIndex) this.
Model.
T this.getYMin(relerrs) 3*max(re)]);
444 ax = pm.nextPlot(
" ctimes ",[
" Error estimator computation times: " this.
Model.
Name],
" \Delta(T) ",
" Comp. time [s] ");
446 ph = zeros(length(this.
Est),1);
452 for idx = 1:length(this.
Est)
454 if isfield(e,
" Color ")
456 error(
" If a field 'Color' exists, all estimators must have assigned a color. ");
462 ph(idx) = plotfun(ax,errs(idx,end),ctimes(idx),...
463 " Marker ",e.MarkerStyle,
" Color ",c,...
464 " MarkerSize ",
this.MarkerSize*1.5);
468 c =
get(ph(i),
" Color ");
469 set(ph(i),
" MarkerFaceColor ",c);
470 set(ph(i),
" MarkerEdgeColor ",c*.7);
473 plot(ax,[errs(1,end) errs(1,end)],[min(ctimes) max(ctimes)],
" black ");
477 [a[:]] = this.
Est(:).Name;
478 legend(a,
" Location ",
" NorthEast ",
" Interpreter ",
" latex ");
479 axis([.9*min(errs(:,end)) 1.1*max(errs(:,end)) .9*min(ctimes(:)) 1.1*max(ctimes(:))]);
485 str =
" Estimator hierarchy (error*time product) ";
486 [~,idx] =
sort(errs(:,end).*ctimes^
t);
488 str =
" Estimator list ";
489 idx = 1:size(errs,2);
492 pt.HasRowHeader=
true;
493 pt.addRow(
" Name ",sprintf(
" $\\Delta(%g)$ ",this.
Model.
T),
" Time ",
" Efficiency ");
495 for id = 1:length(this.
Est)
496 pt.addRow(this.
Est(idx(
id)).Name,errs(idx(
id),end),ctimes(idx(
id)),...
497 errs(idx(
id),end)/errs(1,end),[sfun,
" %2.2fs ",sfun]);
510 fields = [
" ErrT ",
" RelErrT ",
" OverestT ",
" CTimes "];
511 fieldnames = [
" Errors ",
" Relative errors ",
" Overestimations ",
" Computation times "];
513 for fi = 1:length(fields)
517 t.Caption= sprintf(
" %s of estimation runs ",
fieldnames[fi]);
518 t.addRow(
" Model / Est ", this.
Est(:).Name);
521 if strcmp(fields[fi],
" CTimes ")
524 fmt = [[
" $%s$ "] repmat([fmt],1,length(this.
Est))];
531 nstr = [
" , \\mu=[ " sprintf(
" %2.2e ",md.mu)
" ] "];
533 if ~isempty(md.inputidx)
534 nstr = [nstr sprintf(
" , u_%d ",md.inputidx)];
536 hlp = num2cell(md.(fields[fi]));
537 t.addRow(nstr,hlp[:],fmt);
564 #if 0 //mtoc++: 'set.EstimatorIterations'
578 #if 0 //mtoc++: 'set.EstimatorVersions'
581 if ~isempty(this.ReducedModel)
583 this.buildEstimatorStruct(this.ReducedModel);
594 function matrix<double>y = getYMin(err) {
597 er = min(
reshape(err(:,2:end),1,[]));
598 if log10(abs(e1 - er)) < 5
606 function doPlots(data,ax) {
610 ph = semilogy(ax,times,data);
612 ph = plot(ax,times,data);
615 set(ph(1),
" LineWidth ",this.
LineWidth+.5);
621 for idx=1:length(this.
Est)
623 if isfield(e," Color ")
625 error(" If a field 'Color' exists,
all estimators must have assigned a color. ");
631 set(ph(idx)," LineStyle ",e.LineStyle," Color ",c);
633 pos = mod(sel+round(nt/(this.
NumMarkers*length(this.
Est)))*(idx-1),nt)+1;
634 h = plot(ax,times(pos), data(idx,pos), e.MarkerStyle,...
637 c = get(ph(idx)," Color ");
638 set(h," MarkerFaceColor ",c," MarkerEdgeColor ",c*.7);
641 [a[:]] = this.Est(:).Name;
642 [~,oh] = legend(a," Location "," NorthEast "," Interpreter "," latex "," FontSize ",14);
644 oh =
findobj(oh," Type "," line ");
645 for idx=1:length(this.Est)
646 c = get(ph(idx)," Color ");
647 set(oh(2*idx)," Marker ",this.Est(idx).MarkerStyle," MarkerFaceColor ",c,...
648 " MarkerEdgeColor ",c*.7," MarkerSize ",this.MarkerSize);
658 function buildEstimatorStruct(r) {
659 this.Est= this.buildKernelEstimatorStruct(r);
663 function est = buildKernelEstimatorStruct(r) {
668 est(end+1).Name = " True error ";
669 est(end).Estimator = error.DefaultEstimator(r);
670 est(end).Estimator.Enabled= true;
671 est(end).MarkerStyle = " o ";
672 est(end).LineStyle = " - ";
677 msg = error.GLEstimator.validModelForEstimator(r.FullModel);
678 e = error.GLEstimator;
679 e.offlineComputations(r.FullModel);
680 e = e.prepareForReducedModel(r);
682 fprintf(" Initializing Global Lipschitz estimator...\n ");
683 est(end+1).Name = " GLE ";
684 est(end).Estimator = e;
685 est(end).MarkerStyle = " s ";
686 est(end).LineStyle = " - ";
688 fprintf(" Cannot use the GLEstimator for model %s:\n%s\n ",r.Name,msg);
692 msg = error.IterationCompLemmaEstimator.validModelForEstimator(r.FullModel);
695 if ~isempty(this.
Model.Approx)
696 k = this.
Model.Approx.Expansion.Kernel;
698 k = this.
Model.System.f.Expansion.Kernel;
702 fprintf(" Using iteration counts: %s\n ",num2str(this.EstimatorIterations));
703 e = error.IterationCompLemmaEstimator;
704 e.offlineComputations(r.FullModel);
705 e = e.prepareForReducedModel(r);
707 fprintf(" Initializing LGL estimator...\n ");
708 est(end+1).Name = " LGL ";
709 est(end).Estimator = e;
710 est(end).Estimator.LocalLipschitzFcn= error.lipfun.LocalGradientLipschitz(
k);
711 est(end).Estimator.UseTimeDiscreteC= false;
712 est(end).MarkerStyle = " s ";
713 est(end).LineStyle = " - ";
715 orig = est(end).Estimator;
717 eval(sprintf([" est(end+1).Name = "" LGL, %d It "" ; "...
718 " est(end).Estimator = orig.clone; "...
719 " est(end).Estimator.Iterations = %d; "...
720 " est(end).MarkerStyle = "" s "" ; "...
721 " est(end).LineStyle = "" -. "" ; "],it,it));
726 fprintf(" Initializing LGLMod (mod secant) estimator...\n ");
727 est(end+1).Name = " LGLMod ";
728 est(end).Estimator = e.clone;
729 est(end).Estimator.LocalLipschitzFcn= error.lipfun.LocalSecantLipschitz(k);
730 est(end).Estimator.UseTimeDiscreteC= false;
731 est(end).MarkerStyle = " h ";
732 est(end).LineStyle = " - ";
734 orig = est(end).Estimator;
736 eval(sprintf([" est(end+1).Name = "" LGLMod, %d It "" ; "...
737 " est(end).Estimator = orig.clone; "...
738 " est(end).Estimator.Iterations = %d; "...
739 " est(end).MarkerStyle = "" h "" ; "...
740 " est(end).LineStyle = "" : "" ; "],it,it));
745 ilfcn = error.lipfun.ImprovedLocalSecantLipschitz(k);
749 fprintf(" Initializing LSL estimator...\n ");
750 est(end+1).Name = " LSLE ";
751 est(end).Estimator = e.clone;
752 est(end).Estimator.LocalLipschitzFcn= ilfcn.clone;
753 est(end).Estimator.UseTimeDiscreteC= false;
754 est(end).MarkerStyle = " p ";
755 est(end).LineStyle = " - ";
757 orig = est(end).Estimator;
759 eval(sprintf([" est(end+1).Name = "" LSLE, %d It "" ; "...
760 " est(end).Estimator = orig.clone; "...
761 " est(end).Estimator.Iterations = %d; "...
762 " est(end).MarkerStyle = "" p "" ; "...
763 " est(end).LineStyle = "" -- "" ; "],it,it));
769 td = error.IterationCompLemmaEstimator;
770 td.offlineComputations(r.FullModel);
771 td = td.prepareForReducedModel(r);
773 td.UseTimeDiscreteC= true;
777 fprintf(" Initializing LSL TD estimators...\n ");
778 est(end+1).Name = " LGL TD ";
779 est(end).Estimator = td;
780 est(end).Estimator.LocalLipschitzFcn= error.lipfun.LocalGradientLipschitz(k);
781 est(end).MarkerStyle = " < ";
782 est(end).LineStyle = " - ";
786 fprintf(" Initializing LSL TD estimators...\n ");
787 est(end+1).Name = " LGL TD ";
788 est(end).Estimator = td.clone;
789 est(end).Estimator.LocalLipschitzFcn= error.lipfun.LocalSecantLipschitz(k);
790 est(end).MarkerStyle = " < ";
791 est(end).LineStyle = " - ";
795 est(end+1).Estimator = est(end).Estimator.clone;
796 est(end).Name = " LSLE TD ";
797 est(end).Estimator = td.clone;
798 est(end).Estimator.LocalLipschitzFcn= ilfcn.clone;
799 est(end).MarkerStyle = " < ";
800 est(end).LineStyle = " - ";
803 fprintf(" Cannot use the IterationCompLemmaEstimator for model %s:\n%s\n ",r.Name,msg);
char Name
The name of the Model.
function setModel(models.BaseFullModel model)
Sets the model to use for the estimator demo.
Collection of generally useful functions.
function [ errs , relerrs , ctimes , double t , PlotManager pm ] = compute(colvec mu,integer inidx,PlotManager pm)
Runs the demo with the current settings.
fields
Returns a cell array of string containing the names of public properties.
function [ models.ReducedModel reduced , double time ] = buildReducedModel(varargin)
Builds a reduced model from a full model.
The base class for any KerMor detailed model.
models.BaseFullModel FullModel
The full model this reduced model was created from.
logical SortResultTable
Set flag to sort the resulting computation time and estimates table by the product of comp-time and e...
models.BaseFirstOrderSystem System
The actual dynamical system used in the model.
models.ReducedModel ReducedModel
The reduced model.
Times
Evaluation points of the model.
logical UseOutputError
Flag wether to use the output errors or state variable errors.
A MatLab cell array or matrix.
function pt = getResultTable(errs, ctimes)
function pm = createPlots(errs, relerrs, ctimes, pm)
OutputError
The output error from the last simulation.
function plotCTimes(errs, ctimes, pm)
StateError
The reduction state-space error from the last simulation.
sort
ort the handle objects in any array in ascending or descending order.
reshape
hanges the dimensions of the handle object array to the specified dimensions. See the MATLAB reshape ...
The KerMor reduced model class.
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
rowvec EstimatorIterations
How many estimator iterations should be performed?
rowvec EstimatorVersions
Chooses the estimator versions. Set to 1 for use, 0 for not use. 1: True Error 2: GLE...
models.BaseFullModel Model
The used model.
Matlab's base handle class (documentation generation substitute)
struct Est
A struct containing information about different error estimators.
error.BaseEstimator ErrorEstimator
The error estimator for the reduced model.
function est = getDefaultEstStruct()
Returns the default structure for the Est property of this class. Contains only the error...
fieldnames
Returns a cell array of string containing the names of public properties. See the MATLAB fieldnames f...
function relerrs = getRelativeErrorEstimates(errs,colvec< double > mu, inidx)
colvec StateScaling
The scaling for the state vectors.
MarkerSize
The marker size for error and relative errors plots.
double T
The final timestep up to which to simulate.
Analysis class for the error estimators.
ModelData
A struct with fields Name, ErrsT, RelErrsT that contains information about the estimations of the dif...
function [ errs , ctimes , varargout ] = getErrorEstimates(colvec< double > mu, inidx, withrel)
PrintTable: Class that allows table-like output spaced by tabs for multiple rows. ...
function ts = createStatsTables(sort)
Creates LaTeX tables with each the Errors,Relative errors,Overestimations and Computation times for t...
function [ t , x , time , cache ] = computeTrajectory(colvec< double > mu, inputidx)
Computes a solution/trajectory for the given mu and inputidx in the SCALED state space.
logical LogarithmicPlot
Determines whether to plot the errors on a logarithmic scale or not.
function offlineGenerations()
Performs all large offline computations for model reduction.
findobj
Finds objects matching the specified conditions from the input array of handle objects.
LineWidth
The line width to use.
PlotStartIndex
The position where to start plotting error estimates.
EstimatorAnalyzer(models.BaseFullModel model)
char SaveTexTables
Flag whether to save the time results as a LaTeX-Table into a text file.
ErrorOrders
% DEIM estimator related stuff The error orders to use. Unset if the JacDEIM/SimTranssizes version sh...
function plotRelativeErrors(relerrs, pm)
LinSpecIterator: Small helper class to automatically iterate through different line styles/markers/co...
A MatLab character array.
function plotErrors(errs, pm)
NumMarkers
The number of markers for error and relative errors plots.
static function str = getLatexStr(value, digits)
function [ rowvec< double > t , matrix< double > y , double sec , x ] = simulate(colvec< double > mu,integer inputidx)
Simulates the system and produces the system's output.
A variable number of output arguments.