コード例 #1
0
ファイル: 2.py プロジェクト: keiikegami/AS4
def GH(m):
    points = h_roots(m)[0]
    weights = h_roots(m)[1]
    return sum([
        weights[i] * np.exp(points[i]**2) * norm.pdf(points[i])
        for i in range(len(points))
    ])
コード例 #2
0
iter_count = 0
# k_coefs = np.array([3.60014515, 0.02656186, 1.91000997, -0.27549642, 5.0906649, -0.29205494, -0.21088586, -2.11306702, -0.01295193, 0.252112])

k_coefs = np.array([
    -2.52223679e-02, 3.14325706e-02, 5.01033193e-02, -4.21653511e-02,
    -1.37994882e-01, -1.44272604e-02, -1.19342985e-02, -6.03401537e-02,
    1.00500937e-01, 1.16229754e-01, -1.39680351e-01, -2.56880900e-01,
    -1.89408316e-01, -1.05148594e-01, 2.54676148e-01, 1.59784452e-01,
    -2.99204643e-01, -7.61316149e-03, -8.17626449e-02, 3.98571631e-01,
    -9.45282186e-02, 2.46187662e-01, 1.10811578e-01, -8.35159959e-02,
    -1.86926213e-01, -8.80258593e-02, 8.52046144e-02, -1.71162032e-04
])
k_coefs_old = k_coefs

n_quadrature_nodes = 5
points, weights = h_roots(n_quadrature_nodes)
weights = weights / np.sqrt(np.pi)


# @jit(cache = True, nopython = True)
def integrationnodes(znow, lambda_zeta, nodes):
    # return np.outer(znow ** lambda_zeta, nodes ** sigma_rho).flatten(order = 'F')
    return np.outer(znow**lambda_zeta, nodes**sigma_rho).T.flatten()


# @jit(cache = True)
def k_function(k, z, k_coefs):
    k_poly = _vander_nd_flat(
        (hermevander, hermevander), [k.reshape(
            (-1, 1)), z.reshape((-1, 1))], [degree, degree]) @ k_coefs
    output_length = k_poly.shape[0]
コード例 #3
0
        return mpf(0)
    if n == 0:
        return mpf(math.pow(math.pi, (-1 / 4)))
    return mpf(x * math.sqrt(2 / n) * hermite(n - 1, x) -
               math.sqrt((n - 1) / n) * hermite(n - 2, x))


# weighting function for Hermite polynomials
def w(x):
    return mpf(math.pow(math.e, (-x * x)))


# Step 0. Setting up the DVR gridpoints and weights

print "Finding the roots of Hermite polynomials (and associated weights)"
xVals, wVals = h_roots(n, False)
print "Complete"
xmax = xVals[-1]
xmin = xVals[0]
print "xmin, ", xmin * xscale, " xmax, ", xmax * xscale
print "Evaluating the Hermite polynomials @ roots of the n'th order one"
# Evaluate H0 and H1 on a grid and use forward recursion with the value of the functions at those points.
HermsAtRoots = np.zeros(
    (n, n)) * mpf(1.0)  # initialize an arbitrary precision array
for a in range(n):
    HermsAtRoots[a, 0] = hermite(0, xVals[a])
    HermsAtRoots[a, 1] = hermite(1, xVals[a])
i = 2
while i < n:
    for a in range(n):
        HermsAtRoots[a, i] = mpf(
コード例 #4
0
ファイル: 2.py プロジェクト: keiikegami/AS4
def GH_weights(m):
    points = h_roots(m)[0]
    weights = h_roots(m)[1]
    return [weights[i] * np.exp(points[i]**2) for i in range(len(points))]
コード例 #5
0
ファイル: 2.py プロジェクト: keiikegami/AS4

def GH(m):
    points = h_roots(m)[0]
    weights = h_roots(m)[1]
    return sum([
        weights[i] * np.exp(points[i]**2) * norm.pdf(points[i])
        for i in range(len(points))
    ])


def GH_weights(m):
    points = h_roots(m)[0]
    weights = h_roots(m)[1]
    return [weights[i] * np.exp(points[i]**2) for i in range(len(points))]


a = [5, 10, 20, 30]

# approximation result
for m in a:
    print(GH(m))

# weights
for m in a:
    print(GH_weights(m))

# points
for m in a:
    print(h_roots(m)[0])