当前位置: 首页>>代码示例>>Python>>正文


Python integrate.dblquad方法代码示例

本文整理汇总了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) 
开发者ID:amzn,项目名称:emukit,代码行数:23,代码来源:baselines.py

示例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 
开发者ID:joselado,项目名称:quantum-honeycomp,代码行数:18,代码来源:topology.py

示例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 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:utils.py

示例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) 
开发者ID:probcomp,项目名称:cgpm,代码行数:9,代码来源:sin.py

示例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) 
开发者ID:probcomp,项目名称:cgpm,代码行数:13,代码来源:sin.py

示例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]) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:mv_normal.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:16,代码来源:mv_normal.py

示例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]) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:mv_normal.py

示例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)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_quadpack.py

示例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) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_quadpack.py

示例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)) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:10,代码来源:test_quadpack.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_quadpack.py

示例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.) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:6,代码来源:test_quadpack.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:10,代码来源:test_quadpack.py

示例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 
开发者ID:djbolder,项目名称:credit-risk-modelling,代码行数:7,代码来源:thresholdModels.py


注:本文中的scipy.integrate.dblquad方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。