samedi 18 octobre 2014

Scipy Integrate Function which takes two functions as arguments that depend on the same variable


Vote count:

0




I want to numerically integrate the following function:


Function to Integrate


I know the function values of f over a grid called grid_y and grid_posterior. To evaluate the entire function, I use linear interpolation as follows:



Af = lambda x: scipy.interpolate.interpn(tuple([grid_y,grid_posterior]),f,x)


The function G(y,z) is written as:



lambda z: y**alpha * np.exp(mu) * z.


H(y,\mu,z) is called:



updated_posterior = lambda z: ( posterior**np.exp(-np.log(z)/sigma**2/
( np.sqrt(2*np.pi)*sigma*y*np.exp(mu)*z ) ).


To evaluate the integral, I create the function:



integrand = lambda z: Af( np.array([y**alpha * np.exp(mu[0]) * z,
updated_posterior(z)])) * phi.pdf(z)


and then pass this function to the scipy.integrate.fixed_quad module:



fixed_quad(integrand, a, b)


My procedure unfortunately results in an error. The fixed_quad function returns the following text:



*** ValueError: The requested sample points xi have dimension 5, but this
RegularGridInterpolator has dimension 2


Does somebody know the source of the error or has a better suggestion in how to evaluate the integral?



asked 36 secs ago







Scipy Integrate Function which takes two functions as arguments that depend on the same variable

Aucun commentaire:

Enregistrer un commentaire