當前位置: 首頁>>代碼示例>>Python>>正文


Python math.gamma方法代碼示例

本文整理匯總了Python中math.gamma方法的典型用法代碼示例。如果您正苦於以下問題:Python math.gamma方法的具體用法?Python math.gamma怎麽用?Python math.gamma使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在math的用法示例。


在下文中一共展示了math.gamma方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: expected_rs

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def expected_rs(n):
  """
  Calculates the expected (R/S)_n for white noise for a given n.

  This is used as a correction factor in the function hurst_rs. It uses the
  formula of Anis-Lloyd-Peters (see [h_3]_).

  Args:
    n (int):
      the value of n for which the expected (R/S)_n should be calculated

  Returns:
    float:
      expected (R/S)_n for white noise
  """
  front = (n - 0.5) / n
  i = np.arange(1,n)
  back = np.sum(np.sqrt((n - i) / i))
  if n <= 340:
    middle = math.gamma((n-1) * 0.5) / math.sqrt(math.pi) / math.gamma(n * 0.5)
  else:
    middle = 1.0 / math.sqrt(n * math.pi * 0.5)
  return front * middle * back 
開發者ID:CSchoel,項目名稱:nolds,代碼行數:25,代碼來源:measures.py

示例2: AR_1_Coeff

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def AR_1_Coeff(data):
        """
        The autocovariance coefficient called as rho, for an AR(1) model can be calculated as shown here:

        .. math::

            \\rho(1) = \\frac{\\gamma(1)}{\\gamma(0)}

        For further information look for example in "Zeitreihenanalyse", pages 17, by Matti Schneider, Sebastian Mentemeier,
        SS 2010.

        :param data: numerical list
        :type data: list
        :return: autocorrelation coefficient
        :rtype: float
        """
        return TimeSeries.acf(data, 1) / TimeSeries.acf(data, 0) 
開發者ID:thouska,項目名稱:spotpy,代碼行數:19,代碼來源:likelihoods.py

示例3: integrate

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def integrate(self, f, dot=numpy.dot):
        flt = numpy.vectorize(float)
        ref_vol = enr_volume(self.dim)
        return ref_vol * dot(f(flt(self.points).T), flt(self.weights))


# The closed formula is
#
#   2
#   * math.factorial(sum(alpha) + n - 1)
#   * prod([math.gamma((k + 1) / 2.0) for k in alpha])
#   / math.gamma((sum(alpha) + n) / 2).
#
# Care must be taken when evaluating this expression as numerator or denominator will
# quickly overflow. A better representation is via a recurrence. This is numerically
# stable and can easily be used for symbolic computation. 
開發者ID:nschloe,項目名稱:quadpy,代碼行數:18,代碼來源:_helpers.py

示例4: integrate_monomial_over_enr

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def integrate_monomial_over_enr(k, symbolic=False):
    n = len(k)
    if any(a % 2 == 1 for a in k):
        return 0
    if all(a == 0 for a in k):
        return enr_volume(n, symbolic)

    # find first nonzero
    idx = next(i for i, j in enumerate(k) if j > 0)
    alpha = (k[idx] - 1) * (sum(k) + n - 1)
    k2 = k.copy()
    k2[idx] -= 2
    return integrate_monomial_over_enr(k2, symbolic) * alpha


# 2 * sqrt(pi) ** n * gamma(n) / gamma(frac(n, 2)) 
開發者ID:nschloe,項目名稱:quadpy,代碼行數:18,代碼來源:_helpers.py

