350 this =
this@error.BaseEstimator;
359 fprintf(
" error.DEIMEstimator: Starting offline computations...\n ");
370 a = general.AffParamMatrix;
371 if isa(fA,
" dscomponents.LinearCoreFun ")
375 a.addMatrix([
" abs( " fA.funStr[i]
" ) "],...
383 this.compute_jacmdeim(fm);
386 this.compute_simtrans(fm);
422 A = hlp - rm.
V*(W^
t*hlp);
424 prepared.M6= A^
t*(
G*A);
427 prepared.M6= []; prepared.M7= []; prepared.M8= []; prepared.M9= [];
430 if ~isempty(fm.System.B)
431 B = fm.System.B - rm.
V*(W^
t*fm.System.B);
432 prepared.M12= B^
t*(
G*B);
435 prepared.M9= []; prepared.M10= []; prepared.M11= []; prepared.M12= [];
437 if ~isempty(A) && ~isempty(B)
438 if isa(B,
" dscomponents.LinearInputConv ")
439 prepared.M9= 2*A^
t*(
G*B.B);
443 prepared.M9= 2*A^
t*(
G*B);
450 prepared.uolst=
addlistener(newd,
" OrderUpdated ",@prepared.handleOrderUpdate);
452 prepared.updateErrMatrices;
471 if this.deim.Order(2) == 0 && ~this.UseTrueDEIMErr
472 warning(
" KerMor:DEIMEstimator ",
" No DEIM error order set. Disabling error estimator. ");
481 [~, this.fullsol, ct] = rm.FullModel.computeTrajectory(mu, inputidx);
486 this.
LastAlpha= zeros(1,length(rm.Times));
487 this.
LastBeta= zeros(1,length(rm.Times));
488 this.lastvalpos= [1 1];
491 this.
M6.prepareSimulation(mu);
494 this.
M7.prepareSimulation(mu);
497 this.
M8.prepareSimulation(mu);
500 this.
M9.prepareSimulation(mu);
514 a = A - rm.V*(rm.W^t*A);
516 a = A - rm.V*(rm.V^t*A);
518 a = a + fs.f.evaluate(rm.V*x,t,
mu) ...
519 - rm.V*rm.System.f.evaluate(x,t,
mu);
521 hlp = fs.B.evaluate(t,
mu)*ut;
522 a = a + (hlp-rm.V*(rm.W^t*hlp));
524 a =
Norm.
LG(a,rm.FullModel.G);
527 v1 = f.evaluateComponentSet(1, x, t);
528 v2 = f.evaluateComponentSet(2, x, t);
532 a = v1
" *this.M3*v1 - v1 "*this.
M4*v2 + v2^t*this.
M5*v2;
535 a = a + x
" *this.M6.evaluate(x,t) + v1 "*this.
M7.evaluate(x,t) ...
536 - v2^t*this.
M8.evaluate(x,t);
538 a = a + x^t*this.
M9.evaluate(ut,t);
543 a = a + v1
" *this.M10.evaluate(t,mu)*ut - v2 "*this.
M11.evaluate(t,
mu)*ut ...
544 + ut^t*this.
M12.evaluate(t,
mu)*ut;
566 this.lastvalpos(1) = this.lastvalpos(1)+1;
586 tx = this.fullsol(:,find(abs(rm.scaledTimes - t) < eps,1));
593 b = d^t*(f.getStateJacobian(tx,t,
mu)*d) / diff;
596 b = d^t*(f.evaluate(tx,t,
mu) - f.evaluate(rx,t,
mu)) / diff;
630 fprintf(2,
" NaN b value occured in error.DEIMEstimator.getBeta!\n ");
636 if ~isempty(this.
Aln)
637 b = b + this.
Aln.compose(t,
mu);
640 this.
LastBeta(this.lastvalpos(2)) = b;
641 this.lastvalpos(2) = this.lastvalpos(2) + 1;
657 eint = this.
getBeta(x(1:end-1), t)*x(end) + this.
getAlpha(x(1:end-1), t, ut);
676 if ~isempty(inputidx)
677 ut = rm.System.Inputs[inputidx](t0);
679 x0 = rm.System.x0.evaluate(this.
mu);
684 time = toc(time) +
postProcess@error.BaseEstimator(
this, x, t, inputidx);
703 copy =
clone@error.BaseEstimator(
this, error.DEIMEstimator);
712 copy.deim= this.deim;
713 if ~isempty(copy.deim)
714 copy.uolst=
addlistener(copy.deim,
" OrderUpdated ",@copy.handleOrderUpdate);
719 copy.jstSize= this.jstSize;
720 copy.QFull= this.
QFull;
729 copy.scale= this.
scale;
730 copy.kexp= this.
kexp;
731 copy.fullsol= this.fullsol;
737 copy.M6= this.
M6.clone;
740 copy.M7= this.
M7.clone;
743 copy.M8= this.
M8.clone;
746 copy.M9= this.
M9.clone;
748 if ~isempty(this.
M10)
749 copy.M10= this.
M10.clone;
751 if ~isempty(this.
M11)
752 copy.M11= this.
M11.clone;
754 if ~isempty(this.
M12)
755 copy.M12= this.
M12.clone;
758 copy.Ah= this.
Ah.clone;
760 if ~isempty(this.
Aln)
764 copy.Bh= this.
Bh.clone;
772 str = sprintf(
" %s: Singular value decay for partial similarity transformation ",context);
773 h = pm.nextPlot(
" deimest_simtrans_singvals ",...
775 " transformation size ",
" singular values ");
776 semilogy(h,this.
QSingVals,
" LineWidth ",2);
784 jtd = data.ApproxTrainData.computeFrom(fm, ...
790 jd = general.MatrixDEIM;
794 fprintf(
" Computing matrix DEIM (MaxOrder=%d) of system jacobian...\n ",...
797 jd.computeDEIM(general.JacCompEvalWrapper(fm.
System.
f), ...
798 md.JacobianTrainData.fxi);
817 jtd = fm.Data.JacobianTrainData;
819 d = fm.System.f.xDim;
821 v = data.FileMatrix(d,n," Dir ",fm.Data.DataDirectory);
824 pi =
ProcessIndicator(" Computing Jacobian similarity transform data for %d jacobians ",n,false,n);
825 hassparse = ~isempty(fm.System.f.JSparsityPattern);
827 [i,j] = find(fm.System.f.JSparsityPattern);
831 J = sparse(i,j,jtd.fxi(:,nr),d,d);
833 J =
reshape(jtd.fxi(:,nr),d,d);
836 [ln(nr), v(:,nr)] =
Utils.logNorm(J);
844 jstd.CompTimes= times;
845 fm.Data.JacSimTransData= jstd;
850 [Q, this.
QSingVals] = p.computePOD(jstd.VFull);
851 if isa(Q," data.FileMatrix ")
852 this.
QFull= Q.toMemoryMatrix;
856 if size(this.
QFull,2) < this.JacSimTransMaxSize
857 fprintf(2," Only %d nonzero singular values in difference to %d desired ones. Setting JacSimTransMaxSize=%d\n ",...
858 size(this.QFull,2),this.JacSimTransMaxSize,size(this.QFull,2));
860 this.JacSimTransMaxSize= size(this.QFull,2);
863 red = 1-size(this.QFull,2)/size(this.QFull,1);
865 fprintf([" Computed partial similarity transform with target size %d over %d eigenvectors. "...
866 " Resulting reduction %d/%d (%g%%)\n "],...
867 p.Value,size(jstd.VFull,2),...
868 size(this.QFull,2),size(this.QFull,1),100*red);
872 fprintf(2," Achieved reduction under 20%%, disabling similarity transformation.\n ");
874 this.JacSimTransSize= ceil(this.JacSimTransMaxSize/2);
880 function handleOrderUpdate(unused1,unused2) {
881 this.updateErrMatrices;
885 function updateErrMatrices() {
886 if isempty(this.deim)
888 error(" Cannot update error matrices as no reduced model instance is specified for this estimator. ");
890 error(" Unintended error. No deim instance stored but a reduced model is set. ");
896 this.
ID,this.deim.Order);
899 if this.deim.Order(2) > 0
903 this.
M3= M1^
t*(
G*M1);
904 this.
M4= 2*M1^
t*(
G*M2);
905 this.
M5= M2^
t*(
G*M2);
907 this.
M7= 2*M1^
t*(
G*this.
Ah);
908 this.
M8= 2*M2^
t*(
G*this.Ah);
912 this.
M11= 2*M2^
t*(
G*this.Bh);
932 function computeLogNormApprox() {
934 load(fullfile(
KerMor.
App.HomeDirectory,
" data/lognorm/res_loclognorms_scaled.mat "));
960 #if 0 //mtoc++: 'get.JacSimTransSize'
962 value = this.jstSize;
969 #if 0 //mtoc++: 'set.JacSimTransSize'
973 if ~isequal(this.jstSize,value)
976 this.
QFull(:,1:this.jstSize));
979 error(
" Value must be empty or a positive int scalar smaller than JacSimTransMaxSize ");
987 #if 0 //mtoc++: 'get.JacMatDEIMOrder'
1000 #if 0 //mtoc++: 'set.JacMatDEIMOrder'
1010 error(" Cannot set an order higher (%d) than the current
JacMatDEIMMaxOrder of %d ",...
1019 #if 0 //mtoc++: 'set.TrainDataSelector'
1021 this.
checkType(value,
" data.selection.ASelector ");
1029 #if 0 //mtoc++: 'set.JacSimTransMaxSize'
1034 fprintf(2,
" New maximum size of similarity transform. Re-run of offlineComputations necessary.\n ");
1045 if ~isempty(obj.deim)
1046 obj.uolst=
addlistener(obj.deim,
" OrderUpdated ",@obj.handleOrderUpdate);
1056 if ~isa(model.
Approx,
" approx.DEIM ")
1057 errmsg =
" The reduced models core function must be a DEIM approximation. ";
1058 elseif ~isempty(model.
System.
B) && ...
1059 ~any(strcmp(
class(model.
System.
B),[
" dscomponents.LinearInputConv ",
" dscomponents.AffLinInputConv "]))
1060 errmsg =
" The systems input must be either Linear- or AffLinInputConv ";
1061 elseif ~isempty(model.
System.
A) && ...
1062 ~any(strcmp(
class(model.
System.
A),...
1063 [
" dscomponents.LinearCoreFun ",
" dscomponents.AffLinCoreFun "]))
1064 errmsg = [
" If the system component A is set, is has to be either a "...
1065 " LinearCoreFun or AffLinCoreFun. "];
integer JacSimTransSize
The size of the partial similarity transform to apply to the matrix DEIM approximated jacobians...
Collection of generally useful functions.
function time = postProcess(matrix< double > x,double t,integer inputidx)
Postprocessing for the error estimate.
UseJacobianLogLipConst
"Even More Expensive version 2": Precompute the full solution and use the true logarithmic lipschitz ...
integer fDim
The current output dimension of the function.
static function errmsg = validModelForEstimator(models.BaseFullModel model)
Abstract static method that forces subclasses to specify whether an estimator can be used for a given...
UseTrueLogLipConst
"Even More Expensive version": Precompute the full solution and use the true logarithmic lipschitz co...
Base interface for any approximation training data selection algorithm.
The base class for any KerMor detailed model.
models.BaseFullModel FullModel
The full model this reduced model was created from.
matrix< double > QFull
The complete similarity transformation matrix of size .
function J = getStateJacobian(x, t)
Default implementation of jacobian matrix evaluation via finite differences.
function ct = prepareConstants(colvec< double > mu,integer inputidx)
integer JacMatDEIMMaxOrder
Maximum order for the DEIM approximation of the state space jacobian.
models.BaseFirstOrderSystem System
The actual dynamical system used in the model.
dscomponents.AInputConv B
The input conversion.
function b = getBeta(colvec< double > x,double t)
Old log lip const kernel learning code x = x .* (this.scale(:,2) - this.scale(:,1)) + this...
function prepareSimulation(colvec< double > mu)
A method that allows parameter-dependent computations to be performed before a simulation using this ...
function plotSummary(pm, context)
function target = project(V, unused1)
scale
Stores zi min- and max scaling.
StateError
The reduction state-space error from the last simulation.
rowvec< double > QSingVals
The singular values computed by the SimTransPOD in the offline stage.
static function obj = loadobj(obj)
matrix< double > G
The custom scalar product matrix .
reshape
hanges the dimensions of the handle object array to the specified dimensions. See the MATLAB reshape ...
function prepared = prepareForReducedModel(models.ReducedModel rm)
Prepares this estimator for use with a given reduced model. Basically uses the projection matrices an...
The KerMor reduced model class.
Aln
The precomputed logarithmic norms of the system's A components.
matrix< double > V
The matrix that has been used for projection.
matrix< double > W
The biorthogonal matrix for V, i.e. .
dscomponents.ACompEvalCoreFun f
The function which DEIM is applied to.
function offlineComputations(models.BaseFullModel fm)
Overrides the method from BaseEstimator and performs additional computations.
Base class for all error estimators.
Enabled
Flag that indicates whether error estimation is used or not.
function fx = evaluate(colvec< double > x, unused1, unused2)
IReductionSummaryPlotProvider:
ID
An ID that allows to uniquely identify this DPCMObject (at least within the current MatLab session/co...
UseFullJacobian
"Expensive version": Using the full system's jacobian for logarithmic norm computation. Included for easy error estimator comparison.
approx.BaseApprox Approx
The approximation method for the CoreFunction.
virtual function copy = clone(target)
The interface method with returns a copy of the current class instance.
data.ModelData Data
The full model's data container. Defaults to an empty container.
UseJacobianNorm
Expensive conservative guess.
function M = evaluate(colvec< double > x,double t)
function checkType(obj, type)
Object typechecker.
static function rowvec< double > n = LG(matrix< double > x, G)
Returns the -induced norm for each column vector in .
dscomponents.ACoreFun f
The core f function from the dynamical system.
data.selection.ASelector TrainDataSelector
The selector that chooses the full model's trajectory points that are used for the MatrixDEIM approxi...
data.ApproxTrainData JacobianTrainData
Training data for the jacobian approximation.
integer JacMatDEIMOrder
The actual order of the DEIM approximation for the system's jacobian.
rowvec< double > scaledTimes
The time steps Times in scaled time units .
integer JacSimTransMaxSize
The maximum size of the similarity transformation.
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
Global configuration class for all KerMor run-time settings.
static function [ double ln , colvec< double > v ] = logNorm(matrix< double > A,matrix< double > G,colvec< double > v0)
Computes the logarithmic norm of a matrix , optionally using a positive definite symmetric matrix in...
models.ReducedModel ReducedModel
The reduced model associated with the error estimator.
static function KerMor theinstance = App()
The singleton KerMor instance.
Norm: Static class for commonly used norms on sets of vectors.
kexp
The local logarithmic norm estimation.
addlistener
Creates a listener for the specified event and assigns a callback function to execute when the event ...
ExtraODEDims
The dimensions added to the ODE function by the estimator.
function setSimilarityTransform(Qk)
UseTrueDEIMErr
"Expensive" version that uses the true approximation error between the DEIM approximation and the ful...
DEIMEstimator: A-posteriori error estimation for DEIM reduced models.
function a = getAlpha(colvec< double > x,double t,colvec< double > ut)
More expensive variant, using the true DEIM approximation error instead of the estimated ones using M...
general.MatrixDEIM JacMDEIM
The MatrixDEIM instance used to approximate the state space jacobian matrices.
function eint = evalODEPart(colvec< double > x,double t,colvec< double > ut)
Compose the ode function.
dscomponents.LinearCoreFun A
Represents a linear or affine-linear component of the dynamical system.
ProcessIndicator: A simple class that indicates process either via waitbar or text output...