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


Python integrate.romberg函数代码示例

本文整理汇总了Python中scipy.integrate.romberg函数的典型用法代码示例。如果您正苦于以下问题:Python romberg函数的具体用法?Python romberg怎么用?Python romberg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了romberg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _initialize_defaults

    def _initialize_defaults(self):
        if self._w0 != -1.0 or self._wa != 0.0:
            a_array = numpy.logspace(
                -16, 0,
                defaults.default_precision["cosmo_npoints"])
            self._de_presure_array = self._de_presure(1/a_array - 1.0)
            self._de_presure_spline = InterpolatedUnivariateSpline(
                numpy.log(a_array), self._de_presure_array)

        self._chi = integrate.romberg(
            self.E, 0.0, self._redshift, vec_func=True,
            tol=defaults.default_precision["cosmo_precision"])

        self.growth_norm = integrate.romberg(
            self._growth_integrand, 1e-16, 1.0, vec_func=True,
            tol=defaults.default_precision["cosmo_precision"])
        self.growth_norm *= 2.5*self._omega_m0*numpy.sqrt(self.E0(0.0))

        a = 1.0/(1.0 + self._redshift)
        growth = integrate.romberg(
            self._growth_integrand, 1e-16, a, vec_func=True,
            tol=defaults.default_precision["cosmo_precision"])
        growth *= 2.5*self._omega_m0*numpy.sqrt(self.E0(self._redshift))
        self._growth = growth/self.growth_norm

        self._sigma_norm = 1.0
        self._sigma_norm = self._sigma_8*self._growth/self.sigma_r(8.0)
开发者ID:ajmendez,项目名称:stomp,代码行数:27,代码来源:cosmology.py

示例2: raw_window_function

    def raw_window_function(self, chi):
        a = 1.0/(1.0 + self.cosmo.redshift(chi))

        try:
            g_chi = numpy.empty(len(chi))
            for idx,value in enumerate(chi):
                chi_bound = value
                if chi_bound < self._g_chi_min: chi_bound = self._g_chi_min

                g_chi[idx] = integrate.romberg(
                    self._lensing_integrand, chi_bound,
                    self.chi_max, args=(value,), vec_func=True,
                    tol=defaults.default_precision["window_precision"])
        except TypeError:
            chi_bound = chi
            if chi_bound < self._g_chi_min: chi_bound = self._g_chi_min

            g_chi = integrate.romberg(
                self._lensing_integrand, chi_bound,
                self.chi_max, args=(chi,), vec_func=True,
                tol=defaults.default_precision["window_precision"])

        g_chi *= self.cosmo.H0*self.cosmo.H0*chi

        return 3.0/2.0*self.cosmo._omega_m0*g_chi/a
开发者ID:ajmendez,项目名称:stomp,代码行数:25,代码来源:kernel.py

示例3: _normalize

    def _normalize(self):
        self.f_norm = 1.0
        norm = integrate.romberg(
            self.f_nu, self.nu_min, self.nu_max, vec_func=True,
            tol=defaults.default_precision["global_precision"],
            rtol=defaults.default_precision["mass_precision"],
            divmax=defaults.default_precision["divmax"])
        self.f_norm = 1.0/norm

        self.bias_norm = 1.0
        norm = integrate.romberg(
            lambda x: self.f_nu(x)*self.bias_nu(x),
            self.nu_min, self.nu_max, vec_func=True,
            tol=defaults.default_precision["global_precision"],
            rtol=defaults.default_precision["mass_precision"],
            divmax=defaults.default_precision["divmax"])
        self.bias_norm = 1.0/norm
        
        self.bias_2_norm = 0.0
        norm = integrate.romberg(
            lambda x: self.f_nu(x)*self.bias_2_nu(x),
            self.nu_min, self.nu_max, vec_func=True,
            tol=defaults.default_precision["global_precision"],
            rtol=defaults.default_precision["mass_precision"],
            divmax=defaults.default_precision["divmax"])
        self.bias_2_norm = -norm
开发者ID:karenyyng,项目名称:chomp,代码行数:26,代码来源:mass_function.py

