コード例 #1
0
    for j in range(m):
        G_10[i, j] = c0(X[:, i]) * k(X[:, i], X[:, j]) + np.sum(
            c2(X[:, i]) * k.ddiff(X[:, i], X[:, j]), axis=(0, 1))

A, _, _, _ = np.linalg.lstsq(G_00, G_10, rcond=1e-12)
d, V = algorithms.sortEig(A, evs=evs, which='SR')

c = Omega.midpointGrid()
W = kernels.gramian2(c, X, k) @ V

#%% plot spectrum
plt.figure()
plt.plot(np.real(d), '.')
plt.title('Spectrum')

printVector(np.real(d), 'd')

#%% plot eigenfunctions
for i in range(evs):
    plt.figure()
    j = evs - i - 1
    Omega.plot(np.real(W[:, j] / np.amax(abs(W[:, j]))))

    wa = psi[i](c)
    wa = wa / np.amax(abs(wa))
    plt.plot(c.T, wa.T)

    plt.title('lambda = %f' % np.real(d[i]))

#%% Poeschl-Teller potential as SDE ---------------------------------------------------------------
コード例 #2
0
ファイル: kgedmdTest.py プロジェクト: sklus/d3s
X = Omega.rand(500)
Y = b(X)
Z = sigma(X)
m = X.shape[1]

#%% apply kernel generator EDMD
G_00, G_10 = gaussianG00G10(X, b, sigma, k)

epsilon = 0
A = sp.linalg.pinv(G_00 + epsilon * np.eye(m), rcond=1e-15) @ G_10
# A, _, _, _ = np.linalg.lstsq(G_00, G_10, rcond=1e-12)
d, V = algorithms.sortEig(A, evs=m, which='SM')
W = kernels.gramian2(Omega.midpointGrid(), X, k) @ V

#%% plot eigenvalues
printVector(np.real(d[:10]), 'd')
plt.figure()
plt.plot(np.real(d), '.')

#%% plot eigenfunctions
ind, = np.where(d < -0.001)
for i in ind[:5]:
    plt.figure()
    plt.clf()
    #plt.scatter(X[0, :], X[1, :], c=V[:, i])
    Omega.plot(np.real(W[:, i]), '3D')
    plt.title('%f' % d[i])

#%% Quantum harmonic oscillator -------------------------------------------------------------------

#%% define domain
コード例 #3
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

b_c = K @ B  # coefficients of the identified system
psi.display(np.real(b_c[:, 0]), 2, 'b_1')