本文整理汇总了Python中scipy.integrate.dblquad方法的典型用法代码示例。如果您正苦于以下问题:Python integrate.dblquad方法的具体用法?Python integrate.dblquad怎么用?Python integrate.dblquad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.integrate
的用法示例。
在下文中一共展示了integrate.dblquad方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bivariate_approximate_ground_truth_integral
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def bivariate_approximate_ground_truth_integral(func, integral_bounds: List[Tuple[float, float]]):
"""
Estimate the 2D ground truth integral
:param func: bivariate function
:param integral_bounds: bounds of integral
:returns: integral estimate, output of scipy.integrate.dblquad
"""
def func_dblquad(x, y):
z = np.array([x, y])
z = np.reshape(z, [1, 2])
return func(z)
lower_bound_x = integral_bounds[0][0]
upper_bound_x = integral_bounds[0][1]
lower_bound_y = integral_bounds[1][0]
upper_bound_y = integral_bounds[1][1]
return dblquad(func=func_dblquad, a=lower_bound_x, b=upper_bound_x, gfun=lambda x: lower_bound_y,
hfun=lambda x: upper_bound_y)
示例2: precise_chern
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def precise_chern(h,dk=0.01, mode="Wilson",delta=0.0001,operator=None):
""" Calculates the chern number of a 2d system """
from scipy import integrate
err = {"epsabs" : 1.0, "epsrel": 1.0,"limit" : 10}
# err = [err,err]
def f(x,y): # function to integrate
if mode=="Wilson":
return berry_curvature(h,np.array([x,y]),dk=dk)
if mode=="Green":
f2 = h.get_gk_gen(delta=delta) # get generator
return berry_green(f2,k=[x,y,0.],operator=operator)
c = integrate.dblquad(f,0.,1.,lambda x : 0., lambda x: 1.,epsabs=0.01,
epsrel=0.01)
chern = c[0]/(2.*np.pi)
open("CHERN.OUT","w").write(str(chern)+"\n")
return chern
示例3: discretize_integrate_2D
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def discretize_integrate_2D(model, x_range, y_range):
"""
Discretize model by integrating the model over the pixel.
"""
from scipy.integrate import dblquad
# Set up grid
x = np.arange(x_range[0] - 0.5, x_range[1] + 0.5)
y = np.arange(y_range[0] - 0.5, y_range[1] + 0.5)
values = np.empty((y.size - 1, x.size - 1))
# Integrate over all pixels
for i in range(x.size - 1):
for j in range(y.size - 1):
values[j, i] = dblquad(lambda y, x: model(x, y), x[i], x[i + 1],
lambda x: y[j], lambda x: y[j + 1])[0]
return values
示例4: mutual_information
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def mutual_information(self):
def mi_integrand(x, y):
return np.exp(self.logpdf_xy(x,y)) * \
(self.logpdf_xy(x,y) - self.logpdf_x(x) - self.logpdf_y(y))
return dblquad(
lambda y, x: mi_integrand(x,y), self.D[0], self.D[1],
self._lower_y, self._upper_y)
示例5: _sanity_test
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def _sanity_test(self):
# Marginal of x integrates to one.
print quad(lambda x: np.exp(self.logpdf_x(x)), self.D[0], self.D[1])
# Marginal of y integrates to one.
print quad(lambda y: np.exp(self.logpdf_y(y)), -1 ,1)
# Joint of x,y integrates to one; quadrature will fail for small noise.
print dblquad(
lambda y,x: np.exp(self.logpdf_xy(x,y)), self.D[0], self.D[1],
lambda x: -1, lambda x: 1)
示例6: expect
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def expect(self, func=lambda x: 1, lower=(-10,-10), upper=(10,10)):
def fun(x, y):
x = np.column_stack((x,y))
return func(x) * self.pdf(x)
from scipy.integrate import dblquad
return dblquad(fun, lower[0], upper[0], lambda y: lower[1],
lambda y: upper[1])
示例7: kl
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def kl(self, other):
'''Kullback-Leibler divergence between this and another distribution
int f(x) (log f(x) - log g(x)) dx
where f is the pdf of self, and g is the pdf of other
uses double integration with scipy.integrate.dblquad
limits currently hardcoded
'''
fun = lambda x : self.logpdf(x) - other.logpdf(x)
return self.expect(fun)
示例8: quad2d
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def quad2d(func=lambda x: 1, lower=(-10,-10), upper=(10,10)):
def fun(x, y):
x = np.column_stack((x,y))
return func(x)
from scipy.integrate import dblquad
return dblquad(fun, lower[0], upper[0], lambda y: lower[1],
lambda y: upper[1])
示例9: test_double_integral
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def test_double_integral(self):
# 8) Double Integral test
def simpfunc(y,x): # Note order of arguments.
return x+y
a, b = 1.0, 2.0
assert_quad(dblquad(simpfunc,a,b,lambda x: x, lambda x: 2*x),
5/6.0 * (b**3.0-a**3.0))
示例10: test_matching_dblquad
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def test_matching_dblquad(self):
def func2d(x0, x1):
return x0**2 + x1**3 - x0 * x1 + 1
res, reserr = dblquad(func2d, -2, 2, lambda x:-3, lambda x:3)
res2, reserr2 = nquad(func2d, [[-3, 3], (-2, 2)])
assert_almost_equal(res, res2)
assert_almost_equal(reserr, reserr2)
示例11: test_double_integral
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def test_double_integral(self):
# 8) Double Integral test
def simpfunc(y, x): # Note order of arguments.
return x+y
a, b = 1.0, 2.0
assert_quad(dblquad(simpfunc, a, b, lambda x: x, lambda x: 2*x),
5/6.0 * (b**3.0-a**3.0))
示例12: test_double_integral2
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def test_double_integral2(self):
def func(x0, x1, t0, t1):
return x0 + x1 + t0 + t1
g = lambda x: x
h = lambda x: 2 * x
args = 1, 2
assert_quad(dblquad(func, 1, 2, g, h, args=args),35./6 + 9*.5)
示例13: test_double_integral3
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def test_double_integral3(self):
def func(x0, x1):
return x0 + x1 + 1 + 2
assert_quad(dblquad(func, 1, 2, 1, 2),6.)
示例14: test_matching_dblquad
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def test_matching_dblquad(self):
def func2d(x0, x1):
return x0**2 + x1**3 - x0 * x1 + 1
res, reserr = dblquad(func2d, -2, 2, lambda x: -3, lambda x: 3)
res2, reserr2 = nquad(func2d, [[-3, 3], (-2, 2)])
assert_almost_equal(res, res2)
assert_almost_equal(reserr, reserr2)
示例15: bivariateTCdf
# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import dblquad [as 别名]
def bivariateTCdf(yy,xx,rho,nu):
t_ans, err = nInt.dblquad(bivariateTDensity, -10, xx,
lambda x: -10,
lambda x: yy,args=(rho,nu))
return t_ans