• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python math._log函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _int_keys

	def _int_keys(self, data):
		t = self.cls()
		self.assertNode(t)
		self.assertIsNone(t._root)
		i = len(data)
		for j in range(i):
			self.assertEqual(j, len(t))
			self.assertNotIn(j, t)
			self.assertEqual(list(range(j)), list(t))
			t._set(j, data[j])
			self.assertNode(t)
			if j > 1:
				self.assertLess(t._root.height(), 2.0 * _log(j + 1, 2))
			else:
				self.assertEqual(t._root.height(), j + 1)
			self.assertEqual(data[j], t.get(j))
			self.assertIn(j, t)
		self.assertEqual(i, len(t))
		self.assertEqual(list(range(len(data))), list(t))
		self.assertIsNone(t.get(i + 1))
		# Deletion
		for j in range(i - 1, -1, -1):
			self.assertEqual(j + 1, len(t))
			self.assertIn(j, t)
			t._delete(j)
			self.assertNode(t)
			if j > 1:
				self.assertLessEqual(t._root.height(), 2.0 * _log(j, 2))
			elif j == 1:
				self.assertEqual(t._root.height(), j)
			else:
				self.assertIsNone(t._root)
			self.assertNotIn(j, t)
			self.assertEqual(list(range(j)), list(t))
		self.assertIsNone(t._root)
开发者ID:wkschwartz,项目名称:billib,代码行数:35,代码来源:test_sortedtable.py


示例2: gammavariate

    def gammavariate(self, alpha, beta):
        """Gamma distribution.  Not the gamma function!
        
        Conditions on the parameters are alpha > 0 and beta > 0.
        
        The probability distribution function is:
        
                    x ** (alpha - 1) * math.exp(-x / beta)
          pdf(x) =  --------------------------------------
                      math.gamma(alpha) * beta ** alpha
        
        """
        if alpha <= 0.0 or beta <= 0.0:
            raise ValueError, "gammavariate: alpha and beta must be > 0.0"
        random = self.random
        if alpha > 1.0:
            ainv = _sqrt(2.0 * alpha - 1.0)
            bbb = alpha - LOG4
            ccc = alpha + ainv
            while 1:
                u1 = random()
                if not 1e-07 < u1 < 0.9999999:
                    continue
                u2 = 1.0 - random()
                v = _log(u1 / (1.0 - u1)) / ainv
                x = alpha * _exp(v)
                z = u1 * u1 * u2
                r = bbb + ccc * v - x
                if r + SG_MAGICCONST - 4.5 * z >= 0.0 or r >= _log(z):
                    return x * beta

        else:
            if alpha == 1.0:
                u = random()
                while u <= 1e-07:
                    u = random()

                return -_log(u) * beta
            while 1:
                u = random()
                b = (_e + alpha) / _e
                p = b * u
                if p <= 1.0:
                    x = p ** (1.0 / alpha)
                else:
                    x = -_log((b - p) / alpha)
                u1 = random()
                if p > 1.0:
                    if u1 <= x ** (alpha - 1.0):
                        break
                elif u1 <= _exp(-x):
                    break

            return x * beta
开发者ID:webiumsk,项目名称:WOT-0.9.12,代码行数:54,代码来源:random.py


示例3: projCoordinate

    def projCoordinate(self, point):
        """ Convert from Point object in EPSG:900913 to a Coordinate object
        """
        # the zoom at which we're dealing with meters on the ground
        diameter = 2 * _pi * 6378137
        zoom = _log(diameter) / _log(2)

        # global offsets
        coord = Coordinate(point.y, point.x, zoom)
        coord.column = coord.column + diameter/2
        coord.row = diameter/2 - coord.row
        
        return coord
开发者ID:federicomenaquintero,项目名称:TileStache,代码行数:13,代码来源:Geography.py