示例5: test_integrate

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def test_integrate():
    moments = quadpy.tools.integrate(lambda x: [x ** k for k in range(5)], -1, +1)
    assert (moments == [2, 0, sympy.S(2) / 3, 0, sympy.S(2) / 5]).all()

    moments = quadpy.tools.integrate(
        lambda x: orthopy.line_segment.tree_legendre(x, 4, "monic", symbolic=True),
        -1,
        +1,
    )
    assert (moments == [2, 0, 0, 0, 0]).all()

    # Example from Gautschi's "How to and how not to" article
    moments = quadpy.tools.integrate(
        lambda x: [x ** k * sympy.exp(-(x ** 3) / 3) for k in range(5)], 0, sympy.oo
    )
    S = numpy.vectorize(sympy.S)
    gamma = numpy.vectorize(sympy.gamma)
    n = numpy.arange(5)
    reference = 3 ** (S(n - 2) / 3) * gamma(S(n + 1) / 3)
    assert numpy.all([sympy.simplify(m - r) == 0 for m, r in zip(moments, reference)]) 
開發者ID:nschloe,項目名稱:quadpy,代碼行數:22,代碼來源:test_tools.py

示例6: _read_out_params

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def _read_out_params(self, kwargs_mass, kwargs_light, kwargs_anisotropy):
        """
        reads the relevant parameters out of the keyword arguments and transforms them to the conventions used in this
        class

        :param kwargs_mass: mass profile keyword arguments
        :param kwargs_light: light profile keyword arguments
        :param kwargs_anisotropy: anisotropy keyword arguments
        :return: a (Rs of Hernquist profile), gamma, rho0_r0_gamma, r_ani
        """
        if 'a' not in kwargs_light:
            kwargs_light['a'] = 0.551 * kwargs_light['r_eff']
        if 'rho0_r0_gamma' not in kwargs_mass:
            kwargs_mass['rho0_r0_gamma'] = self._rho0_r0_gamma(kwargs_mass['theta_E'], kwargs_mass['gamma'])
        a = kwargs_light['a']
        gamma = kwargs_mass['gamma']
        rho0_r0_gamma = kwargs_mass['rho0_r0_gamma']
        r_ani = kwargs_anisotropy['r_ani']
        return a, gamma, rho0_r0_gamma, r_ani 
開發者ID:sibirrer,項目名稱:lenstronomy,代碼行數:21,代碼來源:analytic_kinematics.py

示例7: _sigma_r2_interp

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def _sigma_r2_interp(self, r, a, gamma, rho0_r0_gamma, r_ani):
        """

        :param r:
        :param a:
        :param gamma:
        :param rho0_r0_gamma:
        :param r_ani:
        :return:
        """
        if not hasattr(self, '_interp_sigma_r2'):
            min_log = np.log10(self._min_integrate)
            max_log = np.log10(self._max_integrate)
            r_array = np.logspace(min_log, max_log, self._interp_grid_num)
            I_R_sigma2_array = []
            for r_i in r_array:
                I_R_sigma2_array.append(self._sigma_r2(r_i, a, gamma, rho0_r0_gamma, r_ani))
            self._interp_sigma_r2 = interp1d(np.log(r_array), np.array(I_R_sigma2_array), fill_value="extrapolate")
        return self._interp_sigma_r2(np.log(r)) 
開發者ID:sibirrer,項目名稱:lenstronomy,代碼行數:21,代碼來源:analytic_kinematics.py

示例8: mvt_pdf

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def mvt_pdf(X, phi, K, nu):
    """
    Multivariate student-t density:
    output:
        the density of the given element
    input:
        x = parameter (d dimensional numpy array or scalar)
        mu = mean (d dimensional numpy array or scalar)
        K = scale matrix (dxd numpy array)
        nu = degrees of freedom
    """
    d = X.shape[-1]
    num = math.gamma((d + nu) / 2.) * pow(
        1. + (1. / (nu - 2)) * ((X - phi).dot(np.linalg.inv(K)).dot(np.transpose(X - phi))), -(d + nu) / 2.)
    denom = math.gamma(nu / 2.) * pow((nu - 2) * math.pi, d / 2.) * pow(np.linalg.det(K), 0.5)
    return num / denom 
開發者ID:IraKorshunova,項目名稱:bruno,代碼行數:18,代碼來源:utils_stats.py

