intro kermor software library - uni-stuttgart.de · 10/32. matlabtm ag 22.02.2010 intro dynamical...

32
Matlab TM AG 22.02.2010 Intro Dynamical Systems Math. concepts Reduction methods Software requirements Offline/Online High level Medium level Detail level Software Design OOP Inheritance Design patterns Application in KerMOR Approximation generation System decomposition Kernels DS components Outlook An introduction to the KerMOR Software Library at the Matlab TM AG, Seminar ’Model Reduction and Real Time Simulation ’ 22.02.2010 Dipl. Math. Dipl. Inf. Daniel Wirtz Institut f¨ ur Angewandte Analysis und Numerische Simulation Universit¨ at Stuttgart Pfaffenwaldring 57 D-70569 Stuttgart 1 / 32

Upload: trinhdat

Post on 20-Jul-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

An introduction to the

KerMORSoftware Library

at the

MatlabTM AG,

Seminar’Model Reduction and Real Time Simulation ’

22.02.2010

Dipl. Math. Dipl. Inf. Daniel WirtzInstitut fur Angewandte Analysis und Numerische SimulationUniversitat StuttgartPfaffenwaldring 57D-70569 Stuttgart

1 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

IntroductionProject

AssociationI PN6: Model reduction, control and real-time simulation

I Parallel development to SimTech project ”KernelMethods for Model Order Reduction of BiochemicalSystems”

I Jun.-Prof. Dr. Bernard Haasdonk, IANS

I Started on February 1st, 2010

2 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Introduction

Cooperations

I Markus Daub, IADM:Mathematical Modelling of Programmed Cell Death

I Steffen Waldherr, IST:Estimation of biochemical network parameterdistributions in cell populations

Figure: Programmed cell death process3 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

General SettingMathematical notations

System for most general case

x ′(t) = f (x(t), t, µ)︸ ︷︷ ︸core function

+ B(t, µ)︸ ︷︷ ︸input conversion

uk(t)︸ ︷︷ ︸inputs

(1)

x(0) = x0(µ)︸ ︷︷ ︸initial state

(2)

y(t) = C (t, µ)︸ ︷︷ ︸output conversion

x(t) (3)

with t ∈ [0,T ], µ ∈ P and

f (x(t), t, µ) ∈ Rd , B(t, µ) ∈ Rd×m

uk(t) ∈ Rm, x(0) ∈ Rd

y(t) ∈ Rl , C (t, µ) ∈ Rl×d

4 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Reduction methodsSituation

ProblemsI Usually d >> 1, m, l ∈ N ’smaller’

I Expensive evaluation of f

I .. or both!

Solution attempts

The base idea / starting point of our research adapts to thework [4], ’Analog macromodeling’ of Philips et al.

I Reduction to Subspace V with dim(V ) = r << d

I Kernel expansion of f

I .. or both!

5 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Reduction methodsShort introduction: Kernels

Sidestep: Kernels

What is a kernel?

Φ : Ω× Ω→ R for some Ω ⊂ Rd

Most important properties (’can be’)

I Positive definite: ∀ x1, . . . , xN ⊂ Ω disjoint anda ∈ RN\0:

N∑i=1

N∑j=1

aiajΦ(xi , xj) > 0

I Symmetric:

Φ(x , y) = Φ(y , x) ∀ x , y ∈ Ω

Large theory, for definitions and examples see [6, 6.24]. 6 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Reduction methodsf approximation

So where are kernels used? Search an f with f ≈ f !

Kernel expansion

f (x(t), t, µ) =N∑

i=1

αiΦ1(x(t), xi )Φ2(t, ti )Φ3(µ, µi )

for ’snapshots’ (xi , ti , µi ) and coefficient vectorsαi ∈ Rd , i = 1 . . .N.

Coefficient computation

I Least squares

I Kernel interpolation (see [6] for example)

I SVR (see [5] for example)

I . . .

7 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Reduction methodsSubspace projection

Another well-known technique:

Subspace reduction

I Compute/select a matrix V ∈ Rd×r

I Select biorthogonal W ∈ Rd×r with W tV = IrI Solve (1) in subspace

Projected System

z ′(t) = W t f (Vz(t), t, µ) + W tB(t, µ)uk(t) (4)

z(0) = W tx0(µ) (5)

y(t) = C (t, µ)Vz(t), (6)

now with z(t) ∈ Rr , r << d .

8 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Software requirementsOffline-Online decomposition

General practice: Split computations in two phases!

OfflineI Parameter sampling

I Snapshot / trajectory computation

I Large matrix multiplications

I Approximation computation

I . . .

OnlineI Simulation (fast)

I Error estimation (cheap)

For examples and practices see [2] or [3]

9 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Software requirementsHigh level functionalities

High level end-user functions

Tasks for any given dynamical system:

I Simulation

I Visualization of results

I Analysis of reduced simulations

I Offline generations

I Storage of models and data

I . . .

10 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Software requirementsMedium level functionalities

Intermediate level system-dependent functions

Tasks that are general but may vary for specific systems:

I System component evaluations

I Component structure (affine-linear etc.)

I Core function component-wise approximation

I Error estimator computation

I Kernel properties or kernel combination

I . . .

11 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Software requirementsDetail level functionalities

Highly system-dependent settings

Strategies that are specific to each model or are eveninfluenced by model constraints (e.g. size)

I Parameter Sampling

I Approximation computation (SVR, LS, . . .)

I Subspace computation (SVD, Krylov, . . .)

I Snapshot generation

I Kernel choice

I . . .

12 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Software DesignSoftware Engineering

Engineering point of view

I Try to design software that reflects this hierarchy

I Maintainability

I Extensibility

I Solution: OOP programming

13 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Software DesignKerMOR uses MatlabTM OOP features

OOP features in KerMOR

Many above mentioned criterias are met using OOP inKerMOR:

I Packages

I Classes & (multiple) Inheritance

I Properties

I Abstract methods

I Interfaces

I . . .

14 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

InheritanceInherit structure ..

Core OOP features: Inheritance

Figure: Inheritance examples from KerMOR

Special MatlabTM feature: Multiple inheritance

15 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Design patternsTemplate Method

Example design pattern 1: Template Method

classdef BaseClass

methods

function res = someBaseFun(this , in)

% Do some work

a = in;

...

% Call template method

b = templateMethod(this , a);

...

% some more work

res = a+b;

end

end

methods(Abstract , Access=protected)

% Define template method signature

b = templateMethod(this , a);

end

end

16 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Design patternsTemplate Method

Example design pattern 1: Template Method

classdef SubClass < BaseClass

% SubClass inherits from BaseClass

methods

function b = templateMethod(this , a)

% Implementation of template method ,

% used as subpart in BaseClass

...

% Some work here ...

...

b = someresult;

end

end

end

Control over subclassing!

17 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Design patternsStrategy

Example design pattern 2: Strategy

classdef IPlugin

methods(Abstract)

% Declare interface method

res = myBehaviour(this , in);

end

end

classdef PluginClassA < IPlugin

methods

function res = myBehaviour(this , in)

% Class A implementation

[... some strategy A here ...]

end

end

end

classdef PluginClassB < IPlugin

methods

function res = myBehaviour(this , in)

% Class B implementation

[... some strategy B here ...]

end

end

end

18 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Design patternsStrategy

Example design pattern 2: Strategy

classdef SomeClass

properties

% Define property

Plugin;

end

methods

function res = someMethod(this , in)

% Do some stuff

...

% Call template method

res = this.Plugin.myBehaviour(in);

...

% some more local stuff

res = res * 5;

end

end

end

Encapsulate behaviour! More about Design Patterns in [1] 19 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Approximation generationApplication of template method

classdef BaseCompWiseKernelApprox ...

< approx.BaseKernelApprox

methods

function gen_approximation_data(this , xi, ti, mui , fxi)

...

K = this.evaluateKernel(xi, ti, mui);

% Call template method 1

this.prepareApproximationGeneration(K);

...

for fdim = 1: fdims

% Call template method 2

[ai , b, svidx] = ...

this.calcComponentApproximation(fxi(fdim ,:));

if ~isempty(svidx)

this.Ma(fdim ,svidx) = ai;

else

this.Ma(fdim ,:) = ai;

end

this.off(fdim) = b;

end

...

end

end

methods(Abstract , Access=protected)

% Preparation template method.

prepareApproximationGeneration(this , K);

% Single dimension approximation computation.

[ai , b, svidx] = calcComponentApproximation(this , fxi);

end

end

20 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Approximation generationApplication of template method

classdef BaseCompWiseKernelApprox ...

< approx.BaseKernelApprox

[...]

methods(Abstract , Access=protected)

% Preparation template method.

prepareApproximationGeneration(this , K);

% Single dimension approximation computation.

[ai , b, svidx] = ...

calcComponentApproximation(this , fxi);

end

end

BenefitsI Clear interface for approximation task

I Force structure for kernel representation

I prepare.. function allows custom initialization

21 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

System decompositionSeparation of dynamical systems into subparts

Splitting using the representation from the start

I f (x(t), t, µ) 7−→ dscomponents.ICoreFun

I B(t, µ) 7−→ dscomponents.IInputConv

I C (t, µ) 7−→ dscomponents.IOutputConv

I uk(t), x0(µ) 7−→@functionPointer

Application of the Strategy pattern

The reduced system may have f instead of f ! Solution:

classdef ICoreFun < dscomponents.IProjectable

%ICOREFUN Basic interface for all