示例4: stdgamma

    def stdgamma(self, alpha, ainv, bbb, ccc):
        # ainv = sqrt(2 * alpha - 1)
        # bbb = alpha - log(4)
        # ccc = alpha + ainv

        random = self.random
        if alpha <= 0.0:
            raise ValueError, 'stdgamma: alpha must be > 0.0'

        if alpha > 1.0:

            # Uses R.C.H. Cheng, "The generation of Gamma
            # variables with non-integral shape parameters",
            # Applied Statistics, (1977), 26, No. 1, p71-74

            while 1:
                u1 = random()
                u2 = random()
                v = _log(u1/(1.0-u1))/ainv
                x = alpha*_exp(v)
                z = u1*u1*u2
                r = bbb+ccc*v-x
                if r + SG_MAGICCONST - 4.5*z >= 0.0 or r >= _log(z):
                    return x

        elif alpha == 1.0:
            # expovariate(1)
            u = random()
            while u <= 1e-7:
                u = random()
            return -_log(u)

        else:   # alpha is between 0 and 1 (exclusive)

            # Uses ALGORITHM GS of Statistical Computing - Kennedy & Gentle

            while 1:
                u = random()
                b = (_e + alpha)/_e
                p = b*u
                if p <= 1.0:
                    x = pow(p, 1.0/alpha)
                else:
                    # p > 1
                    x = -_log((b-p)/alpha)
                u1 = random()
                if not (((p <= 1.0) and (u1 > _exp(-x))) or
                          ((p > 1)  and  (u1 > pow(x, alpha - 1.0)))):
                    break
            return x
开发者ID:AngusGeek,项目名称:org.aspectj,代码行数:50,代码来源:random.py


示例5: coordinateProj

    def coordinateProj(self, coord):
        """ Convert from Coordinate object to a Point object in EPSG:900913
        """
        # the zoom at which we're dealing with meters on the ground
        diameter = 2 * _pi * 6378137
        zoom = _log(diameter) / _log(2)
        coord = coord.zoomTo(zoom)
        
        # global offsets
        point = Point(coord.column, coord.row)
        point.x = point.x - diameter/2
        point.y = diameter/2 - point.y

        return point
开发者ID:federicomenaquintero,项目名称:TileStache,代码行数:14,代码来源:Geography.py


示例6: sample

	def sample(self, population, k, generator=None):
		# This function exactly parallels the code in Random.py.
		# Comments are therefore omitted, to save space.
		
		n = len(population)
		if not 0 <= k <= n:
			raise ValueError('sample larger than population')
		randrange = self.randrange
		result = [None] * k
		setsize = 21
		if k > 5:
			setsize += 4 ** _ceil(_log(k * 3, 4))
		if n <= setsize or hasattr(population, 'keys'):
			pool = list(population)
			for i in xrange(k):
				j = randrange(n-i, generator=generator)
				result[i] = pool[j]
				pool[j] = pool[n-i-1]
		else:
			try:
				selected = set()
				selected_add = selected.add
				for i in xrange(k):
					j = randrange(n, generator=generator)
					while j in selected:
						j = randrange(n, generator=generator)
					selected_add(j)
					result[i] = population[j]
			except (TypeError, KeyError):
				if isinstance(population, list):
					raise
				return self.sample(tuple(population), k, generator)
		return result
开发者ID:toffer,项目名称:RandomSources,代码行数:33,代码来源:quantumRandom.py