示例9: crPlusMultifactor

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def crPlusMultifactor(N,M,wMat,p,c,aVec,alpha,rId):
    K = len(aVec)
    S = np.zeros([M,K])
    for k in range(0,K):        
        S[:,k] = np.random.gamma(aVec[k], 1/aVec[k], [M]) 
    W = wMat[rId,:]
    # Could replace tile with np.kron(W[:,0],np.ones([1,M])), but it's slow
    wS =  np.tile(W[:,0],[M,1]) + np.dot(S,np.transpose(W[:,1:]))
    pS = np.tile(p,[M,1])*wS
    H = np.random.poisson(pS,[M,N])
    lossIndicator = 1*np.greater_equal(H,1)
    lossDistribution = np.sort(np.dot(lossIndicator,c),axis=None)
    el,ul,var,es=util.computeRiskMeasures(M,lossDistribution,alpha)
    return el,ul,var,es          
      
# -----------------------
# Miscellaneous functions
# ----------------------- 
開發者ID:djbolder,項目名稱:credit-risk-modelling,代碼行數:20,代碼來源:mixtureModels.py

示例10: _levy_flight__

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def _levy_flight__(self, epoch, solution, prey):
        beta = 1
        # muy and v are two random variables which follow normal distribution
        # sigma_muy : standard deviation of muy
        sigma_muy = np.power(gamma(1 + beta) * np.sin(np.pi * beta / 2) / (gamma((1 + beta) / 2) * beta * np.power(2, (beta - 1) / 2)), 1 / beta)
        # sigma_v : standard deviation of v
        sigma_v = 1
        muy = np.random.normal(0, sigma_muy)
        v = np.random.normal(0, sigma_v)
        s = muy / np.power(np.abs(v), 1 / beta)
        # D is a random solution
        D = self._create_solution__(minmax=self.ID_MAX_PROBLEM)
        LB = 0.01 * s * (solution[self.ID_POS] - prey[self.ID_POS])

        levy = D[self.ID_POS] * LB
        return levy

        #x_new = solution[0] + 1.0/np.sqrt(epoch+1) * np.sign(np.random.uniform() - 0.5) * levy
        #return x_new 
開發者ID:thieunguyen5991,項目名稱:metaheuristics,代碼行數:21,代碼來源:TWO.py

示例11: _levy_flight__

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def _levy_flight__(self, epoch, solution, prey):
        beta = 1
        # muy and v are two random variables which follow normal distribution
        # sigma_muy : standard deviation of muy
        sigma_muy = np.power(gamma(1 + beta) * np.sin(np.pi * beta / 2) / (gamma((1 + beta) / 2) * beta * np.power(2, (beta - 1) / 2)), 1 / beta)
        # sigma_v : standard deviation of v
        sigma_v = 1
        muy = np.random.normal(0, sigma_muy)
        v = np.random.normal(0, sigma_v)
        s = muy / np.power(np.abs(v), 1 / beta)
        # D is a random solution
        D = self._create_solution__(minmax=self.ID_MAX_PROBLEM)
        LB = 0.001 * s * (solution[self.ID_POS] - prey[self.ID_POS])

        levy = D[self.ID_POS] * LB
        #return levy

        x_new = solution[0] + 1.0/np.sqrt(epoch+1) * np.sign(np.random.uniform() - 0.5) * levy
        return x_new 
開發者ID:thieunguyen5991,項目名稱:metaheuristics,代碼行數:21,代碼來源:HGSO.py

示例12: _levy_flight__

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def _levy_flight__(self, epoch, solution, prey):
        beta = 1
        # muy and v are two random variables which follow normal distribution
        # sigma_muy : standard deviation of muy
        sigma_muy = np.power(gamma(1 + beta) * np.sin(np.pi * beta / 2) / (gamma((1 + beta) / 2) * beta * np.power(2, (beta - 1) / 2)),1 / beta)
        # sigma_v : standard deviation of v
        sigma_v = 1
        muy = np.random.normal(0, sigma_muy)
        v = np.random.normal(0, sigma_v)
        s = muy / np.power(np.abs(v), 1 / beta)
        # D is a random solution
        D = self._create_solution__()
        LB = 0.001 * s * (solution[self.ID_POS] - prey[self.ID_POS])

        levy = D[self.ID_POS] * LB
        return levy
        #x_new = solution[self.ID_POS] + 1.0/np.sqrt(epoch+1) * np.sign(np.random.uniform() - 0.5) * levy
        #return x_new 