示例4: _initialize_pp_gm

    def _initialize_pp_gm(self):
        pp_gm_cent_array = numpy.zeros_like(self._ln_k_array)

        for idx in xrange(self._ln_k_array.size):
            pp_gm_cent = integrate.romberg(
                self._pp_gm_integrand, numpy.log(self.mass.nu_min),
                numpy.log(self.mass.nu_max), vec_func=True,
                tol=defaults.default_precision["halo_precision"],
                args=(self._ln_k_array[idx], "central_first_moment"))
            pp_gm_cent_array[idx] = pp_gm_cent/self.n_bar

        self._pp_gm_cent_spline = InterpolatedUnivariateSpline(
            self._ln_k_array, pp_gm_cent_array)

        pp_gm_sat_array = numpy.zeros_like(self._ln_k_array)

        for idx in xrange(self._ln_k_array.size):
            pp_gm_sat = integrate.romberg(
                self._pp_gm_integrand, numpy.log(self.mass.nu_min),
                numpy.log(self.mass.nu_max), vec_func=True,
                tol=defaults.default_precision["halo_precision"],
                args=(self._ln_k_array[idx], "satellite_first_moment"))
            pp_gm_sat_array[idx] = pp_gm_sat/self.n_bar

        self._pp_gm_sat_spline = InterpolatedUnivariateSpline(
            self._ln_k_array, pp_gm_sat_array)

        self._initialized_pp_gm = True
开发者ID:ajmendez,项目名称:stomp,代码行数:28,代码来源:halo.py

示例5: complex_integral

def complex_integral(func,a,b,args,intype='stupid'):
    real_func = lambda z: np.real(func(z,*args))
    imag_func = lambda z: np.imag(func(z,*args))
    if intype == 'quad':
        real_int = integ.quad(real_func,a,b)
        imag_int = integ.quad(imag_func,a,b)
#        print(real_int)
#        print(imag_int)
        return real_int[0] + 1j * imag_int[0]
    elif intype == 'quadrature':
        real_int = integ.quadrature(real_func,a,b)
        imag_int = integ.quadrature(imag_func,a,b)
#        print(real_int)
#        print(imag_int)
        return real_int[0] + 1j * imag_int[0]
    elif intype == 'romberg':
        real_int = integ.romberg(real_func,a,b)
        imag_int = integ.romberg(imag_func,a,b)
#        print(real_int)
#        print(imag_int)
        return real_int + 1j * imag_int
    elif intype == 'stupid':
        Npoints = 500
        z,dz = np.linspace(a,b,Npoints,retstep=True)
        real_int = np.sum(real_func(z))*dz
        imag_int = np.sum(imag_func(z))*dz
#        print(real_int)
#        print(imag_int)
        return real_int + 1j*imag_int
开发者ID:qLuxor,项目名称:sagnac,代码行数:29,代码来源:Benn_Kolo.py

示例6: raw_correlation

    def raw_correlation(self, r):
        """
        Compute the value of the correlation at array values r

        Args:
            r: float array of position values in Mpc/h
        """
        try:
            xi_out = numpy.empty(len(r))
            for idx, value in enumerate(r):
                xi_out[idx] = integrate.romberg(
                    self._correlation_integrand,
                    self._ln_k_min, self._ln_k_max, args=(value,),
                    vec_func=True,
                    tol=defaults.default_precision["global_precision"],
                    rtol=defaults.default_precision["corr_precision"],
                    divmax=defaults.default_precision["divmax"])
        except TypeError:
            xi_out = integrate.romberg(
                    self._correlation_integrand,
                    self._ln_k_min, self._ln_k_max, args=(r,), vec_func=True,
                    tol=defaults.default_precision["global_precision"],
                    rtol=defaults.default_precision["corr_precision"],
                    divmax=defaults.default_precision["divmax"])
        return xi_out
开发者ID:karenyyng,项目名称:chomp,代码行数:25,代码来源:correlation.py

示例7: dirichlet_integrate

