def cov(X0, Y, theta): A = theta.sig_alpha * np.dot( np.array(X0)[:, :-3], np.array(X0)[:, :-3].T) B = theta.sig_beta * np.diag(np.ones(len(X0))) C = theta.sig_zeta D = mk52(np.array(X0)[:, -3:-1], [theta.l1, theta.l2], theta.sig_m) Kx = A + B + C + D L = np.array([ np.array([ theta.rho[str(sorted([i, j]))] if i >= j else 0.0 for j in range(theta.n_IS) ]) for i in range(theta.n_IS) ]) # Normalize L to stop over-scaling values small if theta.normalize_L: L = L / np.linalg.norm(L) # Force it to be positive semi-definite Ks = L.dot(L.T) if theta.normalize_Ks: Ks = Ks / np.linalg.norm(Ks) e = np.diag(np.array([theta.e1, theta.e2])) Ks = e.dot(Ks.dot(e)) return np.kron(Ks, Kx)
def cov(X, Y, theta): A = theta.sig_alpha * np.dot(np.array(X)[:, 1:-3], np.array(X)[:, 1:-3].T) B = theta.sig_beta * np.diag(np.ones(len(X))) C = theta.sig_zeta D = mk52(np.array(X)[:, -3:-1], [theta.l1, theta.l2], theta.sig_m) return A + B + C + D
def cov_old2(X, Y, theta): A = theta.sig_alpha * np.dot( np.array(X)[:, 1:-3], np.array(X)[:, 1:-3].T) B = theta.sig_beta * np.diag(np.ones(len(X))) C = theta.sig_zeta D = mk52(np.array(X)[:, -3:-1], [theta.l1, theta.l2], theta.sig_m) return theta.rho_matrix(X, use_psd=True) * (A + B + C + D)
def cov_new(X, Y, theta): # Get a list of all unique X, removing initial IS identifier X0 = [] for x in X: if not any( [all([a == b for a, b in zip(x[1:], xchk)]) for xchk in X0]): X0.append(x[1:]) A = theta.sig_alpha * np.dot( np.array(X0)[:, :-3], np.array(X0)[:, :-3].T) B = theta.sig_beta * np.diag(np.ones(len(X0))) C = theta.sig_zeta D = mk52(np.array(X0)[:, -3:-1], [theta.l1, theta.l2], theta.sig_m) Kx = A + B + C + D L = np.array([ np.array([ theta.rho[str(sorted([i, j]))] if i >= j else 0.0 for j in range(theta.n_IS) ]) for i in range(theta.n_IS) ]) # Normalize L to stop over-scaling values small L = L / np.linalg.norm(L) # Force it to be positive semi-definite Ks = L.dot(L.T) return np.kron(Ks, Kx) #K = np.kron(Ks, Kx) # Now, we get the sub-covariance matrix for the specified sampled X and Y indices = [] for l in range(theta.n_IS): for i, x in enumerate(X0): test = [l] + list(x) if any( [all([a == b for a, b in zip(test, xchk)]) for xchk in X]): indices.append(l * len(X0) + i) K_local = K[np.ix_(indices, indices)] return K_local
def cov(X0, Y, theta): A = theta.sig_alpha * np.dot( np.array(X0)[:, :-3], np.array(X0)[:, :-3].T) B = theta.sig_beta * np.diag(np.ones(len(X0))) C = theta.sig_zeta D = mk52(np.array(X0)[:, -3:-1], [theta.l1, theta.l2], theta.sig_m) Kx = A + B + C + D Ks = np.array([ np.array( [theta.rho[str(sorted([i, j]))] for j in range(theta.n_IS)]) for i in range(theta.n_IS) ]) if theta.normalize_Ks: Ks = Ks / np.linalg.norm(Ks) e = np.diag(np.array([theta.e1, theta.e2])) Ks = e.dot(Ks.dot(e)) return np.kron(Ks, Kx)
def cov(X0, Y, theta): A = theta.sig_alpha * np.dot( np.array(X0)[:, :-3], np.array(X0)[:, :-3].T) B = theta.sig_beta * np.diag(np.ones(len(X0))) C = theta.sig_zeta D = mk52(np.array(X0)[:, -3:-1], [theta.l1, theta.l2], theta.sig_m) Kx = A + B + C + D if unitary is not None: Ks = np.array([[1.0, unitary], [unitary, 1.0]]) else: L = np.array([ np.array([ theta.rho[str(sorted([i, j]))] if i >= j else 0.0 for j in range(theta.n_IS) ]) for i in range(theta.n_IS) ]) # Force it to be positive semi-definite Ks = L.dot(L.T) e = np.diag(np.array([theta.e1, theta.e2])) Ks = e.dot(Ks.dot(e)) return np.kron(Ks, Kx)