200 this =
this@approx.BaseApprox(sys);
208 if ~isa(this.
f,
" dscomponents.ACompEvalCoreFun ");
209 error(
" Cannot use DEIM with no ACompEvalCoreFun core functions. ");
218 p.UseSVDS= size(atd.fxi,1) > 10000;
219 this.
u= p.computePOD(atd.fxi);
222 warning(
" Less singular values (%d) than MaxOrder (%d). Setting MaxOrder=%d ",...
228 this.
pts= this.getInterpolationPoints(this.
u);
231 SP = this.
f.JSparsityPattern;
236 invalid = sum(SP,2) == 0;
237 if any(invalid(this.pts))
238 invalididx = find(invalid);
239 this.pts= setdiff(this.pts, invalididx,
" stable ");
242 warning(
" Detected Jacobian rows with all zero entries. New MaxOrder=%d (Prev: %d) ",this.
MaxOrder,old);
246 je = zeros(1,length(this.pts));
247 for i=1:length(this.pts)
248 sprow = SP(this.
pts(i),:);
265 zi = atd.xi.toMemoryMatrix;
267 zi = this.
W^
t*atd.xi.toMemoryMatrix;
277 vatd = data.ApproxTrainData(zi,atd.ti,atd.mui);
279 vatd.fxi= sparse(this.pts,1:mo,ones(mo,1),size(atd.fxi,1),mo)^
t*fzi;
288 off = this.
jend(idx-1);
290 xireq = atd.xi(this.
jrow(off+1:this.
jend(idx)),:);
291 latd = data.ApproxTrainData(xireq, atd.ti, atd.mui);
292 latd.fxi= atd.fxi(this.
pts(idx),:);
306 c = zeros(this.
fOrder,size(x,2));
313 off = off + this.
jend(o-1);
329 s = RandStream(
" mt19937ar ",
" Seed ",42);
331 nTraj = this.
System.
Model.Data.TrajectoryData.getNumTrajectories();
333 ntimes = size(this.
System.
Model.Data.TrajectoryData,2);
334 nJac = min(nJac, nTraj*ntimes);
335 nMu = size(this.
System.
Model.Data.ParamSamples, 2);
338 dim = m.Approx.f.xDim;
339 JSP =
logical(sparse(dim,dim));
341 if m.System.ParamCount == 0
343 [Xi, ~, ~, ~] = m.Data.TrajectoryData.getTrajectoryNr(s.randperm(nTraj,min(nJac,nTraj)));
345 for j = s.randperm(size(Xi,2),nJac)
352 k = s.randperm(size(Xi,3),1);
361 error(
" Have no parameter samples, yet the system has configured some. ");
364 nMuToUse = min(nMu, nJac);
365 nJacPerMu = floor(nJac/nMuToUse);
369 mus = m.Data.ParamSamples(:, s.randperm(nMu,nMuToUse));
379 inputindex = m.System.inputidx;
381 [Xi, ~] = m.Data.TrajectoryData.getTrajectory(muu,inputindex);
383 for j = randperm(size(Xi,2),nJacPerMu)
397 nJacDone = nJacDone + 1;
409 projected = this.
clone;
416 projected.V1Expansion.Ma= orig;
418 projected =
project@approx.BaseApprox(
this, V, W, projected);
419 projected.updateOrderData;
424 copy = approx.KernelEI(this.
System);
425 copy =
clone@approx.BaseApprox(
this, copy);
431 copy.jrow= this.
jrow;
432 copy.jend= this.
jend;
438 copy.jend= this.
jend;
439 copy.jrow= this.
jrow;
450 function pts = getInterpolationPoints(
u) {
455 [v(1),
pts(1)] = max(abs(
u(:,1)));
459 c = (P
" *u(:,1:(i-1))) \ (P "*
u(:,i));
460 [v(i),
pts(i)] = max(abs(
u(:,i) -
u(:,1:(i-1))*c));
461 P = sparse(
pts(1:i),1:i,ones(i,1),n,i);
464 fprintf(
" DEIM interpolation points [%s] with values [%s] ",...
477 function updateOrderData() {
480 P = sparse(this.
pts(1:o),1:o,ones(o,1),n,o);
481 this.
U= this.
u(:,1:this.
fOrder) * ...
484 this.
U= this.
W^
t*this.
U;
487 len = this.
jend(end);
488 sel = this.
jrow(1:len);
490 this.
S= this.
V(sel,:);
492 this.
S= sparse(1:len,sel,ones(len,1),len,n);
505 #if 0 //mtoc++: 'get.Order'
506 function o =
Order() {
514 #if 0 //mtoc++: 'set.Order'
515 function
Order(value) {
516 if isempty(this.u) || isempty(this.
pts)
519 if value > size(this.u,2) || value < 1
520 error(" Invalid
Order value. Allowed are integers in [1, %d] ",size(this.u,2));
524 this.updateOrderData;
531 #if 0 //mtoc++: 'set.MaxOrder'
547 m = models.pcd.PCDModel(1);
550 m.EnableTrajectoryCaching=
false;
553 ec = kernels.config.ParamTimeExpansionConfig;
554 ec.StateConfig= kernels.config.GaussConfig(
" G ",1:3);
556 ec.ParamConfig= kernels.config.GaussConfig(
" G ",1:3);
558 a = approx.algorithms.VKOGA;
559 a.MaxExpansionSize= 300;
560 a.UsefScaling=
false;
561 a.UsefPGreedy=
false;
564 kei = approx.KernelEI(m.System);
569 m.Approx.MaxOrder= 5;
570 m.System.Params(1).Desired = 2;
571 m.SpaceReducer= spacereduction.PODGreedy;
572 m.SpaceReducer.Eps= 1e-5;
573 m.offlineGenerations;
575 mu = m.getRandomParam;
576 r = m.buildReducedModel;
580 m.off5_computeApproximation;
582 r = m.buildReducedModel;
Collection of generally useful functions.
matrix< double > Ma
The coefficient data for each dimension.
KernelEI: DEIM approximation using kernel expansions for function/operator evaluations.
natural nJacobians
nJacobians: number of Jacobian samples to use for empirical sparsity detection i.e. we choose nJacobians many Jacobian samples from trajectories number
The base class for any KerMor detailed model.
CustomProjection
Set this property if the projection process is customized by overriding the default project method...
models.BaseFirstOrderSystem System
The actual dynamical system used in the model.
function prepareSimulation(colvec< double > mu)
A method that allows parameter-dependent computations to be performed before a simulation using this ...
logical TimeDependent
Flag that indicates if the ACoreFun is (truly) time-dependent.
Model
The Model this System is attached to.
integer MaxOrder
The maximum order up to which the DEIM approximation should be computed.
static function res = test_KernelEI()
U
The U matrix for the current Order.
rowvec< kernels.KernelExpansion > V2Expansions
The array of kernel expansions of using Variant 2.
function ESP = computeEmpiricalSparsityPattern()
function target = project(V, W)
function fx = evaluate(matrix x, varargin)
Evaluates the kernel expansion.
kernels.KernelExpansion V1Expansion
The Kernel expansion computed if using Variant 1.
function approximateSystemFunction(models.BaseFullModel model)
models.BaseFirstOrderSystem System
The system associated with the current ACoreFun.
integer Order
The actual order for the current DEIM approximation.
V
The matrix of the biorthogonal pair .
colvec< double > mu
The current model parameter mu for evaluations. Will not be persisted as only valid for runtime durin...
data.ModelData Data
The full model's data container. Defaults to an empty container.
Abstract base class for all core function approximations inside dynamical systems.
dscomponents.ACoreFun f
The core f function from the dynamical system.
function fx = evaluateCoreFun(colvec< double > x,double t)
Actual method used to evaluate the dynamical sytems' core function.
function fx = evaluateMulti(colvec< double > x,double t,colvec< double > mu)
Evaluates this function on multiple locations and maybe multiple times and parameters.
function projected = project(V, W)
static function char str = implode(char|rowvec data,char glue,char format)
Implodes the elements of data using glue.
function [ matrix< double > J , dx ] = getStateJacobianFD(x, t,rowvec< integer > partidx)
Implementation of jacobian matrix evaluation via finite differences.
function copy = clone(copy)
The interface method with returns a copy of the current class instance.
Global configuration class for all KerMor run-time settings.
approx.ABase Algorithm
An approx.ABase approximation algorithm that is used to learn the component functions (either simulta...
static function KerMor theinstance = App()
The singleton KerMor instance.
u
The full approximation base.
Variant
The variant to use.
W
The matrix of the biorthogonal pair .
data.ApproxTrainData ApproxTrainData
Training data for the core function approximation.
ProcessIndicator: A simple class that indicates process either via waitbar or text output...
KernelExpansion: Base class for state-space kernel expansions.