def dirichlet_integrate(alpha):
    normalizer = exp(sum(gammaln(alpha)) - gammaln(sum(alpha)))

    def f_recur(x, idx, upper, vals):
        if idx == 1:
            # base case.
            # set values for last two components
            vals[1] = x
            vals[0] = 1.0 - sum(vals[1:])
            # compute Dirichlet value
            print(vals.T, prod(vals ** (alpha - 1)) , normalizer, alpha)
            return prod(vals.T ** (alpha - 1)) / normalizer
        else:
            vals[idx] = x
            split = alpha[idx-1] / sum(alpha)
            if (split < upper - x):
                return romberg(f_recur, 0, split, args=(idx - 1, upper - x, vals), vec_func=False) + \
                    romberg(f_recur, split, upper - x, args=(idx - 1, upper - x, vals), vec_func=False)
            else:
                return romberg(f_recur, 0, upper - x, args=(idx - 1, upper - x, vals), vec_func=False)

    split = alpha[-1] / sum(alpha)
    print(alpha / sum(alpha))
    return romberg(f_recur, 0, split, args=(len(alpha) - 1, 1.0, zeros((len(alpha), 1), float64)), vec_func=False) + \
        romberg(f_recur, split, 1, args=(len(alpha) - 1, 1.0, zeros((len(alpha), 1), float64)), vec_func=False) 
开发者ID:CellProfiler,项目名称:CellProfiler-Analyst,代码行数:25,代码来源:dirichletintegrate.py

示例8: __call__

	def __call__(self,Phi_Mz,p_Mz,par):
		#
		integrand = lambda M,z: Phi_Mz(M,z,par) * p_Mz(M,z) * self.dVdzdO(z)
		inner = lambda z: romberg(integrand,*self.Mrange,args=(z,),
		                          **self.int_kwargs)
		outer = romberg(inner,*self.zrange,**self.int_kwargs)
		return outer
开发者ID:imcgreer,项目名称:QLFz4,代码行数:7,代码来源:qlffit.py

示例9: correlation

    def correlation(self, l):
        """
        Compute the value of the correlation at array values theta

        Args:
            theta: float array of angular values in radians to compute the
                correlation
        """
        try:
            power = numpy.empty(len(l))
            for idx, value in enumerate(l):
                power[idx] = integrate.romberg(
                    self._correlation_integrand, 
                    self.kernel.chi_min, self.kernel.chi_max, args=(value,), 
                    vec_func=True,
                    tol=defaults.default_precision["global_precision"],
                    rtol=defaults.default_precision["corr_precision"],
                    divmax=defaults.default_precision["divmax"])
        except TypeError:
            power = integrate.romberg(
                self._correlation_integrand, 
                self.kernel.chi_min, self.kernel.chi_max, args=(l,), vec_func=True,
                tol=defaults.default_precision["global_precision"],
                rtol=defaults.default_precision["corr_precision"],
                divmax=defaults.default_precision["divmax"])
        return power
开发者ID:karenyyng,项目名称:chomp,代码行数:26,代码来源:correlation.py

示例10: synphot

    def synphot (self, wlen, flam):
        """`wlen` and `flam` give a tabulated model spectrum in wavelength and f_λ
        units. We interpolate linearly over both the model and the bandpass
        since they're both discretely sampled.

        Note that quadratic interpolation is both much slower and can blow up
        fatally in some cases. The latter issue might have to do with really large
        X values that aren't zero-centered, maybe?

        I used to use the quadrature integrator, but Romberg doesn't issue
        complaints the way quadrature did. I should probably acquire some idea
        about what's going on under the hood.

        """
        from scipy.interpolate import interp1d
        from scipy.integrate import romberg

        d = self._ensure_data ()

        mflam = interp1d (wlen, flam,
                          kind='linear',
                          bounds_error=False, fill_value=0)

        mresp = interp1d (d.wlen, d.resp,
                          kind='linear',
                          bounds_error=False, fill_value=0)

        bmin = d.wlen.min ()
        bmax = d.wlen.max ()

        numer = romberg (lambda x: mresp (x) * mflam (x),
                         bmin, bmax, divmax=20)
        denom = romberg (lambda x: mresp (x),
                         bmin, bmax, divmax=20)
        return numer / denom
开发者ID:dkhikhlukha,项目名称:pwkit,代码行数:35,代码来源:synphot.py

示例11: ri

 def ri(u):
     ''' Epälineaarisen osan integrointi Gaussin kaavalla '''
     J = h/2 # Jakobiaani
     I = lambda k: N(k)*np.cos(np.sum(N(k)*u))*J # Integrandi
     I0 = lambda k: I(k)[0]
     I1 = lambda k: I(k)[1]
     #return 2.0*I(0.0)
     #return quad(I,-1,1)[0]
     return np.array([romberg(I0,-1,1),romberg(I1,-1,1)])
开发者ID:adesam01,项目名称:FEMTools,代码行数:9,代码来源:diffis2.py

示例12: romberg_slit_1d