開發者ID:thieunguyen5991,項目名稱:metaheuristics,代碼行數:20,代碼來源:PFA.py

示例13: _levy_flight__

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def _levy_flight__(self, epoch, solution, prey):
        beta = 1
        # muy and v are two random variables which follow normal distribution
        # sigma_muy : standard deviation of muy
        sigma_muy = np.power(gamma(1 + beta) * np.sin(np.pi * beta / 2) / (gamma((1 + beta) / 2) * beta * np.power(2, (beta - 1) / 2)),1 / beta)
        # sigma_v : standard deviation of v
        sigma_v = 1
        muy = np.random.normal(0, sigma_muy)
        v = np.random.normal(0, sigma_v)
        s = muy / np.power(np.abs(v), 1 / beta)
        # D is a random solution
        D = self._create_solution__(minmax=self.ID_MIN_PROBLEM)
        LB =0.001 * s * (solution[self.ID_POS] - prey[self.ID_POS])

        levy = D[self.ID_POS] * LB
        return levy

        # x_new = solution[0] + 1.0/np.sqrt(epoch+1) * np.sign(np.random.uniform() - 0.5) * levy
        # return x_new 
開發者ID:thieunguyen5991,項目名稱:metaheuristics,代碼行數:21,代碼來源:NMR.py

示例14: _levy_flight__

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def _levy_flight__(self, epoch, solution, prey):
        beta = 1
        # muy and v are two random variables which follow normal distribution
        # sigma_muy : standard deviation of muy
        sigma_muy = np.power(gamma(1 + beta) * np.sin(np.pi * beta / 2) / (gamma((1 + beta) / 2) * beta * np.power(2, (beta - 1) / 2)), 1 / beta)
        # sigma_v : standard deviation of v
        sigma_v = 1
        muy = np.random.normal(0, sigma_muy**2)
        v = np.random.normal(0, sigma_v**2)
        s = muy / np.power(np.abs(v), 1 / beta)
        # D is a random solution
        D = self._create_solution__(minmax=self.ID_MAX_PROBLEM)
        LB = 0.01 * s * (solution[self.ID_POS] - prey[self.ID_POS])

        levy = D[self.ID_POS] * LB
        return levy

        #x_new = solution[0] + 1.0/np.sqrt(epoch+1) * np.sign(np.random.uniform() - 0.5) * levy
        #return x_new 
開發者ID:thieunguyen5991,項目名稱:metaheuristics,代碼行數:21,代碼來源:SFO.py

示例15: _levy_flight__

# 需要導入模塊: import math [as 別名]
# 或者: from math import gamma [as 別名]
def _levy_flight__(self, solution, A, current_iter):
        # muy and v are two random variables which follow normal distribution
        # sigma_muy : standard deviation of muy
        beta = 1
        sigma_muy = np.power(
            gamma(1 + beta) * np.sin(np.pi * beta / 2) / (gamma((1 + beta) / 2) * beta * np.power(2, (beta - 1) / 2)),
            1 / beta)
        # sigma_v : standard deviation of v
        sigma_v = 1
        muy = np.random.normal(0, sigma_muy)
        v = np.random.normal(0, sigma_v)
        s = muy / np.power(np.abs(v), 1 / beta)
        D = self._create_solution__(minmax=self.ID_MIN_PROBLEM)[self.ID_POS]
        LB = 0.01 * s * (solution - A)
        levy = D * LB
        # X_new = solution + 0.01*levy
        # X_new = solution + 1.0/np.sqrt(current_iter+1)*np.sign(np.random.random()-0.5)*levy
        return levy 
開發者ID:thieunguyen5991,項目名稱:metaheuristics,代碼行數:20,代碼來源:QSO.py


注:本文中的math.gamma方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。