本文整理匯總了Python中random.lognormvariate方法的典型用法代碼示例。如果您正苦於以下問題:Python random.lognormvariate方法的具體用法?Python random.lognormvariate怎麽用?Python random.lognormvariate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類random
的用法示例。
在下文中一共展示了random.lognormvariate方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _add_initial_log_distribution
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def _add_initial_log_distribution(list_population, mu, sigma):
"""
Adding a initial distribution
@attention: Values for first sample
@param list_population: Main list for all distributions
@type : list[list[float]]
@param mu: Mean
@type mu: float
@param sigma: standard deviation
@type sigma: float
@return: Nothing
@rtype: None
"""
assert isinstance(list_population, list)
assert isinstance(mu, (float, int, long))
assert isinstance(sigma, (float, int, long))
for index in xrange(len(list_population)):
list_population[index][0] = random.lognormvariate(mu, sigma)
示例2: _add_timeseries_lognorm
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def _add_timeseries_lognorm(list_population, mu, sigma):
"""
each abundance profile is produced by
- draw new value from lognorm distribution
- add old and new value and divide by 2
@attention:
@param list_population: Main list for all distributions
@type : list[list[float]]
@param mu: Mean
@type mu: float
@param sigma: standard deviation
@type sigma: float
@return: Nothing
@rtype: None
"""
assert isinstance(list_population, list)
assert isinstance(mu, (float, int, long))
assert isinstance(sigma, (float, int, long))
for index_p in xrange(len(list_population)):
for index_i in xrange(len(list_population[index_p])-1):
list_population[index_p][index_i+1] = (list_population[index_p][index_i] + random.lognormvariate(mu, sigma))/2
示例3: _add_differential
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def _add_differential(list_population, mu, sigma):
"""
Abundance is drawn independently from previous lognorm distributions
@attention:
@param list_population: Main list for all distributions
@type : list[list[float]]
@param mu: Mean
@type mu: float
@param sigma: standard deviation
@type sigma: float
@return: Nothing
@rtype: None
"""
assert isinstance(list_population, list)
assert isinstance(mu, (float, int, long))
assert isinstance(sigma, (float, int, long))
for index_p in xrange(len(list_population)):
for index_i in xrange(len(list_population[index_p])-1):
list_population[index_p][index_i+1] = random.lognormvariate(mu, sigma)
示例4: get_dist
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def get_dist(d):
return {
'randrange': random.randrange, # start, stop, step
'randint': random.randint, # a, b
'random': random.random,
'uniform': random, # a, b
'triangular': random.triangular, # low, high, mode
'beta': random.betavariate, # alpha, beta
'expo': random.expovariate, # lambda
'gamma': random.gammavariate, # alpha, beta
'gauss': random.gauss, # mu, sigma
'lognorm': random.lognormvariate, # mu, sigma
'normal': random.normalvariate, # mu, sigma
'vonmises': random.vonmisesvariate, # mu, kappa
'pareto': random.paretovariate, # alpha
'weibull': random.weibullvariate # alpha, beta
}.get(d)
示例5: test_Density
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def test_Density(self):
"""Statistics.Density test"""
import random
## a lognormal density distribution the log of which has mean 1.0
## and stdev 0.5
self.X = [ (x, p_lognormal(x, 1.0, 0.5))
for x in N0.arange(0.00001, 50, 0.001)]
alpha = 2.
beta = 0.6
self.R = [ random.lognormvariate( alpha, beta )
for i in range( 10000 )]
p = logConfidence( 6.0, self.R )[0]#, area(6.0, alpha, beta)
示例6: test_heap
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def test_heap(self):
iterations = 5000
maxblocks = 50
blocks = []
# create and destroy lots of blocks of different sizes
for i in xrange(iterations):
size = int(random.lognormvariate(0, 1) * 1000)
b = multiprocessing.heap.BufferWrapper(size)
blocks.append(b)
if len(blocks) > maxblocks:
i = random.randrange(maxblocks)
del blocks[i]
# get the heap object
heap = multiprocessing.heap.BufferWrapper._heap
# verify the state of the heap
all = []
occupied = 0
heap._lock.acquire()
self.addCleanup(heap._lock.release)
for L in heap._len_to_seq.values():
for arena, start, stop in L:
all.append((heap._arenas.index(arena), start, stop,
stop-start, 'free'))
for arena, start, stop in heap._allocated_blocks:
all.append((heap._arenas.index(arena), start, stop,
stop-start, 'occupied'))
occupied += (stop-start)
all.sort()
for i in range(len(all)-1):
(arena, start, stop) = all[i][:3]
(narena, nstart, nstop) = all[i+1][:3]
self.assertTrue((arena != narena and nstart == 0) or
(stop == nstart))
示例7: test_heap
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def test_heap(self):
iterations = 5000
maxblocks = 50
blocks = []
# create and destroy lots of blocks of different sizes
for i in range(iterations):
size = int(random.lognormvariate(0, 1) * 1000)
b = multiprocessing.heap.BufferWrapper(size)
blocks.append(b)
if len(blocks) > maxblocks:
i = random.randrange(maxblocks)
del blocks[i]
# get the heap object
heap = multiprocessing.heap.BufferWrapper._heap
# verify the state of the heap
all = []
occupied = 0
heap._lock.acquire()
self.addCleanup(heap._lock.release)
for L in list(heap._len_to_seq.values()):
for arena, start, stop in L:
all.append((heap._arenas.index(arena), start, stop,
stop-start, 'free'))
for arena, start, stop in heap._allocated_blocks:
all.append((heap._arenas.index(arena), start, stop,
stop-start, 'occupied'))
occupied += (stop-start)
all.sort()
for i in range(len(all)-1):
(arena, start, stop) = all[i][:3]
(narena, nstart, nstop) = all[i+1][:3]
self.assertTrue((arena != narena and nstart == 0) or
(stop == nstart))
示例8: sample
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def sample(self):
result = self._scale * random.lognormvariate(self._mu, self._sigma)
if self._maximum is not None and result > self._maximum:
for _ignore in range(10):
result = self._scale * random.lognormvariate(self._mu, self._sigma)
if result <= self._maximum:
break
else:
raise ValueError("Unable to generate LogNormalDistribution sample within required range")
return result
示例9: test_lognormal
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def test_lognormal(self):
"""Statistics.lognormal test"""
import random
import Biskit.gnuplot as gnuplot
import Biskit.hist as H
cr = []
for i in range( 10000 ):
## Some random values drawn from the same lognormal distribution
alpha = 1.5
beta = .7
x = 10.
R = [ random.lognormvariate( alpha, beta ) for j in range( 10 ) ]
cr += [ logConfidence( x, R )[0] ]
ca = logArea( x, alpha, beta )
if self.local:
gnuplot.plot( H.density( N0.array(cr) - ca, 100 ) )
globals().update( locals() )
self.assertAlmostEqual( ca, 0.86877651432955771, 7)
示例10: callback_liveOut_pipe_in
# 需要導入模塊: import random [as 別名]
# 或者: from random import lognormvariate [as 別名]
def callback_liveOut_pipe_in(named_count, state_uid, **kwargs):
'Handle something changing the value of the input pipe or the associated state uid'
cache_key = _get_cache_key(state_uid)
state = cache.get(cache_key)
# If nothing in cache, prepopulate
if not state:
state = {}
# Guard against missing input on startup
if not named_count:
named_count = {}
# extract incoming info from the message and update the internal state
user = named_count.get('user', None)
click_colour = named_count.get('click_colour', None)
click_timestamp = named_count.get('click_timestamp', 0)
if click_colour:
colour_set = state.get(click_colour, None)
if not colour_set:
colour_set = [(None, 0, 100) for i in range(5)]
_, last_ts, prev = colour_set[-1]
# Loop over all existing timestamps and find the latest one
if not click_timestamp or click_timestamp < 1:
click_timestamp = 0
for _, the_colour_set in state.items():
_, lts, _ = the_colour_set[-1]
if lts > click_timestamp:
click_timestamp = lts
click_timestamp = click_timestamp + 1000
if click_timestamp > last_ts:
colour_set.append((user, click_timestamp, prev * random.lognormvariate(0.0, 0.1)),)
colour_set = colour_set[-100:]
state[click_colour] = colour_set
cache.set(cache_key, state, 3600)
return "(%s,%s)" % (cache_key, click_timestamp)