In [1]:
%load_ext Cython
In [12]:
import vegas
import math
from functools import partial
def f(x, ct=0.5):
dx2 = 0.0
for d in range(4):
dx2 += (x[d] - ct) ** 2
return math.exp(- dx2 * 100.) * 1000.
def main():
integ = vegas.Integrator([[-1, 1], [0, 1], [0, 1], [0,1]])
intg = partial(f, ct=0.6)
integ(intg, nitn=10, neval=2000)
result = integ(intg, nitn=10, neval=2000)
# print(result.summary())
In [13]:
%timeit -n3 -r3 main()
In [ ]:
from scipy import integrate
def ff(x0, x1, x2, x3, ct=0.5):
xx = [x0, x1, x2, x3]
dx2 = 0.0
for x in xx:
dx2 += (x - ct) ** 2
return math.exp(- dx2 * 100.) * 1000.
integrate.nquad(ff, [[-1, 1],[0, 1], [0, 1], [0, 1]], full_output=True)
Scipy.integrate is extremely slow and memory-cost in this example. Maybe it's because I don't know how to use this method correctly.