本文整理汇总了Python中random.betavariate方法的典型用法代码示例。如果您正苦于以下问题:Python random.betavariate方法的具体用法?Python random.betavariate怎么用?Python random.betavariate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类random
的用法示例。
在下文中一共展示了random.betavariate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zeroinputs
# 需要导入模块: import random [as 别名]
# 或者: from random import betavariate [as 别名]
def test_zeroinputs(self):
# Verify that distributions can handle a series of zero inputs'
g = random.Random()
x = [g.random() for i in range(50)] + [0.0]*5
g.random = x[:].pop; g.uniform(1,10)
g.random = x[:].pop; g.paretovariate(1.0)
g.random = x[:].pop; g.expovariate(1.0)
g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
g.random = x[:].pop; g.normalvariate(0.0, 1.0)
g.random = x[:].pop; g.gauss(0.0, 1.0)
g.random = x[:].pop; g.lognormvariate(0.0, 1.0)
g.random = x[:].pop; g.vonmisesvariate(0.0, 1.0)
g.random = x[:].pop; g.gammavariate(0.01, 1.0)
g.random = x[:].pop; g.gammavariate(1.0, 1.0)
g.random = x[:].pop; g.gammavariate(200.0, 1.0)
g.random = x[:].pop; g.betavariate(3.0, 3.0)
g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0)
示例2: test
# 需要导入模块: import random [as 别名]
# 或者: from random import betavariate [as 别名]
def test (mean_ratio,base_rate,length,alpha_pos=2,alpha_neg=2):
print "\n *** ScoringRule(mean_ratio=%d,base_rate=%f,length=%d,alpha: %d/%d)" % (mean_ratio,base_rate,length,alpha_pos,alpha_neg)
assert mean_ratio > 1
mean_neg = base_rate / (mean_ratio * base_rate + 1 - base_rate)
beta_neg = alpha_neg * (1-mean_neg) / mean_neg
mean_pos = min(1-base_rate,mean_ratio * mean_neg)
beta_pos = alpha_pos * (1-mean_pos) / mean_pos
sr = ScoringRule("mr={mr:g}".format(mr=mean_ratio))
lq = LiftQuality(sr.title)
for _ in xrange(int(round(base_rate*length))):
score = random.betavariate(alpha_pos,beta_pos)
sr.add(True,score)
lq.add(True,score)
for _ in xrange(int(round(length*(1-base_rate)))):
score = random.betavariate(alpha_neg,beta_neg)
sr.add(False,score)
lq.add(False,score)
print sr
print lq
示例3: get_dist
# 需要导入模块: import random [as 别名]
# 或者: from random import betavariate [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)
示例4: weighted_choice
# 需要导入模块: import random [as 别名]
# 或者: from random import betavariate [as 别名]
def weighted_choice(population, n):
"""Randomly select n unique individuals from a weighted population, fitness determines probability of being selected"""
def random_index_betavariate(pop_size):
#has a higher probability of returning index of item at the head of the list
alpha = 1
beta = 2.5
return int(random.betavariate(alpha, beta)*pop_size)
def random_index_weighted(pop_size):
"""might lead to problems: if there's only one valid configuration this method only returns that configuration"""
weights = [w for _, w in population]
#invert because lower is better
inverted_weights = [1.0/w for w in weights]
prefix_sum = np.cumsum(inverted_weights)
total_weight = sum(inverted_weights)
randf = random.random()*total_weight
#return first index of prefix_sum larger than random number
return next(i for i,v in enumerate(prefix_sum) if v > randf)
random_index = random_index_betavariate
indices = [random_index(len(population)) for _ in range(n)]
chosen = []
for ind in indices:
while ind in chosen:
ind = random_index(len(population))
chosen.append(ind)
return [population[ind][0] for ind in chosen]
示例5: test_betavariate_return_zero
# 需要导入模块: import random [as 别名]
# 或者: from random import betavariate [as 别名]
def test_betavariate_return_zero(self, gammavariate_mock):
# betavariate() returns zero when the Gamma distribution
# that it uses internally returns this same value.
gammavariate_mock.return_value = 0.0
self.assertEqual(0.0, random.betavariate(2.71828, 3.14159))
示例6: skewedGauss
# 需要导入模块: import random [as 别名]
# 或者: from random import betavariate [as 别名]
def skewedGauss(mu, sigma, bounds, upperSkewed=True):
raw = gauss(mu, sigma)
# Quicker to check an extra condition than do unnecessary math. . . .
if raw < mu and not upperSkewed:
out = ((mu - bounds[0]) / (3 * sigma)) * raw + ((mu * (bounds[0] - (mu - 3 * sigma))) / (3 * sigma))
elif raw > mu and upperSkewed:
out = ((mu - bounds[1]) / (3 * -sigma)) * raw + ((mu * (bounds[1] - (mu + 3 * sigma))) / (3 * -sigma))
else:
out = raw
return out
# @todo create a def for generating an alpha and beta for a beta distribution
# given a mu, sigma, and an upper and lower bound. This proved faster in
# profiling in addition to providing a much better distribution curve
# provided multiple iterations happen within this function; otherwise it was
# slower.
# This might be a scratch because of the bounds placed on mu and sigma:
#
# For alpha > 1 and beta > 1:
# mu^2 - mu^3 mu^3 - mu^2 + mu
# ----------- < sigma < ----------------
# 1 + mu 2 - mu
#
##def generateBeta(mu, sigma, scale, repitions=1):
## results = []
##
## return results
# Creates rock objects:
示例7: get_day_color
# 需要导入模块: import random [as 别名]
# 或者: from random import betavariate [as 别名]
def get_day_color():
#return (int(800 + (5000 * betavariate(0.2, 0.9))), randint(0, 10000), int(65535 * betavariate(0.5, 1)), randint(3500, 5000))
#return (randint(11739, 30836), randint(0, 10000), int(65535 * betavariate(0.15, 1)), randint(3500, 5000))
return (randint(11739, 30836), randint(3000, 10000), int(65535 * betavariate(0.15, 1)), randint(3000, 4000))
示例8: get_fire_color
# 需要导入模块: import random [as 别名]
# 或者: from random import betavariate [as 别名]
def get_fire_color():
return (int(800 + (5000 * betavariate(0.2, 0.9))), randint(60000, 65535), int(65535 * betavariate(0.05, 1)), randint(2500, 3500))
示例9: Random
# 需要导入模块: import random [as 别名]
# 或者: from random import betavariate [as 别名]
def Random(self):
"""Generates a random variate from this distribution."""
return random.betavariate(self.alpha, self.beta)