def romberg_slit_1d(q, width, height, form, pars):
    """
    Romberg integration for slit resolution.

    This is an adaptive integration technique.  It is called with settings
    that make it slow to evaluate but give it good accuracy.
    """
    from scipy.integrate import romberg, dblquad

    if any(k not in form.info['defaults'] for k in pars.keys()):
        keys = set(form.info['defaults'].keys())
        extra = set(pars.keys()) - keys
        raise ValueError("bad parameters: [%s] not in [%s]"%
                         (", ".join(sorted(extra)), ", ".join(sorted(keys))))

    if np.isscalar(width):
        width = [width]*len(q)
    if np.isscalar(height):
        height = [height]*len(q)
    _int_w = lambda w, qi: eval_form(sqrt(qi**2 + w**2), form, pars)
    _int_h = lambda h, qi: eval_form(abs(qi+h), form, pars)
    # If both width and height are defined, then it is too slow to use dblquad.
    # Instead use trapz on a fixed grid, interpolated into the I(Q) for
    # the extended Q range.
    #_int_wh = lambda w, h, qi: eval_form(sqrt((qi+h)**2 + w**2), form, pars)
    q_calc = slit_extend_q(q, np.asarray(width), np.asarray(height))
    Iq = eval_form(q_calc, form, pars)
    result = np.empty(len(q))
    for i, (qi, w, h) in enumerate(zip(q, width, height)):
        if h == 0.:
            r = romberg(_int_w, 0, w, args=(qi,),
                        divmax=100, vec_func=True, tol=0, rtol=1e-8)
            result[i] = r/w
        elif w == 0.:
            r = romberg(_int_h, -h, h, args=(qi,),
                        divmax=100, vec_func=True, tol=0, rtol=1e-8)
            result[i] = r/(2*h)
        else:
            w_grid = np.linspace(0, w, 21)[None,:]
            h_grid = np.linspace(-h, h, 23)[:,None]
            u = sqrt((qi+h_grid)**2 + w_grid**2)
            Iu = np.interp(u, q_calc, Iq)
            #print np.trapz(Iu, w_grid, axis=1)
            Is = np.trapz(np.trapz(Iu, w_grid, axis=1), h_grid[:,0])
            result[i] = Is / (2*h*w)
            """
            r, err = dblquad(_int_wh, -h, h, lambda h: 0., lambda h: w,
                             args=(qi,))
            result[i] = r/(w*2*h)
            """

    # r should be [float, ...], but it is [array([float]), array([float]),...]
    return result
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:53,代码来源:resolution.py

示例13: __massEjected

    def __massEjected(self, m_min):
        """
        Return the mass integration of the mass ejected by the collapse of the
        star
        """
        if(self.imfType == "S"):
            return self.__massEjectedSalpeter(m_min)

        else:
            mEject = (romberg(self.__mPhi, m_min, self.__amsup1, tol=1.48e-04)
                 - romberg(self.__mrPhi, m_min, self.__amsup1, tol=1.48e-04)
                      )
        return mEject
开发者ID:duducosmos,项目名称:pycosmicstar,代码行数:13,代码来源:cosmicstarformation.py

示例14: dL2

def dL2(z,h):
    c=3.e5
    H0=100.*h
    if type(z) == ndarray:
	n=len(z)
	DL=zeros(n,'d')
	for i in range(n):
	    s=romberg(func,0.,z[i])#,tol=1.e-6)
	    DL[i]=c/H0*(1+z[i])*s #(Mpc/h)
    else:
	s=romberg(func,0.,z)#,tol=1.e-6)
	DL=c/H0*(1+z)*s #(Mpc/h)
    return DL
开发者ID:rfinn,项目名称:Virgo,代码行数:13,代码来源:astrofuncs.py

示例15: dL

def dL(z,h):
    c=3.e5
    H0=100.*h

    try:#multiple objects
	n=len(z)
	DL=zeros(n,'d')
	for i in range(n):
	    s=romberg(func,0.,z[i])#,tol=1.e-6)
	    DL[i]=c/H0*(1+z[i])*s #(Mpc/h)
    except TypeError:
	s=romberg(func,0.,z)#,tol=1.e-6)
	DL=c/H0*(1+z)*s #(Mpc/h)
    return DL
开发者ID:rfinn,项目名称:Virgo,代码行数:14,代码来源:astrofuncs.py


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