Example #1
0
from d3s.tools import printVector, printMatrix

#%% load variables from mat file into main scope
data = sp.io.loadmat('data/lorenz.mat', squeeze_me=True)
for s in data.keys():
    if s[:2] == '__' and s[-2:] == '__': continue
    exec('%s = data["%s"]' % (s, s))

#%% apply SINDy
d = X.shape[0]
p = 2 # maximum order of monomials

psi = observables.monomials(p)
Xi1 = algorithms.sindy(X, Y, psi, iterations=1)

c = observables.allMonomialPowers(d, p)
n = c.shape[1] # number of functions

#%% output results
printMatrix(c)
printMatrix(Xi1)

#%% apply gEDMD
K, _, _ = algorithms.gedmd(X, Y, None, psi)

# construct projection onto full-state observable
B = np.zeros((10, d))
for i in range(3):
    B[i+1, i] = 1
Xi2 = (K@B).T
printMatrix(Xi2)
Example #2
0

def b(x):
    return np.array([gamma * x[0, :], delta * (x[1, :] - x[0, :]**2)])


# define observables
psi = observables.monomials(8)

# generate data
X = Omega.rand(1000)  # generate test points
Y = b(X)

# apply generator EDMD
evs = 8  # number of eigenvalues/eigenfunctions to be computed
K, d, V = algorithms.gedmd(X, Y, None, psi, evs=evs, operator='K')
# printMatrix(K, 'K_gEDMD')
printVector(np.real(d), 'd_gEDMD')

V[:, 1] /= V[3, 1]
V[:, 3] /= V[10, 3]
V[:, 4] /= V[6, 4]  # normalize eigenvectors for convenience
for i in range(evs):
    psi.display(np.real(V[:, i]), 2, 'phi_%d' % (i + 1))
print('')

# system identification
B = np.zeros((K.shape[0], Omega.dimension()))
B[1, 0] = 1
B[2, 1] = 1