var = np.load('../UU_sig.npy')[:290] ell = np.load('../UU_ell.npy')[:290] [x_quad, w] = ct.util.QuadratureRule('CC').get_rule(5, 6) y_quad = np.load('../data_pressure_CC_quadrature_lev6.npy')[:, -1] #coeffs = ct.chaos.PolyChaos().comp_coeffs(x_quad, y_quad, w, 9) l2_err = np.zeros((6, 8)) for i in range(l2_err.shape[0]): for j in range(l2_err.shape[1]): Q = 2 + j X_i = X[:50 * i + 40, :].copy() Y_i = Y[:50 * i + 40, :].copy() rbf = kp.RBF(X.shape[1], var[50 * i + 20], ell[50 * i + 20]) I = IntegralPosterior(X_i, Y_i, Q, rbf) [m, C] = I.predict('L') pol = ct.chaos.PolyBasis(5, Q, 'L') P = pol(x_quad) y_pred = np.dot(P, m) diff = (y_quad - y_pred)**2 l2_err[i, j] = np.abs(np.sum(diff * w)) / np.sum(y_quad**2 * w) print 'order :' + str(j) print i y_axis = [50 * i for i in range(6)] x_axis = [2, 3, 4, 5, 6, 7, 8, 9] np.save('./images/l2_err.npy', l2_err)
import scipy.stats as st import sys sys.path.insert(0, '../') from GP_integral import * import kernel_py as kp import chaos_toolbox as ct import matplotlib.pyplot as plt X = np.load('X.npy') Y = np.load('Y.npy') Q = 5 var = np.load('sig_smooth.npy')[-1] ell = np.load('ell_smooth.npy')[-2] rbf = kp.RBF(X.shape[1], var, ell) I = IntegralPosterior(X, Y, Q, rbf) [m, C] = I.predict('L') #v_all = I.v_all('L') #print v_all #np.save('coeffs/v_all.npy', v_all) print m plt.plot(m) plt.show() pol = ct.chaos.PolyBasis(2, Q, 'L') xi = st.norm.rvs(size=(1000, 2)) P = pol(xi) y = np.dot(P, m)
for i in range(XI.shape[0]): print 'Taking initial sample : ' + str(i) u = np.zeros((ny, nx)) v = np.zeros((ny, nx)) p = np.zeros((ny, nx)) b = np.zeros((ny, nx)) xi = 0.5 * (XI[i, :].copy() + 1.) xi[-1] = 0.04 * xi[-1] + 0.01 u, v, p = cavity_flow(nt, u, v, dt, dx, dy, p, rho, xi) YI[i, 0] = p[-2, -1] print YI kern = kp.RBF(dim, 1, 1) gp = kp.GP(XI, YI, kern) N_quad = 300 gp.optimize() sig = np.zeros(N_quad + 1) sig_noise = np.zeros(N_quad + 1) ell = np.zeros(N_quad + 1) sig[0] = gp._kern._var sig_noise[0] = gp._noise_var ell[0] = gp._kern._lengthscale[0] kern._var = sig[0] kern._lengthscale = [ell[0]] * dim
return y X = 2 * st.uniform.rvs(size=(4, 2)) - 1. Y = np.zeros((X.shape[0], 1)) N = 1000 T = 10. for i in range(X.shape[0]): y0 = np.zeros(3) y0[0] = 1. y0[1] = 0.1 * X[i, 0] y0[2] = X[i, 1] Y[i, 0] = RK4(y0, T, N)[1, -1] # + 0.1 * np.random.normal(size = (3,1)) kern = kp.RBF(2, 1, 1) ker = gpy.kern.RBF(2, 1, 1) m = gpy.models.GPRegression(X, Y, ker) gp = kp.GP(X, Y, kern) #x = np.linspace(-4., 4., 100).reshape(100,1) x = np.linspace(-1, 1., 50) y = np.linspace(-1, 1., 50) xx, yy = np.meshgrid(x, y) X_test = np.hstack( [xx.flatten().reshape(2500, 1), yy.flatten().reshape(2500, 1)]) f, var = gp.predict(X_test)