Zero value when computing an integral in 4-dimensions using quasi-Monte Carlo quadrature

38 views Asked by At

Calculate the value of the integral using the _nquad method. The value is 2.9613231498508394e-18 but the solution takes a long time. qmc_quad can be used for acceleration, but the value remains 0. Where could there be a mistake? Or am I doing something wrong?

import numpy as np
from scipy import integrate
import datetime

start = datetime.datetime.now()

XX = [None, 11.3, 14.8, 7.6, 10.5, 12.7, 3.9, 11.2, 5.4, 8.5, 5.0, 4.4, 7.3, 2.9, 5.7, 6.2, 7.3, 3.3, 4.2, 5.5, 4.2]
number_i = [None, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
N = 20


def F(M1, Mn, S1, Sn, i, n, x):
    M = (M1 * (n - i) / (n - 1)) + (Mn * (i - 1) / (n - 1))
    S = (S1 * (n - i) / (n - 1)) + (Sn * (i - 1) / (n - 1))
    y = (x - M) / S
    f = np.exp(-0.5 * y * y) / np.sqrt(2 * np.pi)
    pdf = f / S
    return pdf


def G(args):
    M1, Mn, S1, Sn = args
    # unpacked values x and i
    x = XX[1:]
    i = number_i[1:]
    # Calculate the value of the function F for each x and i
    values = [F(M1, Mn, S1, Sn, i_val, 20, x_val) for i_val, x_val in zip(i, x)]
    result = np.prod(values)
    return result


# limits of integration for M1,Mn,S1,Sn a=lower, b=upper
a = (-100, -100, 0.0001, 0.0001)
b = (100, 100, 100, 100)

K, _ = integrate.qmc_quad(G, a, b, n_estimates=4, n_points=204800)

print(K)
print(datetime.datetime.now() - start)
# result module nquad
# K = (2.9613231498508394e-18, 9.999964969225108e-21)
# result module qmc_quad
# K = (0, 0)
0

There are 0 answers