% dynamical system ’s core functions

methods(Abstract)

% Evaluates the core function

y = evaluate(x,t,mu);

end

end

22 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Application of the Strategy patternApproximations implement ICoreFun

classdef BaseApprox < dscomponents.ICoreFun ...

& ICloneable

methods

function fx = evaluate(this , x, t, mu)

% Evaluates the f-approximation.

% Depending on projection settings this wraps

% the template methods results or not.

if this.CustomProjection || isempty(this.V) || ...

isempty(this.W)

fx = this.evaluate_approximation(x, t, mu);

else

fx = this.W’*this.evaluate_approximation (...

this.V*x, t, mu);

end

end

end

end

In each case this.f.evaluate(x,t,mu); is sufficient!

23 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

KernelsMore applied design patterns

Composite Pattern

I Strategy pattern for different kernels (Linear,Polynomial, Gaussian, . . .)

I Kernels can be combined to new kernel

I Combined Kernel is Kernel itself

classdef BaseKernel < handle

%BASEKERNEL Basic KerMor Kernel

properties(SetAccess=protected)

% Flag whether this kernel is rotation -invariant.

RotationInvariant = false;

end

methods(Abstract)

% Evaluation method for the current kernel.

K = evaluate(x,y);

...

end

end24 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

KernelsComposite Pattern

classdef LinearKernel < kernels.BaseKernel

%LINEARKERNEL The simple scalar -product kernel.

methods

function this = LinearKernel

this.RotationInvariant = true;

end

function K = evaluate(this , x, y)

if nargin == 2

y = x;

end

K = x’*y;

end

end

end

classdef CombinationKernel < kernels.BaseKernel

properties

% The combination operation for each kernel.

CombOp = @(a,b)a+b;

end

...25 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

KernelsComposite Pattern II

...

properties(Access=private)

Kernels = ;

Weights = [];

end

methods

function K = evaluate(this , x, varargin)

if isempty(this.Kernels)

error(’No Kernels here to combine.’);

end

K = this.Weights (1) * ...

this.Kernels 1. evaluate(x,varargin :);

for n = 2: length(this.Kernels)

K = this.CombOp(K, this.Weights(n) * ...

this.Kernelsn. evaluate(x,varargin :));

end

end

function this = addKernel(this , kernel , weight)

...

end

end

end 26 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

More strategy applicationsIn- and Output conversion

Strategy for In- and Outputs

Figure: Strategy pattern examples

27 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Outlook

Future WorkI More approximation strategies

I More subspace generation methods

I Data Storage: possibly extension to hard drives forstorage of large data

I Event system notifications about progress etc

I ... and much more!

Thank you!

28 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

DiscussionOwn experiences - Remarks - Comments

Our recent open questions / wishes

I Caching of large variables in Filesystem?

I clone()-method for handle-classes!

I Default-initializations with new instances (flag?)

I Autocompletion of inherited functions

I Any feedback to MatlabTM from customers aboutOOP?

I Any speed loss through try...catch?

Discussion

I Own experiences with OOP in MatlabTM ?

I What could be the benefits / drawbacks?

29 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Referenzen I

Elisabeth Freeman, Eric Freeman, Bert Bates, andKathy Sierra.Head First Design Patterns.O’ Reilly & Associates, Inc., 2004.

B. Haasdonk and M. Ohlberger.Efficient reduced models for parametrized dynamicalsystems by offline/online decomposition.In Proc. MATHMOD 2009, 6th Vienna InternationalConference on Mathematical Modelling, 2009.

30 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Referenzen II

A.T. Patera and G. Rozza.Reduced Basis Approximation and a Posteriori ErrorEstimation for Parametrized Partial DifferentialEquations.MIT, 2007.Version 1.0, Copyright MIT 2006-2007, to appear in(tentative rubric) MIT Pappalardo GraduateMonographs in Mechanical Engineering.

J. Phillips, J. Afonso, A. Oliveira, and L.M. Silveira.Analog macromodeling using kernel methods.In Proc. of ICCAD-2003, International Conference onVolume Computer Aided Design, volume Nov 2003,pages 446– 453, 2003.

31 / 32

MatlabTM AG

22.02.2010

Intro

DynamicalSystems

Math. concepts

Reduction methods

Softwarerequirements

Offline/Online

High level

Medium level

Detail level

Software Design

OOP

Inheritance

Design patterns

Application inKerMOR

Approximationgeneration

System decomposition

Kernels

DS components

Outlook

Referenzen III

B. Scholkopf and J. A. Smola.Learning with Kernels.Adaptive Computation adn Machine Learning. The MITPress, 2002.

Holger Wendland.Scattered data approximation, volume 17 of CambridgeMonographs on Applied and ComputationalMathematics.Cambridge University Press, 2005.

32 / 32