lebedov / scikit-cuda

Python interface to GPU-powered libraries
http://scikit-cuda.readthedocs.org/
Other
975 stars 179 forks source link

Integrate modied gaussian defined integral #304

Open jaimecoj opened 4 years ago

jaimecoj commented 4 years ago

The integral is like this:

formula

I was thinking of using quad but is not supported. However, non-accelerated quad is very slow and I'm in need of optimice my script.

Do you know if this can be done by another scipy.integrate method by collection samples? If so, in which points would I need to collect samples?

I can accept a small error of 0.001 or less

lebedov commented 4 years ago

Are t1, d1, t2, d2 fixed parameters? If so, scipy.integrate.quad() seems to run pretty rapidly for the following example:

import functools

import numpy as np
import scipy.integrate as integrate
import scipy.special as sp

def modified_gaussian(x, t1, d1, t2, d2):
    sqrt2 = np.sqrt(2)
    return (np.exp(-x**2/2)*(0.5*sp.erf((t1-x)/(sqrt2*np.sqrt(d1**2+5.12)))*+0.5)*\
        (0.5*sp.erf((t2-x)/(sqrt2*np.sqrt(d2**2+5.12)))+0.5))/(sqrt2*np.pi)

t1 = 1
d1 = 1
t2 = 1
d2 = 1
f = functools.partial(modified_gaussian, t1=t1, d1=d1, t2=t2, d2=d2)
print(integrate.quad(f, -np.inf, np.inf))