479 fTrainingInputs =
"[]";
481 fTrainingParams =
"[]";
490 this =
this@models.BaseModel;
494 this.
addlistener(
" Name ",
" PostSet ", @this.nameChanged);
502 this.
Sampler= sampling.RandomSampler;
512 this.
registerProps(
" Sampler ",
" SpaceReducer ",
" Approx ",...
513 " preApproximationTrainingCallback ",
" postApproximationTrainingCallback ",...
514 " Data ",
" TrainingInputs ",
" AutoSave ");
517 this.
addlistener(
" T ",
" PreSet ", @this.intTimeChanging);
518 this.
addlistener(
" dt ",
" PreSet ", @this.intTimeChanging);
519 this.
addlistener(
" T ",
" PostSet ", @this.intTimeChanged);
520 this.
addlistener(
" dt ",
" PostSet ", @this.intTimeChanged);
540 delete@models.BaseModel(
this);
551 error(
" No parameter sampler set for a parameterized system. See package sampling and the Sampler property of the BaseFullModel class. ");
568 completed = zeros(3,num_s*num_in);
569 tlen = length(this.
Times);
593 fprintf(
" Starting parallel projection training data computation of %d trajectories on %d workers...\n ",size(idxmat,2),matlabpool(
" size "));
595 paridx = idxmat(1,:);
607 if remote.Data.SampleCount > 0
609 mu = remote.Data.getParams(paridx(idx));
613 if remote.TrainingInputCount > 0
614 inputidx = inidx(idx);
618 [
t, x, ctime] = remote.computeTrajectory(mu, inputidx);
621 remote.Data.TrajectoryData.addTrajectory(x, mu, inputidx, ctime);
630 completed(:,idx) = [inidx(idx); paridx(idx); size(x,2) == tlen];
637 td.consolidate(
this);
640 td.clearTrajectories;
656 pi =
ProcessIndicator(sprintf(
" Generating projection training data (%d trajectories)... ",num_in*num_s),num_in*num_s);
659 completed =
double.empty(3,0);
680 elseif size(x,2) ~= tlen
692 ok = size(x,2) == tlen;
695 warning(ME.identifier,
" Failed to compute trajectory:\n%s ",ME.message);
697 completed(:,end+1) = [inidx; pidx; ok];
714 incomplete = find(completed(3,:)==0);
720 fprintf(
" Computing input space span... ");
725 warning(
" KerMor:BaseFullModel ",
" Cannot compute B span, no System.B set. ");
728 if isa(B,
" dscomponents.LinearInputConv ")
729 o = general.Orthonormalizer;
731 elseif isa(B,
" dscomponents.AffLinInputConv ")
732 o = general.Orthonormalizer;
735 tmp = [tmp B.getMatrix(
k)];
740 warning(
" KerMor:BaseFullModel ",
" B span computation: Case %s not yet implemented ",
class(B));
769 fprintf(
" Adjusting TargetDimensions of space reducer#%d: Selection "" : "" invalid when having algebraic constraints.\n ",
k);
771 elseif any(td > dim-numalgdofs)
772 disp(td(td > dim-numalgdofs));
773 error(
" Cannot select algebraic constraints for reduction (Check System.AlgebraicConditionDoF and SpaceReducer.TargetDimensions) ! Conflicting DoF indices above. ");
777 fprintf(
" Computing %d projection space(s)...\n ",ns);
780 [V, W] = s.generateReducedSpace(
this);
797 this.
System.
f,
this.Approx.TrainDataSelector,
this.ComputeParallel);
818 error(
" No approximation training data available. Called off4_genApproximationTrainData? ");
826 fprintf(
" Starting approximation process for %d dimensions ...\n ",size(this.
Data.
ApproxTrainData.
fxi,1));
856 fprintf(
" Starting error estimator offline computations...\n ");
858 e.offlineComputations(
this);
894 reduced = models.ReducedModel(
this);
895 reduced.build(varargin[:]);
932 error(
" Nonlinarity properties fDim and xDim not set. See dscomponents.ACoreFun ");
940 [x, time] = this.
Data.
SimCache.getTrajectory([this.
T; this.
dt; mu], inputidx);
944 if size(x,2) < length(t)
945 warning(
" Inconsistent trajectory data: Cached trajectory shorter than current time-steps. Using matching subarray of model.scaledTimes ");
947 elseif size(x,2) > length(t)
948 error(
" Inconsistent trajectory data: More trajectory samples than time-steps in current model. Please fix. ");
968 if size(x,2) == length(this.
Times)
969 this.
Data.
SimCache.addTrajectory(x, [this.
T; this.
dt; mu], inputidx, time);
971 warning(
" KerMor:InconsistentTrajectoryData ",...
972 " Not caching trajectory: Returned result size differs from simulation times. ");
1016 if isempty(fd.ProjectionSpaces)
1024 if target_dim > size(fd.ProjectionSpaces(1).V,2)
1025 warning(
" Target dimension %d too large, using max value of %d. ",...
1026 target_dim,size(fd.ProjectionSpaces(1).V,2));
1027 target_dim = size(fd.ProjectionSpaces(1).V,2);
1029 V = fd.ProjectionSpaces(1).V(:,1:target_dim);
1094 function file =
save(
char directory,
char filename) {
1099 warning(
" KerMor:NoSaveTag ",
" No SaveTag set. Using default 'model.mat' ");
1100 filename =
" model.mat ";
1106 file = fullfile(directory,filename);
1130 function intTimeChanging(src,unused1) {
1131 this.ftcold.(src.Name) = this.(src.Name);
1135 function intTimeChanged(src,unused1) {
1136 if this.ftcold.(src.Name) ~= this.(src.Name)
1137 md = this.
Data.TrajectoryData;
1138 if md.getNumTrajectories > 0
1147 function nameChanged(unused1,unused2) {
1150 strrep(strtrim(this.
Name)," "," _ ")," [^\d\w~-] ",);
1155 function autoSave() {
1170 #if 0 //mtoc++: 'set.Sampler'
1172 this.
checkType(value,
" sampling.BaseSampler ");
1180 #if 0 //mtoc++: 'set.Data'
1181 function
Data(value) {
1182 this.
checkType(value,
" data.ModelData ");
1183 if ~isequal(this.
Data, value)
1193 #if 0 //mtoc++: 'set.SpaceReducer'
1195 this.
checkType(value,
" spacereduction.BaseSpaceReducer ");
1203 #if 0 //mtoc++: 'set.Approx'
1205 this.
checkType(value,
" approx.BaseApprox ");
1213 #if 0 //mtoc++: 'set.preApproximationTrainingCallback'
1215 if ~isempty(value) && ~isa(value,
" function_handle ")
1216 error(" Value must be a function
handle taking the current model instance ");
1225 #if 0 //mtoc++: 'set.postApproximationTrainingCallback'
1227 if ~isempty(value) && ~isa(value,
" function_handle ")
1228 error(" Value must be a function
handle taking the current model instance ");
1237 #if 0 //mtoc++: 'set.TrainingInputs'
1241 error(" Value may only contain valid indices for the Inputs
cell array. ");
1242 elseif any(value > this.
System.InputCount) || any(value < 1)
1243 error(" Invalid indices for Inputs. ");
1244 elseif isempty(this.
System.B)
1245 error(" You must set the system "" s property B when using training inputs. ");
1248 this.fTrainingInputs= value;
1255 #if 0 //mtoc++: 'set.TrainingParams'
1259 error(" Value may only contain valid indices for the parameter array. ");
1260 elseif any(value > this.
System.ParamCount) || any(value < 1)
1261 error(" Invalid indices for Inputs. ");
1264 this.fTrainingParams= value;
1271 #if 0 //mtoc++: 'set.ProjectApproxTrainingData'
1273 if ~islogical(value) || ~isscalar(value)
1283 #if 0 //mtoc++: 'set.EnableTrajectoryCaching'
1285 if ~islogical(value) || ~isscalar(value)
1295 #if 0 //mtoc++: 'set.AutoSave'
1297 if ~islogical(value) || ~isscalar(value)
1298 error("
AutoSave must be a flag (scalar logical) ");
1307 #if 0 //mtoc++: 'get.TrainingInputs'
1309 ti = this.fTrainingInputs;
1316 #if 0 //mtoc++: 'get.TrainingParams'
1318 ti = this.fTrainingParams;
1325 #if 0 //mtoc++: 'get.TrainingInputCount'
1336 if ~isa(
this,
" models.BaseFullModel ") && nargin < 2
1337 error(
" The model class has changed but the loadobj method does not implement backwards-compatible loading behaviour.\nPlease implement the loadobj-method in your subclass and pass the loaded object struct as second argument. ");
1340 this =
loadobj@models.BaseModel(
this, sobj);
1342 this.
Approx= sobj.Approx;
1351 this.fTrainingInputs= sobj.fTrainingInputs;
1353 this.ftcold= sobj.ftcold;
1354 if isfield(sobj,
" AutoSave ")
1355 this.
AutoSave= logical(sobj.AutoSave);
1357 if isfield(sobj,
" TrajectoriesCompleted ")
1363 this.Data= sobj.Data;
1365 this =
loadobj@models.BaseModel(
this);
1367 this.
addlistener(
" T ",
" PreSet ", @this.intTimeChanging);
1368 this.
addlistener(
" dt ",
" PreSet ", @this.intTimeChanging);
1369 this.
addlistener(
" T ",
" PostSet ", @this.intTimeChanged);
1370 this.
addlistener(
" dt ",
" PostSet ", @this.intTimeChanged);
1371 this.
addlistener(
" Name ",
" PostSet ", @this.nameChanged);
1379 m = models.BaseFullModel;
1380 af = dscomponents.AffLinCoreFun(m.System);
1381 af.addMatrix(
" 1 ", rand(4,4));
1382 af.addMatrix(
" sum(mu)*5 ", rand(4,4)*3);
1385 m.System.x0= dscomponents.ConstInitialValue(sin(1:4)^
t);
1386 m.System.addParam(
" test ",.5,
" Range ",[0 1],
" Desired ",10);
1387 m.System.MaxTimestep= m.dt/2;
1389 m.offlineGenerations;
1390 red = m.buildReducedModel;
1392 m.simulate(m.getRandomParam);
1393 red.simulate(m.getRandomParam);
1402 m = models.BaseFullModel;
1407 m.System= models.BaseFirstOrderSystem(m);
1408 m.System.f= dscomponents.PointerCoreFun(@(x,
t,mu)A*x,2);
1409 m.System.x0= dscomponents.ConstInitialValue(sin(1:2)^
t);
1411 m.offlineGenerations;
1414 m.buildReducedModel;
1427 ts = testing.testsettings;
1429 m.Approx.Algorithm.ExpConfig.ParamConfig= [];
1431 s.f= dscomponents.PointerCoreFun(ts.flin,ts.testdim);
1434 m.offlineGenerations;
1435 r = m.buildReducedModel;
1442 ts = testing.testsettings;
1444 m.Approx.Algorithm.ExpConfig.ParamConfig= [];
1447 s.f= dscomponents.PointerCoreFun(ts.flin,ts.testdim);
1450 m.offlineGenerations;
1451 r = m.buildReducedModel;
1458 ts = testing.testsettings;
1462 s.f= dscomponents.PointerCoreFun(ts.flin,ts.testdim);
1465 m.offlineGenerations;
1466 r = m.buildReducedModel;
1473 ts = testing.testsettings;
1475 m.Approx.Expansion.ParamKernel= ts.ParamKernel;
1477 s.f= dscomponents.PointerCoreFun(ts.flin_p,ts.testdim);
1479 for idx = 1:length(ts.params)
1481 s.addParam(p.Name, p.Default,
" Range ", [p.MinVal p.MaxVal],
" Desired ", p.Desired);
1483 m.simulate(m.getRandomParam);
1484 m.offlineGenerations;
1485 r = m.buildReducedModel;
1486 r.simulate(r.getRandomParam);
1492 ts = testing.testsettings;
1494 m.Approx.Algorithm.ExpConfig.ParamConfig= [];
1496 s.B= dscomponents.PointerInputConv(ts.B);
1497 s.f= dscomponents.PointerCoreFun(ts.flin,ts.testdim);
1499 s.Inputs= ts.Inputs;
1501 m.TrainingInputs= 1:ts.testinputs;
1502 m.offlineGenerations;
1503 r = m.buildReducedModel;
1510 ts = testing.testsettings;
1513 s.f= dscomponents.PointerCoreFun(ts.flin_p, ts.testdim);
1514 s.B= dscomponents.PointerInputConv(ts.B_p);
1516 for idx = 1:length(ts.params)
1518 s.addParam(p.Name, p.Default,
" Range ", [p.MinVal p.MaxVal],
" Desired ", p.Desired);
1520 s.Inputs= ts.Inputs;
1521 m.simulate(m.getRandomParam, 1);
1522 m.TrainingInputs= 1:ts.testinputs;
1523 m.offlineGenerations;
1524 r = m.buildReducedModel;
1525 r.simulate(r.getRandomParam, 1);
1531 ts = testing.testsettings;
1534 s.f= dscomponents.PointerCoreFun(ts.fnlin,ts.testdim);
1536 m.Approx.Algorithm.ExpConfig.ParamConfig= [];
1538 m.offlineGenerations;
1539 r = m.buildReducedModel;
1546 ts = testing.testsettings;
1549 s.f= dscomponents.PointerCoreFun(ts.fnlin_p,ts.testdim);
1551 for idx = 1:length(ts.params)
1553 s.addParam(p.Name, p.Default,
" Range ", [p.MinVal p.MaxVal],
" Desired ", p.Desired);
1555 m.simulate(m.getRandomParam);
1556 m.offlineGenerations;
1557 r = m.buildReducedModel;
1558 r.simulate(r.getRandomParam);
1564 ts = testing.testsettings;
1566 m.Approx.Algorithm.ExpConfig.ParamConfig= [];
1568 s.B= dscomponents.PointerInputConv(ts.B);
1569 s.f= dscomponents.PointerCoreFun(ts.fnlin,ts.testdim);
1571 s.Inputs= ts.Inputs;
1573 m.offlineGenerations;
1574 r = m.buildReducedModel;
1581 ts = testing.testsettings;
1583 m.Approx.Expansion.ParamKernel= ts.ParamKernel;
1585 s.f= dscomponents.PointerCoreFun(ts.fnlin_p,ts.testdim);
1586 s.B= dscomponents.PointerInputConv(ts.B_p);
1588 for idx = 1:length(ts.params)
1590 s.addParam(p.Name, p.Default,
" Range ", [p.MinVal p.MaxVal],
" Desired ", p.Desired);
1592 s.Inputs= ts.Inputs;
1593 m.simulate(m.getRandomParam,1);
1594 m.offlineGenerations;
1595 r = m.buildReducedModel;
1596 r.simulate(r.getRandomParam,1);
1602 ts = testing.testsettings;
1604 m.Approx.Algorithm.ExpConfig.ParamConfig= [];
1606 s.f= dscomponents.PointerCoreFun(ts.flin,ts.testdim);
1608 s.C= dscomponents.PointerOutputConv(@(
t,mu)
t,
true);
1610 m.offlineGenerations;
1611 r = m.buildReducedModel;
1618 m = models.circ.RCLadder(10);
1619 m.offlineGenerations;
1620 dir = m.Data.DataDirectory;
1623 m = models.circ.RCLadder(10);
1626 res = exist(dir,
" file ") == 0;
1629 m.Data.useFileTrajectoryData;
1630 m.ComputeTrajectoryFxiData=
true;
1631 m.TrainingInputs= [2 3];
1632 m.offlineGenerations;
1636 atd = m.Data.ApproxTrainData;
1637 atd.xi= atd.xi.copyWithNewBlockSize(0.1);
1638 atd.fxi= atd.fxi.copyWithNewBlockSize(0.1);
1640 dir = m.Data.DataDirectory;
1643 res = res && exist(dir,
" file ") == 0;
function file = save(char directory,char filename)
Saves this instance inside the data.ModelData.DataDirectory folder using the model's SaveTag if set o...
char Name
The name of the Model.
Collection of generally useful functions.
static function test_LinearModel()
integer fDim
The current output dimension of the function.
varargin TargetDimensions
This property determines which dimensions are to be reduced. It is possible to reduce the entire numb...
data.FileMatrix xi
The state space samples , stored row-wise in a data.FileMatrix instance.
static function res = test_FileSystemTidyness()
Plain small model.
static function comb = createCombinations(ranges, varargin)
Creates the cartesian product of the vectors passed as a matrix containing elements of each vector pe...
data.FileMatrix fxi
The evaluations of , stored row-wise in a data.FileMatrix.
function useFileTrajectoryData(logical overwrite)
Sets the TrajectoryData and TrajectoryFxiData classes to filesystem based versions.
BaseModel: Base class for both full and reduced models.
virtual function [ colvec< double > x , double ctime ] = getTrajectory(colvec< double > mu,integer inputidx)
Gets the traejctory for the given parameter and input index.
matrix< double > InputSpaceSpan
The orthonormalized vectors spanning the space of the input components.
logical isStatic
Determines if the model is time dependent or static.
error.BaseEstimator ErrorEstimator
The associated error estimator for this model.
virtual function approximateSystemFunction(model)
Computes the approximation according to the concrete approximation strategy.
function [ models.ReducedModel reduced , double time ] = buildReducedModel(varargin)
Builds a reduced model from a full model.
The base class for any KerMor detailed model.
function off6_prepareErrorEstimator()
Prepares offline data for a possible error estimator.
double dt
The desired time-stepsize for simulations.
integer TrainingInputs
The indices of inputs to use for training data generation. Uses the DefaultInput if not set (and Defa...
sampling.BaseSampler Sampler
The sampling strategy the Model uses.
static function test_TimeDependentOutput()
models.BaseFirstOrderSystem System
The actual dynamical system used in the model.
dscomponents.AInputConv B
The input conversion.
Times
Evaluation points of the model.
SampleCount
The number of samples contained in the model data.
function prepareSimulation(colvec< double > mu)
A method that allows parameter-dependent computations to be performed before a simulation using this ...
virtual function clearTrajectories()
Clears all stored trajectory data.
function setConfig(mu, inputidx)
Sets the dynamical system's configuration.
A MatLab cell array or matrix.
static function test_LinearModelNoProj()
colvec< data.ProjectionSpace > ProjectionSpaces
Array of ProjectionSpace instances that contains all the separate linear projection spaces computed d...
function off3_computeReducedSpace()
Offline phase 3: Generate state space reduction.
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
virtual function addTrajectory(colvec< double > x,colvec< double > mu,integer inputidx,double ctime)
Adds a trajectory to the ModelData instance.
logical RealTimePlotting
Determines if the simulation should plot intermediate steps during computation.
function_handle postApproximationTrainingCallback
Advanced property. Must be a function handle taking the current model instance.
matrix ParamSamples
A Model's parameter samples as column vector collection.
function transferFrom(data.ATrajectoryData source)
Transfers the data from one ATrajectoryData instance to another.
data.FileDataCollection TrajectoryFxiData
Evaluations of the system's nonlinearity on the trajectoriy data.
function [ double t , matrix< double > y , colvec< double > mu , in , ct ] = getSimCacheTrajectory(nr)
A MatLab function handle.
static function test_LinearModelInputs()
JKerMorExport: Export class for JaRMoS model generation from KerMor models.
Matlab's base handle class (documentation generation substitute)
function off4_genApproximationTrainData()
Generates the training data for the -approximation and precomputes values.
BaseSampler Basis class for parameter sampling classes.
static function test_NonlinearModelInputs()
DPCM: Default property change monitoring for MatLab class properties.
static function test_LinearModelParams()
ComputeParallel
Flag whether the code should be run in parallel or not.
Base class for all error estimators.
function [ V , W ] = assembleProjectionMatrices(target_dim)
A variable number of input arguments.
integer xDim
The current state space dimension of the function's argument .
BaseFullModel(char name)
Creates a new instance of a full model.
static function test_NonlinearModel()
ApproxTrainData(matrix< double > xi,rowvec< double > ti,matrix< double > mui)
Creates a new approx train data instance.
logical ProjectApproxTrainingData
Flag to determine if the data collected by the approx.Approx.TrainDataSelector should be projected in...
integer DefaultInput
The default input to use if none is given.
export.JKerMorExport JKerMorExport
Export instance for possible export of this model to JKerMor.
rowvec< integer > TrainingParams
The indices of the model parameters to use for training data generation.
function plotTrajectoryNr(nr)
logical ComputeTrajectoryFxiData
Flag that determines whether fxi data should be computed along with the trajectories or not...
static function res = test_BareModel()
approx.BaseApprox Approx
The approximation method for the CoreFunction.
disp
Handle object disp method which is called by the display method. See the MATLAB disp function...
double T
The final timestep up to which to simulate.
function addProjectionSpace(V, W, dims)
Adds a new projection space to the model data instance.
data.ModelData Data
The full model's data container. Defaults to an empty container.
function off5_computeApproximation()
Offline phase 5: Core function approximation.
function off2_genTrainingData()
Offline phase 2: Snapshot generation for subspace computation.
char DataDirectory
The root folder where the FileData's files are saved.
spacereduction.BaseSpaceReducer SpaceReducer
The reduction algorithm for subspaces.
function_handle preApproximationTrainingCallback
Advanced property. Must be a function handle taking the current model instance.
static function this = loadobj(this, sobj)
integer TrainingInputCount
Gets the number of inputs used for training.
static function test_BaseModels()
function off1_createParamSamples()
Offline phase 1: Sample generation.
ModelData(varargin)
Creates a new container for large full model data.
Abstract base class for all core function approximations inside dynamical systems.
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.
function checkType(obj, type)
Object typechecker.
logical EnableTrajectoryCaching
Flag that enables caching of computed trajectories in a simulation cache stored in KerMor's TempDirec...
IParallelizable Interface to indicate parallel computation capability of the implementing classes...
dscomponents.ACoreFun f
The core f function from the dynamical system.
function [ double t , colvec< double > x , double ctime ] = solveStatic(colvec< double > mu,integer inputidx)
Solves the linear system . Spatial dependence of f is neglected in the current implementation (since ...
function samples = generateSamples(models.BaseFullModel model)
function offlineGenerations()
Performs all large offline computations for model reduction.
function fx = evaluateMulti(colvec< double > x,double t,colvec< double > mu)
Evaluates this function on multiple locations and maybe multiple times and parameters.
ParamCount
The number of the system's parameters.
rowvec< double > scaledTimes
The time steps Times in scaled time units .
rowvec< double > OfflinePhaseTimes
The computation times for all phases of the last offline generation.
static function criticalsCheck(DPCMobj)
This is a shorthand method that runs the DPCM but only for critical properties.
virtual function [ colvec< double > x , colvec< double > mu , integer inputidx , double ctime ] = getTrajectoryNr(nr)
Gets the trajectory with the number nr.
function [ handle f , handle ax ] = plot(rowvec< double > t,matrix< double > y, varargin)
Plots the results of the simulation. Override in subclasses for a more specific plot if desired...
Data class that contains a model's large data, including subspace matrices, trajectories and approxim...
Global configuration class for all KerMor run-time settings.
static function test_NonlinearModelParams()
function matrix< double > mu = getParams(rowvec< int32 > idx)
Returns parameters for given indices.
logical AutoSave
Flag to enable automatic saving of the model after each individual offline phase step and at other lo...
BaseFirstOrderSystem(models.BaseFullModel model)
Creates a new base dynamical system class instance.
TrajectoriesCompleted
Contains a flag for each input/parameter combination which has been successfully computed completely ...
static function KerMor theinstance = App()
The singleton KerMor instance.
addlistener
Creates a listener for the specified event and assigns a callback function to execute when the event ...
data.ApproxTrainData ApproxTrainData
Training data for the core function approximation.
A MatLab character array.
Base class for all space reduction algorithms.
static function test_LinearModelNoApprox()
static function test_NonlinearModelParamsInput()
data.ATrajectoryData TrajectoryIncompleteData
The incomplete trajectory training data for the full model is saved separately.
ProcessIndicator: A simple class that indicates process either via waitbar or text output...
data.ATrajectoryData TrajectoryData
The trajectory training data for the full model (only complete trajectories!)
char SaveTag
A custom tag that can be used as a prefix to files for corresponding model identification.
static function test_LinearModelParamsInput()