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


Python math.log1p方法代碼示例

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


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

示例1: test_math_subclass

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def test_math_subclass(self):
        """verify subtypes of float/long work w/ math functions"""
        import math
        class myfloat(float): pass
        class mylong(long): pass

        mf = myfloat(1)
        ml = mylong(1)

        for x in math.log, math.log10, math.log1p, math.asinh, math.acosh, math.atanh, math.factorial, math.trunc, math.isinf:
            try:
                resf = x(mf)
            except ValueError:
                resf = None
            try:
                resl = x(ml)
            except ValueError:
                resl = None
            self.assertEqual(resf, resl) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_math.py

示例2: include_revision

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def include_revision(revision_num, skip_factor=1.1):
  """Decide whether to include a revision.

  If the number of revisions is large, we exclude some revisions to avoid
  a quadratic blowup in runtime, since the article is likely also large.

  We make the ratio between consecutive included revision numbers
  appproximately equal to "factor".

  Args:
    revision_num: an integer
    skip_factor: a floating point number >= 1.0

  Returns:
    a boolean
  """
  if skip_factor <= 1.0:
    return True
  return (int(math.log1p(revision_num) / math.log(skip_factor)) != int(
      math.log(revision_num + 2.0) / math.log(skip_factor))) 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:22,代碼來源:wiki_revision_utils.py

示例3: _isapressalt_m

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def _isapressalt_m(self, pressure_pa):
        """Returns the geopotential alt (m) at which ISA has the given pressure"""
        press_it = np.nditer([pressure_pa, None])
        for press_pa, alt_m in press_it:
            if press_pa > self._pLevel1:
                # Troposphere
                alt_m[...] = (press_pa ** (1 / self._E1) - self._C1) / self._D1
            elif press_pa > self._pLevel2:
                # Lower stratopshere
                alt_m[...] = (1 / self._G2) * math.log1p(press_pa / self._F2 - 1)
            elif press_pa > self._pLevel3:
                # Upper stratopshere
                alt_m[...] = (press_pa ** (1 / self._E3) - self._C3) / self._D3
            elif press_pa > self._pLevel4:
                # Between 32 and 47 km
                alt_m[...] = (press_pa ** (1 / self._E4) - self._C4) / self._D4
            else:
                # Between 47km and 51km
                alt_m[...] = (1 / self._G5) * math.log1p(press_pa / self._F5 - 1)
        return press_it.operands[1] 
開發者ID:sobester,項目名稱:ADRpy,代碼行數:22,代碼來源:atmospheres.py

示例4: _isadensalt_m

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def _isadensalt_m(self, dens_kgpm3):
        """Returns the geopotential alt (m) at which ISA has given density (kg/m^3)"""
        dense_it = np.nditer([dens_kgpm3, None])
        for d_kgpm3, alt_m in dense_it:
            if d_kgpm3 > self._dLevel1:
                # Troposphere
                alt_m[...] = (d_kgpm3 ** (1 / self._L1) - self._I1) / self._J1
            elif d_kgpm3 > self._dLevel2:
                # Lower stratopshere
                alt_m[...] = (1 / self._N2) * math.log1p(dens_kgpm3 / self._M2 - 1)
            elif d_kgpm3 > self._dLevel3:
                # Upper stratopshere
                alt_m[...] = (d_kgpm3 ** (1 / self._L3) - self._I3) / self._J3
            elif dens_kgpm3 > self._dLevel4:
                # Between 32 and 47 km
                alt_m[...] = (d_kgpm3 ** (1 / self._L4) - self._I4) / self._J4
            else:
                # Between 47km and 51km
                alt_m[...] = (1 / self._N5) * math.log1p(d_kgpm3 / self._M5 - 1)
            # Adjust for the temperature offset
        return dense_it.operands[1] 
開發者ID:sobester,項目名稱:ADRpy,代碼行數:23,代碼來源:atmospheres.py

示例5: __add__

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def __add__(self, other):
        if other < 0:
            return self - -other

        log_other = self._log(other)
        if self.log_value > log_other:
            log_l, log_s = self.log_value, log_other
        elif self.log_value < log_other:
            log_l, log_s = log_other, self.log_value
        else:  # Must be equal, so just double value
            return self * 2

        if log_s == float("-inf"):  # Just return largest value
            return Probability(log_l, log_value=True)

        return Probability(log_l + log1p(exp(log_s - log_l)),
                           log_value=True) 
開發者ID:dstl,項目名稱:Stone-Soup,代碼行數:19,代碼來源:numeric.py

示例6: __sub__

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def __sub__(self, other):
        if other < 0:
            return self + -other

        log_other = self._log(other)
        if self.log_value > log_other:
            log_l, log_s = self.log_value, log_other
        elif self.log_value < log_other:  # Result will be negative
            return float(self) - other
        else:  # Must be equal, so return 0
            return Probability(float("-inf"), log_value=True)

        if log_s == float("-inf"):  # Just return largest value
            return Probability(log_l, log_value=True)

        exp_diff = exp(log_s - log_l)
        if exp_diff == 1:  # Diff too small, so result is effectively zero
            return Probability(float("-inf"), log_value=True)

        return Probability(log_l + log1p(-exp_diff),
                           log_value=True) 
開發者ID:dstl,項目名稱:Stone-Soup,代碼行數:23,代碼來源:numeric.py

示例7: __rsub__

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def __rsub__(self, other):
        if other < 0:  # Result will be negative
            return other + -float(self)

        log_other = self._log(other)
        if log_other > self.log_value:
            log_l, log_s = log_other, self.log_value
        elif log_other < self.log_value:  # Result will be negative
            return other + -float(self)
        else:  # Must be equal, so return 0
            return Probability(float("-inf"), log_value=True)

        if log_s == float("-inf"):  # Just return largest value
            return Probability(log_l, log_value=True)

        exp_diff = exp(log_s - log_l)
        if exp_diff == 1:  # Diff too small, so result is effectively zero
            return Probability(float("-inf"), log_value=True)

        return Probability(log_l + log1p(-exp_diff),
                           log_value=True) 
開發者ID:dstl,項目名稱:Stone-Soup,代碼行數:23,代碼來源:numeric.py

示例8: PDF

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def PDF(self,x):
        if (x <= 0.0) or (x >= 1.0):
            return 0.0
        else:
            logX = math.log(x)
            if (x < 0.0) and (x > 0.0):
                return 0.0
            log1mX = math.log1p(-x)
            ret = math.exp((self.alpha - 1.0) * logX + (self.beta - 1.0) \
                  * log1mX - self.Z)
            return ret 
開發者ID:modelop,項目名稱:hadrian,代碼行數:13,代碼來源:dist.py

示例9: _get_most_used_nodes

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def _get_most_used_nodes(preferences: Preferences) -> Set[int]:
    d = {}
    for node in preferences:
        d[node] = round(math.log1p(preferences[node] * 1000))
    nodes = sorted(d.items(), reverse=True, key=lambda x: x[1])
    z = nodes[0][1]
    best_nodes = {x[0] for x in nodes if x[1] == z}
    return best_nodes 
開發者ID:intel,項目名稱:workload-collocation-agent,代碼行數:10,代碼來源:numa_allocator.py

示例10: testLog1p

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def testLog1p(self):
        self.assertRaises(TypeError, math.log1p)
        self.ftest('log1p(1/e -1)', math.log1p(1/math.e-1), -1)
        self.ftest('log1p(0)', math.log1p(0), 0)
        self.ftest('log1p(e-1)', math.log1p(math.e-1), 1)
        self.ftest('log1p(1)', math.log1p(1), math.log(2))
        self.assertEqual(math.log1p(INF), INF)
        self.assertRaises(ValueError, math.log1p, NINF)
        self.assertTrue(math.isnan(math.log1p(NAN)))
        n= 2**90
        self.assertAlmostEqual(math.log1p(n), 62.383246250395075)
        self.assertAlmostEqual(math.log1p(n), math.log1p(float(n))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_math.py

示例11: log_sum_exp

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def log_sum_exp(a, b):
    """
    Stable log sum exp.
    """
    return max(a, b) + math.log1p(math.exp(-abs(a-b))) 
開發者ID:awni,項目名稱:transducer,代碼行數:7,代碼來源:decoders.py

示例12: test_log1p_expr

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def test_log1p_expr():
    expr = ast.Log1pExpr(ast.NumVal(2.0))

    interpreter = interpreters.PythonInterpreter()

    expected_code = """
import math
def score(input):
    return math.log1p(2.0)
    """

    utils.assert_code_equal(interpreter.interpret(expr), expected_code) 
開發者ID:BayesWitnesses,項目名稱:m2cgen,代碼行數:14,代碼來源:test_python.py

示例13: test_pure_python_math_module

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def test_pure_python_math_module(self):
        vals = [1, -.5, 1.5, 0, 0.0, -2, -2.2, .2]

        # not being tested: math.asinh, math.atanh, math.lgamma, math.erfc, math.acos
        def f():
            functions = [
                math.sqrt, math.cos, math.sin, math.tan, math.asin, math.atan,
                math.acosh, math.cosh, math.sinh, math.tanh, math.ceil,
                math.erf, math.exp, math.expm1, math.factorial, math.floor,
                math.log, math.log10, math.log1p
            ]
            tr = []
            for idx1 in range(len(vals)):
                v1 = vals[idx1]
                for funIdx in range(len(functions)):
                    function = functions[funIdx]
                    try:
                        tr = tr + [function(v1)]
                    except ValueError as ex:
                        pass

            return tr

        r1 = self.evaluateWithExecutor(f)
        r2 = f()
        self.assertGreater(len(r1), 100)
        self.assertTrue(numpy.allclose(r1, r2, 1e-6)) 
開發者ID:ufora,項目名稱:ufora,代碼行數:29,代碼來源:MathTestCases.py

示例14: idf

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def idf(self, term: str) -> float:
        r"""Calculate the Inverse Document Frequency of a term in the corpus.

        Parameters
        ----------
        term : str
            The term to calculate the IDF of

        Returns
        -------
        float
            The IDF

        Examples
        --------
        >>> tqbf = 'the quick brown fox jumped over the lazy dog\n\n'
        >>> tqbf += 'and then it slept\n\n and the dog ran off'
        >>> corp = UnigramCorpus(tqbf)
        >>> round(corp.idf('dog'), 10)
        0.6931471806
        >>> round(corp.idf('the'), 10)
        0.6931471806


        .. versionadded:: 0.4.0

        """
        if term in self.corpus:
            count, term_doc_count = self.corpus[term]
            return log1p(self.doc_count / term_doc_count)
        else:
            return float('inf') 
開發者ID:chrislit,項目名稱:abydos,代碼行數:34,代碼來源:_unigram_corpus.py

示例15: sim

# 需要導入模塊: import math [as 別名]
# 或者: from math import log1p [as 別名]
def sim(self, src: str, tar: str) -> float:
        """Return the Consonni & Todeschini III similarity of two strings.

        Parameters
        ----------
        src : str
            Source string (or QGrams/Counter objects) for comparison
        tar : str
            Target string (or QGrams/Counter objects) for comparison

        Returns
        -------
        float
            Consonni & Todeschini III similarity

        Examples
        --------
        >>> cmp = ConsonniTodeschiniIII()
        >>> cmp.sim('cat', 'hat')
        0.1648161441769704
        >>> cmp.sim('Niall', 'Neil')
        0.1648161441769704
        >>> cmp.sim('aluminum', 'Catalan')
        0.10396755253417303
        >>> cmp.sim('ATCG', 'TAGC')
        0.0


        .. versionadded:: 0.4.0

        """
        self._tokenize(src, tar)

        a = self._intersection_card()
        n = self._population_unique_card()

        if src == tar and n <= a:
            return 1.0

        return log1p(a) / log1p(n) 
開發者ID:chrislit,項目名稱:abydos,代碼行數:42,代碼來源:_consonni_todeschini_iii.py


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