1 namespace dscomponents{
236 " MultiArgumentEvaluations ",
" JSparsityPattern ",...
237 " TimeDependent ",
" xDim ",
" fDim ");
250 error(
" The target parameter must be given if custom projection is used. ");
254 target =
project@general.AProjectable(
this, V, W, target);
257 target.xDim= this.
xDim;
259 target.xDim= size(V,2);
263 target.fDim= this.
fDim;
265 target.fDim= size(W,2);
298 if ~cp && ~isempty(this.
V)
302 if ~cp && ~isempty(this.
V)
336 singlemu = size(mu,2) == 1;
345 t =
double.empty(0,size(x,2));
346 elseif length(t) == 1
347 t = ones(1,size(x,2))*
t;
353 fx = zeros(this.
fDim, m);
354 for idx = 1:size(x,2)
358 fx(:,idx) = this.
evaluate(x(:,idx),
t(:,idx));
401 J = this.
W^t*(J*this.
V);
439 if nargin == 1 || ~isa(copy,
" dscomponents.ACoreFun ")
440 error(
" Incorrect call to clone. As this class is abstract, a subclass of ACoreFun has to be passed as second argument. ");
442 copy =
clone@general.AProjectable(
this, copy);
449 copy.xDim= this.
xDim;
450 copy.fDim= this.
fDim;
459 partidx = 1:this.
xDim;
461 len = length(partidx);
463 dx = ones(d,1)*sqrt(eps(
class(x))).*max(abs(x),1);
465 DX = sparse(1:d,1:d,dx,d,d);
530 #if 0 //mtoc++: 'set.CustomProjection'
533 error(" Property must be
logical/
boolean. either true or false ");
542 #if 0 //mtoc++: 'set.JSparsityPattern'
544 if ~isempty(value) && ~issparse(value)
554 #if 0 //mtoc++: 'set.xDim'
555 function
xDim(value) {
566 #if 0 //mtoc++: 'set.fDim'
567 function
fDim(value) {
569 error("
fDim must be a positive integer. ");
581 x = rand(this.
xDim,200);
582 mui = rand(mudim,200);
584 fxs = zeros(size(x));
585 for idx = 1:size(x,2)
587 fxs(:,idx) = this.
evaluate(x(:,idx), idx);
589 err = sum((fxm-fxs).^2,1);
590 res =
all(err < eps);
608 xa = rand(this.
xDim,20);
612 if nargin < 4 || isempty(mua)
613 mua =
double.empty(0,size(xa,2));
614 if nargin < 3 || isempty(ta)
615 ta =
double.empty(0,size(xa,2));
620 perstep = floor((256*1024^2)/(8*d));
622 steps = ceil(d/perstep);
623 gpi = steps == 1 && size(xa,2) > 1;
625 pi =
ProcessIndicator(
" Comparing %d %dx%d jacobians with finite differences ",...
626 size(xa,2),
false,size(xa,2),this.
fDim,this.
xDim);
629 mua = repmat(mua,1,size(xa,2));
633 haspattern = ~isempty(JSP);
636 x = xa(:,i);
t = ta(:,i);
642 pi =
ProcessIndicator(
" Comparing %dx%d jacobian with finite differences over %d blocks of size %d ",...
643 steps,
false,this.
fDim,this.
xDim,steps,min(d,perstep));
646 pos = (k-1)*perstep+1:min(d,k*perstep);
654 if haspattern && any(J(zero(:,pos)))
655 warning(
" Jacobian Pattern mismatch between given and finite-difference version! ");
656 ax = pm.nextPlot(,
" Nonzero positions ");
658 errpos = zero(:,pos) &
logical(J);
660 [rows,columns] = find(errpos)
665 diff = abs(J-Jc(:,pos));
666 reldiff = abs((J-Jc(:,pos))./J);
667 abserr = max(diff(:));
670 r = reldiff(~iszero);
671 [r, idx] =
sort(r,
" descend ");
673 pos = find(r < 1e-2,1);
674 if ~isempty(pos) && pos > 1
675 ax = pm.nextPlot(,...
676 sprintf(
" Relative errors larger than 1e-2\nCorresponding absolute difference "));
678 ax = plotyy(1:pos,r(1:pos),1:pos,di(1:pos),
" plot ");
684 ax = pm2.nextPlot(,
" FD-Jacobian ");
687 ax = pm2.nextPlot(,
" Analytic Jacobian ");
690 ax = pm.nextPlot(,...
691 sprintf(
" Points greater than ten percent\nof the max abs error %g ",abserr));
775 obj.CustomProjection= from.CustomProjection;
776 obj.JSparsityPattern= from.JSparsityPattern;
777 obj.TimeDependent= from.TimeDependent;
780 obj =
loadobj@general.AProjectable(obj, from);
783 obj =
loadobj@general.AProjectable(obj);
integer fDim
The current output dimension of the function.
CustomProjection
Set this property if the projection process is customized by overriding the default project method...
function J = getStateJacobian(x, t)
Default implementation of jacobian matrix evaluation via finite differences.
Interface for all components that can be projected.
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.
Base class for any KerMor class.
sort
ort the handle objects in any array in ascending or descending order.
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
function res = test_MultiArgEval(mudim)
Convenience function that tests if a custom MultiArgumentEvaluation works as if called with single ar...
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Basic interface for all dynamical system's core functions Inherits the AProjectable interface...
logical LeaveOpen
Flag indicating if the plots should be left open once the PlotManager is deleted (as variable) ...
KerMorObject()
Constructs a new KerMor object.
integer xDim
The current state space dimension of the function's argument .
virtual function fx = evaluateCoreFun(colvec< double > x,double t)
Actual method used to evaluate the dynamical sytems' core function.
models.BaseFirstOrderSystem System
The system associated with the current ACoreFun.
static function obj = loadobj(obj, from)
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...
function copy = clone(copy)
The interface method with returns a copy of the current class instance.
function fx = evaluate(x, t)
Evaluates the f-approximation. Depending on a possible projection and the CustomProjection-property t...
sparse< logical > JSparsityPattern
Sparsity pattern for the jacobian matrix.
function fx = evaluateMulti(colvec< double > x,double t,colvec< double > mu)
Evaluates this function on multiple locations and maybe multiple times and parameters.
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
function [ matrix< double > J , dx ] = getStateJacobianFD(x, t,rowvec< integer > partidx)
Implementation of jacobian matrix evaluation via finite differences.
Global configuration class for all KerMor run-time settings.
function logical res = test_Jacobian(matrix< double > xa,rowvec< double > ta,matrix< double > mua)
Tests the custom provided jacobian matrix against the default finite difference computed one...
static function KerMor theinstance = App()
The singleton KerMor instance.
W
The matrix of the biorthogonal pair .
function J = getStateJacobianImpl(colvec< double > x,double t)
Default implementation of state jacobians. uses finite differences.
Base class for all KerMor first-order dynamical systems.
function target = project(V, W, target)
Sets the protected matrices that can be utilized on core function evaluations after projection...
ProcessIndicator: A simple class that indicates process either via waitbar or text output...