# Dynamic Mode Decomposition

The (Exact) Dynamic Mode Decomposition is a method for generating an approximating linear differential equation directly from the observed data. If X and Y are data matrices containing points of the same trajectory, than DMD approximates

$K = Y~X^{\dagger}$

where $\dagger$ denotes the Moore-Penrose pseudoinverse and K is the approximation of the Koopman Operator.

DMD approximates discrete time systems of the form

$u_{i+1} = K ~ u_{i}$

gDMD approximates continuous time systems of the form

$\frac{d}{dt}u = K_{G} ~ u$

where $K_{G}$ is the generator of the Koopman Operator.

## Functions

DataDrivenDiffEq.DMDFunction
DMD(X; alg)
DMD(X, Y; alg)

Approximates a 'LinearKoopman' with the AbstractKoopmanAlgorithm 'alg' from the data matrices X or X and Y, respectively. If only X is given, the data is split into X[:, 1:end-1] and X[:, 2:end].

Example

alg = DMDPINV()
koopman = DMD(X, alg = alg)

koopman = DMD(X[:, 1:end-1], X[:, 2:end], alg = alg)
source
DataDrivenDiffEq.gDMDFunction
gDMD(X, Y; alg)
gDMD(t, X ; dt, alg, fdm, itp)

Approximates a 'LinearKoopman' with the AbstractKoopmanAlgorithm 'alg' from the data matrices X and Y. X should contain the state trajectory and Y the differential state trajectory.

If no measurements of the differential state are available, gDMD can be called with measurement time points t as the first argument. It will then create an interpolation using the interpolation method from DataInterpolations.jl defined in itp. The trajectory will then be resampled to equidistant measurements over time corresponding to the mean of diff(t) or dt, if given. The differential state measurements will be computed via 'FiniteDifferences.jl', given a FiniteDifferenceMethod in fdm.

Example

koopman = gDMD(X, Y)

fdm = backward_fdm(5,1)
itp = CubicSpline
koopman = gDMD(t, X, fdm = fdm, itp = itp)
source

## Examples

using DataDrivenDiffEq
using OrdinaryDiffEq
using LinearAlgebra
using Plots
gr()

function linear_discrete(du, u, p, t)
du[1] = 0.9u[1]
du[2] = 0.05u[2] + 0.1u[1]
end

u0 = [10.0; -2.0]
tspan = (0.0, 20.0)
problem = DiscreteProblem(linear_discrete, u0, tspan)
solution = solve(problem, FunctionMap())
X = Array(solution)

approx = DMD(X[:,1:3])

prob_approx = DiscreteProblem(approx, u0, tspan)
approx_sol = solve(prob_approx, FunctionMap())

plot(approx_sol, label = ["u[1]" "u[2]"]) #hide
plot!(solution, label = ["True u[1]" "True u[2]"]) #hide
savefig("dmd_example_1.png") #hide


function linear_discrete_2(du, u, p, t)
du[1] = 0.9u[1] + 0.05u[2]
du[2] = 0.1u[1]
end

problem = DiscreteProblem(linear_discrete_2, u0, tspan)
solution = solve(problem, FunctionMap())

X = Array(solution)

update!(approx, X[:, 4:end-1], X[:, 5:end])

prob_approx = DiscreteProblem(approx, u0, tspan)
approx_sol = solve(prob_approx, FunctionMap())

# Show solutions
plot(approx_sol, label = ["u[1]" "u[2]"]) #hide
plot!(solution, label = ["True u[1]" "True u[2]"]) #hide
savefig("dmd_example_2.png") #hide