import matplotlib.pyplot as plt from matplotlib import rc import matplotlib.path as path from hermite_poly import Hermite, Poly from models_and_functions import simulate, VAC, well_well, makegrid, fcn_weighting, L2subspaceProj_d, OU, dot from mpl_toolkits import mplot3d from basis_sets import indicator from numpy import exp, arange from pylab import meshgrid, cm, imshow, contour, clabel, colorbar, axis, title, show import tables as tb dimension = 1 fineness = 10 endpoint = 2.5 basis = [ indicator(fineness, endpoint, center=i).to_fcn() for i in makegrid(endpoint, dimension=dimension, n=fineness) ] basis = [Hermite(0).to_fcn()] basis = basis + [ Hermite(n, d).to_fcn() for n in range(1, fineness) for d in range(dimension) ] basisSize = len(basis) delta_t = .01 T = 1000 n = 160 length = round(T / delta_t) print("Now opening trajectory data.") h5 = tb.open_file( "Trajectory_Data/OU_1D_delta_t={},T={},n={}.h5".format(delta_t, T, n), 'r')
from scipy.special import hermite from scipy.linalg import eigh import numpy as np import matplotlib.pyplot as plt import matplotlib.path as path from hermite_poly import Hermite from simple_models import simulate, VAC, well_well, makegrid, fcn_weighting, L2subspaceProj_d from mpl_toolkits import mplot3d from basis_sets import indicator from numpy import exp, arange from pylab import meshgrid, cm, imshow, contour, clabel, colorbar, axis, title, show m = 3 basis_H = [Hermite(n) for n in range(m)] basis_I = [ indicator(fineness=5, endpoint=1, center=i) for i in makegrid(endpoint=1, n=5) ] x = simulate([0, 0], .1, 100) # x.set_seed(5) y = x.normal() Y = VAC(basis_H, y, 1) ev_y_H = Y.find_eigen(3) z = x.potential(well_well) Z = VAC(basis_H, z, 1) ev_z_H = Z.find_eigen(3) Y = VAC(basis_I, y, 1)
H_fcns_y = [fcn_weighting(basis_H, v) for v in ev_y_H[1].T][::-1] t = np.linspace(-1.7, 1.7, 100) k = [h(z) for h in H_fcns_y] plt.plot(z, k[0], "-m", label="First, H") plt.plot(z, k[1], "-c", label="Second, H") plt.plot(z, k[2], "-k", label="Third, H") plt.legend(loc=8, prop={'size': 7}) plt.title("Estimated eigenfcns with indicator and Hermite bases") plt.show() m = 10 basis_I_20 = [ indicator(fineness=m, endpoint=2, center=i) for i in makegrid(endpoint=2, n=m) ] basis_I_40 = [ indicator(fineness=2 * m, endpoint=2, center=i) for i in makegrid(endpoint=2, n=2 * m) ] basis_I_80 = [ indicator(fineness=4 * m, endpoint=2, center=i) for i in makegrid(endpoint=2, n=4 * m) ] Z_20 = VAC(basis_I_20, z, 1) Z_40 = VAC(basis_I_40, z, 1) Z_80 = VAC(basis_I_80, z, 1)
delta_t = .001 T = 1000 n = 10 length = round(T / delta_t) h5 = tb.open_file("Trajectory_Data/DW_1D_delta_t=.001,T=1000,n=10.h5", 'r') a = h5.root.data t = np.array([a[3,round(length * .05):round(length * .3)]]) print("Now getting eigenvalues.") Phi_f = np.array([f(distribution) for f in basis_true]) evs = [] error = [] for l in fineness: basis = [indicator(l, endpoint, center = i).to_fcn() for i in makegrid(endpoint, dimension = 1, n = l)] ev = VAC(basis, t, time_lag, delta_t).find_eigen(4) evs.append(ev) Phi_g = np.array([f(distribution) for f in basis]) error.append(L2subspaceProj_d(w_f = w_f[2:], w_g = ev[1].T[2:][::-1], distribution = distribution, Phi_f = Phi_f, Phi_g = Phi_g)) print("Now calculating error.") plt.plot(fineness, error) plt.xlabel("Number of basis functions") plt.ylabel("Error in estimated subspaces") plt.title("Error in estimation with varying basis size (Double Well, 1D)") print([i for i in range(len(error)) if error[i] == min(error)])