def galerkin_approx(coordinates, joint, expansion_small, norms_small):
    alpha, beta = chaospy.variable(2)

    e_alpha_phi = chaospy.E(alpha*expansion_small, joint)
    initial_condition = e_alpha_phi/norms_small

    phi_phi = chaospy.outer(expansion_small, expansion_small)
    e_beta_phi_phi = chaospy.E(beta*phi_phi, joint)

    def right_hand_side(c, t):
        return -numpy.sum(c*e_beta_phi_phi, -1)/norms_small

    coefficients = odeint(
        func=right_hand_side,
        y0=initial_condition,
        t=coordinates,
    )
    return chaospy.sum(expansion_small*coefficients, -1)
# <d/dx sum(c*P),P[k]> = <-a*sum(c*P), P[k]>
# d/dx c[k]*<P[k],P[k]> = -sum(c*<a*P,P[k]>)
# d/dx c = -E( outer(a*P,P) ) / E( P*P )
#
# u(0) = I
# <sum(c(0)*P), P[k]> = <I, P[k]>
# c[k](0) <P[k],P[k]> = <I, P[k]>
# c(0) = E( I*P ) / E( P*P )
order = 5
P, norm = cp.orth_ttr(order, dist, retall=True, normed=True)

# support structures
q0, q1 = cp.variable(2)
P_nk = cp.outer(P, P)
E_ank = cp.E(q0*P_nk, dist)
E_ik = cp.E(q1*P, dist)
sE_ank = cp.sum(E_ank, 0)

# Right hand side of the ODE
def f(c_k, x):
    return -cp.sum(c_k*E_ank, -1)/norm

solver = odespy.RK4(f)
c_0 = E_ik/norm
solver.set_initial_condition(c_0)
c_n, x = solver.solve(x)
U_hat = cp.sum(P*c_n, -1)

mean = cp.E(U_hat, dist)
var = cp.Var(U_hat, dist)
def f(c_k, x):
    return -cp.sum(c_k*E_ank, -1)/norm
Example #4
0
def test_orth_chol():
    dist = cp.Normal(0, 1)
    orth1 = cp.orth_ttr(5, dist, normed=True)
    orth2 = cp.orth_chol(5, dist, normed=True)
    eps = cp.sum((orth1-orth2)**2)
    assert np.allclose(eps(np.linspace(-100, 100, 5)), 0)
Example #5
0
def test_orth_chol():
    dist = cp.Normal(0, 1)
    orth1 = cp.orth_ttr(5, dist, normed=True)
    orth2 = cp.orth_chol(5, dist, normed=True)
    eps = cp.sum((orth1-orth2)**2)
    assert np.allclose(eps(np.linspace(-100, 100, 5)), 0)
def f(c_k, x):
    return -cp.sum(c_k * E_ank, -1) / norm
# d/dx c[k]*<P[k],P[k]> = -sum(c*<a*P,P[k]>)
# d/dx c = -E( outer(a*P,P) ) / E( P*P )
#
# u(0) = I
# <sum(c(0)*P), P[k]> = <I, P[k]>
# c[k](0) <P[k],P[k]> = <I, P[k]>
# c(0) = E( I*P ) / E( P*P )
order = 5
P, norm = cp.orth_ttr(order, dist, retall=True, normed=True)

# support structures
q0, q1 = cp.variable(2)
P_nk = cp.outer(P, P)
E_ank = cp.E(q0 * P_nk, dist)
E_ik = cp.E(q1 * P, dist)
sE_ank = cp.sum(E_ank, 0)


# Right hand side of the ODE
def f(c_k, x):
    return -cp.sum(c_k * E_ank, -1) / norm


solver = odespy.RK4(f)
c_0 = E_ik / norm
solver.set_initial_condition(c_0)
c_n, x = solver.solve(x)
U_hat = cp.sum(P * c_n, -1)

mean = cp.E(U_hat, dist)
var = cp.Var(U_hat, dist)
def lagrange_approximation(evaluations, expansion):
    return chaospy.sum(evaluations.T * expansion, axis=-1).T