示例7: sample

 def sample(self, population, k):
    """Chooses k unique random elements from a population sequence."""
    # https://github.com/python/cpython/blob/2.7/Lib/random.py#L275
    n = len(population)
    if not 0 <= k <= n:
       raise ValueError("sample larger than population")
    random = self.random
    _int = int
    result = [None] * k
    setsize = 21      # size of a small set minus size of an empty list
    if k > 5:
       setsize += 4 ** _ceil(_log(k * 3, 4)) # table size for big sets
    if n <= setsize or hasattr(population, "keys"):
       # An n-length list is smaller than a k-length set, or this is a
       # mapping type so the other algorithm wouldn't work.
       pool = list(population)
       for i in xrange(k):       # invariant:  non-selected at [0,n-i)
          j = _int(random() * (n-i))
          result[i] = pool[j]
          pool[j] = pool[n-i-1]   # move non-selected item into vacancy
    else:
       try:
          selected = set()
          selected_add = selected.add
          for i in xrange(k):
             j = _int(random() * n)
             while j in selected:
                j = _int(random() * n)
             selected_add(j)
             result[i] = population[j]
       except (TypeError, KeyError):   # handle (at least) sets
          if isinstance(population, list):
             raise
          return self.sample(tuple(population), k)
    return result
开发者ID:raohmaru,项目名称:CFC,代码行数:35,代码来源:utils_random.py


示例8: dup_revert

def dup_revert(f, n, K):
    """
    Compute ``f**(-1)`` mod ``x**n`` using Newton iteration.

    This function computes first ``2**n`` terms of a polynomial that
    is a result of inversion of a polynomial modulo ``x**n``. This is
    useful to efficiently compute series expansion of ``1/f``.

    Examples
    ========

    >>> from sympy.polys import ring, QQ
    >>> R, x = ring("x", QQ)

    >>> f = -QQ(1,720)*x**6 + QQ(1,24)*x**4 - QQ(1,2)*x**2 + 1

    >>> R.dup_revert(f, 8)
    61/720*x**6 + 5/24*x**4 + 1/2*x**2 + 1

    """
    g = [K.revert(dup_TC(f, K))]
    h = [K.one, K.zero, K.zero]

    N = int(_ceil(_log(n, 2)))

    for i in range(1, N + 1):
        a = dup_mul_ground(g, K(2), K)
        b = dup_mul(f, dup_sqr(g, K), K)
        g = dup_rem(dup_sub(a, b, K), h, K)
        h = dup_lshift(h, dup_degree(h), K)

    return g
开发者ID:asmeurer,项目名称:sympy,代码行数:32,代码来源:densetools.py


示例9: sample

 def sample(self, population, k):
     if isinstance(population, _Set):
         population = tuple(population)
     if not isinstance(population, _Sequence):
         raise TypeError('Population must be a sequence or set.  For dicts, use list(d).')
     randbelow = self._randbelow
     n = len(population)
     if not 0 <= k <= n:
         raise ValueError('Sample larger than population')
     result = [None]*k
     setsize = 21
     if k > 5:
         setsize += 4**_ceil(_log(k*3, 4))
     if n <= setsize:
         pool = list(population)
         for i in range(k):
             j = randbelow(n - i)
             result[i] = pool[j]
             pool[j] = pool[n - i - 1]
     else:
         selected = set()
         selected_add = selected.add
         for i in range(k):
             j = randbelow(n)
             while j in selected:
                 j = randbelow(n)
             selected_add(j)
             result[i] = population[j]
     return result
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:29,代码来源:random.py


示例10: expovariate

    def expovariate(self, lambd):

        """Exponential distribution.


        lambd is 1.0 divided by the desired mean.  It should be

        nonzero.  (The parameter would be called "lambda", but that is

        a reserved word in Python.)  Returned values range from 0 to

        positive infinity if lambd is positive, and from negative

        infinity to 0 if lambd is negative.


        """

        # lambd: rate lambd = 1/mean

        # ('lambda' is a Python reserved word)


        # we use 1-random() instead of random() to preclude the

        # possibility of taking the log of zero.

        return -_log(1.0 - self.random())/lambd
开发者ID:JoseAntonioMora,项目名称:ProyectoSVM,代码行数:28,代码来源:lrandom.py


示例11: integer_nthroot

def integer_nthroot(y, n):
    """
    Return a tuple containing x = floor(y**(1/n))
    and a boolean indicating whether the result is exact (that is,
    whether x**n == y).

    >>> from sympy import integer_nthroot
    >>> integer_nthroot(16,2)
    (4, True)
    >>> integer_nthroot(26,2)
    (5, False)

    """
    y, n = int(y), int(n)
    if y < 0:
        raise ValueError("y must be nonnegative")
    if n < 1:
        raise ValueError("n must be positive")
    if y in (0, 1):
        return y, True
    if n == 1:
        return y, True
    if n == 2:
        x, rem = mpmath_sqrtrem(y)
        return int(x), not rem
    if n > y:
        return 1, False
    # Get initial estimate for Newton's method. Care must be taken to
    # avoid overflow
    try:
        guess = int(y**(1./n) + 0.5)
    except OverflowError:
        exp = _log(y, 2)/n
        if exp > 53:
            shift = int(exp - 53)
            guess = int(2.0**(exp - shift) + 1) << shift
        else:
            guess = int(2.0**exp)
    #print n
    if guess > 2**50:
        # Newton iteration
        xprev, x = -1, guess
        while 1:
            t = x**(n - 1)
            #xprev, x = x, x - (t*x-y)//(n*t)
            xprev, x = x, ((n - 1)*x + y//t)//n
            #print n, x-xprev, abs(x-xprev) < 2
            if abs(x - xprev) < 2:
                break
    else:
        x = guess
    # Compensate
    t = x**n
    while t < y:
        x += 1
        t = x**n
    while t > y:
        x -= 1
        t = x**n
    return x, t == y
开发者ID:hrashk,项目名称:sympy,代码行数:60,代码来源:power.py


示例12: _randbelow

    def _randbelow(self, n, _log=_log, _int=int, _maxwidth=1<<BPF,
                   _Method=_MethodType, _BuiltinMethod=_BuiltinMethodType):
        """Return a random int in the range [0,n)

        Handles the case where n has more bits than returned
        by a single call to the underlying generator.
        """

        try:
            getrandbits = self.getrandbits
        except AttributeError:
            pass
        else:
            # Only call self.getrandbits if the original random() builtin method
            # has not been overridden or if a new getrandbits() was supplied.
            # This assures that the two methods correspond.
            if type(self.random) is _BuiltinMethod or type(getrandbits) is _Method:
                k = _int(1.00001 + _log(n-1, 2.0))   # 2**k > n-1 > 2**(k-2)
                r = getrandbits(k)
                while r >= n:
                    r = getrandbits(k)
                return r
        if n >= _maxwidth:
            _warn("Underlying random() generator does not supply \n"
                "enough bits to choose from a population range this large")
        return _int(self.random() * n)
开发者ID:PySCeS,项目名称:pysces,代码行数:26,代码来源:PyscesRandom.py


示例13: sample

    def sample(self, population, k):
        """Chooses k unique random elements from a population sequence.

        Returns a new list containing elements from the population while
        leaving the original population unchanged.  The resulting list is
        in selection order so that all sub-slices will also be valid random
        samples.  This allows raffle winners (the sample) to be partitioned
        into grand prize and second place winners (the subslices).

        Members of the population need not be hashable or unique.  If the
        population contains repeats, then each occurrence is a possible
        selection in the sample.

        To choose a sample in a range of integers, use xrange as an argument.
        This is especially fast and space efficient for sampling from a
        large population:   sample(xrange(10000000), 60)
        """

        # Sampling without replacement entails tracking either potential
        # selections (the pool) in a list or previous selections in a set.

        # When the number of selections is small compared to the
        # population, then tracking selections is efficient, requiring
        # only a small set and an occasional reselection.  For
        # a larger number of selections, the pool tracking method is
        # preferred since the list takes less space than the
        # set and it doesn't suffer from frequent reselections.

        n = len(population)
        if not 0 <= k <= n:
            raise ValueError("sample larger than population")
        random = self.random
        _int = int
        result = [None] * k
        setsize = 21        # size of a small set minus size of an empty list
        if k > 5:
            setsize += 4 ** _ceil(_log(k * 3, 4)) # table size for big sets
        if n <= setsize or hasattr(population, "keys"):
            # An n-length list is smaller than a k-length set, or this is a
            # mapping type so the other algorithm wouldn't work.
            pool = list(population)
            for i in xrange(k):         # invariant:  non-selected at [0,n-i)
                j = _int(random() * (n-i))
                result[i] = pool[j]
                pool[j] = pool[n-i-1]   # move non-selected item into vacancy
        else:
            try:
                selected = set()
                selected_add = selected.add
                for i in xrange(k):
                    j = _int(random() * n)
                    while j in selected:
                        j = _int(random() * n)
                    selected_add(j)
                    result[i] = population[j]
            except (TypeError, KeyError):   # handle (at least) sets
                if isinstance(population, list):
                    raise
                return self.sample(tuple(population), k)
        return result
开发者ID:zegab,项目名称:diane,代码行数:60,代码来源:random.py


示例14: gauss

    def gauss(self, mu, sigma):
        # """Gaussian distribution.
        # mu is the mean, and sigma is the standard deviation.  This is
        # slightly faster than the normalvariate() function.
        # Not thread-safe without a lock around calls.
        # """

        # When x and y are two variables from [0, 1), uniformly
        # distributed, then
        #
        #    cos(2*pi*x)*sqrt(-2*log(1-y))
        #    sin(2*pi*x)*sqrt(-2*log(1-y))
        #
        # are two *independent* variables with normal distribution
        # (mu = 0, sigma = 1).
        # (Lambert Meertens)
        # (corrected version; bug discovered by Mike Miller, fixed by LM)

        # Multithreading note: When two threads call this function
        # simultaneously, it is possible that they will receive the
        # same return value.  The window is very small though.  To
        # avoid this, you have to use a lock around all calls.  (I
        # didn't want to slow this down in the serial case by using a
        # lock here.)

        __random = self.random
        z = self.gauss_next
        self.gauss_next = None
        if z is None:
            x2pi = __random() * TWOPI
            g2rad = _sqrt(-2.0 * _log(1.0 - __random()))
            z = _cos(x2pi) * g2rad
            self.gauss_next = _sin(x2pi) * g2rad

        return mu + z*sigma
开发者ID:Afey,项目名称:pyjs,代码行数:35,代码来源:random.py


示例15: dup_revert

def dup_revert(f, n, K):
    """
    Compute ``f**(-1)`` mod ``x**n`` using Newton iteration.

    This function computes first ``2**n`` terms of a polynomial that
    is a result of inversion of a polynomial modulo ``x**n``. This is
    useful to efficiently compute series expansion of ``1/f``.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.densetools import dup_revert

    >>> f = [-QQ(1,720), QQ(0), QQ(1,24), QQ(0), -QQ(1,2), QQ(0), QQ(1)]

    >>> dup_revert(f, 8, QQ)
    [61/720, 0/1, 5/24, 0/1, 1/2, 0/1, 1/1]

    """
    g = [K.revert(dup_TC(f, K))]
    h = [K.one, K.zero, K.zero]

    N = int(_ceil(_log(n, 2)))

    for i in xrange(1, N + 1):
        a = dup_mul_ground(g, K(2), K)
        b = dup_mul(f, dup_sqr(g, K), K)
        g = dup_rem(dup_sub(a, b, K), h, K)
        h = dup_lshift(h, dup_degree(h), K)

    return g
开发者ID:jenshnielsen,项目名称:sympy,代码行数:32,代码来源:densetools.py


示例16: expovariate

    def expovariate(self, lambd):
        random = self.random
        u = random()
        while u <= 1e-07:
            u = random()

        return -_log(u) / lambd
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:7,代码来源:random.py


示例17: sample

    def sample(self, population, k):
        n = len(population)
        if not 0 <= k <= n:
            raise ValueError, 'sample larger than population'
        random = self.random
        _int = int
        result = [None] * k
        setsize = 21
        if k > 5:
            setsize += 4 ** _ceil(_log(k * 3, 4))
        if n <= setsize or hasattr(population, 'keys'):
            pool = list(population)
            for i in xrange(k):
                j = _int(random() * (n - i))
                result[i] = pool[j]
                pool[j] = pool[n - i - 1]

        else:
            try:
                selected = set()
                selected_add = selected.add
                for i in xrange(k):
                    j = _int(random() * n)
                    while j in selected:
                        j = _int(random() * n)

                    selected_add(j)
                    result[i] = population[j]

            except (TypeError, KeyError):
                if isinstance(population, list):
                    raise
                return self.sample(tuple(population), k)

        return result
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:35,代码来源:random.py


示例18: sample

    def sample(self, population: Iterable[T], k: int) -> List[T]:
        """Chooses k unique random elements from a population sequence or set.

        Returns a new list containing elements from the population while
        leaving the original population unchanged.  The resulting list is
        in selection order so that all sub-slices will also be valid random
        samples.  This allows raffle winners (the sample) to be partitioned
        into grand prize and second place winners (the subslices).

        Members of the population need not be hashable or unique.  If the
        population contains repeats, then each occurrence is a possible
        selection in the sample.

        To choose a sample in a range of integers, use range as an argument.
        This is especially fast and space efficient for sampling from a
        large population:   sample(range(10000000), 60)
        """

        # Sampling without replacement entails tracking either potential
        # selections (the pool) in a list or previous selections in a set.

        # When the number of selections is small compared to the
        # population, then tracking selections is efficient, requiring
        # only a small set and an occasional reselection.  For
        # a larger number of selections, the pool tracking method is
        # preferred since the list takes less space than the
        # set and it doesn't suffer from frequent reselections.

        if isinstance(population, _Sequence):
            populationseq = population
        elif isinstance(population, _Set):
            populationseq = list(population)
        else:
            raise TypeError("Population must be a sequence or set.  For dicts, use list(d).")
        randbelow = self._randbelow
        n = len(populationseq)
        if not (0 <= k and k <= n):
            raise ValueError("Sample larger than population")
        result = [cast(T, None)] * k
        setsize = 21        # size of a small set minus size of an empty list
        if k > 5:
            setsize += 4 ** _ceil(_log(k * 3, 4)) # table size for big sets
        if n <= setsize:
            # An n-length list is smaller than a k-length set
            pool = list(populationseq)
            for i in range(k):         # invariant:  non-selected at [0,n-i)
                j = randbelow(n-i)
                result[i] = pool[j]
                pool[j] = pool[n-i-1]   # move non-selected item into vacancy
        else:
            selected = Set[int]()
            selected_add = selected.add
            for i in range(k):
                j = randbelow(n)
                while j in selected:
                    j = randbelow(n)
                selected_add(j)
                result[i] = populationseq[j]
        return result
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:59,代码来源:random.py


示例19: weibullvariate

    def weibullvariate(self, alpha, beta):
        # """Weibull distribution.
        # alpha is the scale parameter and beta is the shape parameter.
        # """
        # Jain, pg. 499; bug fix courtesy Bill Arms

        u = 1.0 - self.random()
        return alpha * pow(-_log(u), 1.0/beta)
开发者ID:Afey,项目名称:pyjs,代码行数:8,代码来源:random.py


示例20: weibullvariate

 def weibullvariate(self, alpha, beta):
     """Weibull distribution.
     
     alpha is the scale parameter and beta is the shape parameter.
     
     """
     u = 1.0 - self.random()
     return alpha * pow(-_log(u), 1.0 / beta)
开发者ID:webiumsk,项目名称:WOT-0.9.12,代码行数:8,代码来源:random.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python math._sin函数代码示例发布时间:2022-05-27
下一篇:
Python math._exp函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap