本文整理汇总了Python中random.Random.betavariate方法的典型用法代码示例。如果您正苦于以下问题:Python Random.betavariate方法的具体用法?Python Random.betavariate怎么用?Python Random.betavariate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类random.Random
的用法示例。
在下文中一共展示了Random.betavariate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: no_learning_case
# 需要导入模块: from random import Random [as 别名]
# 或者: from random.Random import betavariate [as 别名]
def no_learning_case(agent, market_odds, seed=None):
"""
Given an agent and a seed, simulates agent.
You should NOT modify this function, except to print less/more info.
Args:
agent: Agent to simulate.
seed: seed for the random number generator. If None/default, the system time is used.
"""
rand = Random(seed)
agent.balance = INITIAL_MONEY
daily_balance = []
debug_print("Seed={}".format(seed))
for d in xrange(0, NUM_DAYS):
debug_print("Day {}".format(d))
debug_print("The balance at the beginning of the day is: {}".format(
agent.balance))
max_value = min(agent.balance, MAXIMUM_VALUE)
value = rand.random()*max_value
price = rand.random()*value
#probability the product is in working condition
#use the beta distribution
prob = rand.betavariate(market_odds[0], market_odds[1])
#is the product *actually* in working condition?
draw = rand.random()
product_working = draw <= prob
prod = Product(value, price)
debug_print("Product is {}".format(prod))
debug_print("The probability of the product being in working condition is {}".format(prob))
will_buy = agent.will_buy(prod, prob)
if will_buy:
debug_print("Agent {} decides to buy it.".format(agent))
#withdraw the product's price from the agent's account
agent.balance -= prod.price
if product_working:
debug_print("Good call: the product is in working condition.")
debug_print("The agent's profit is: {}.".format(
prod.value - prod.price))
#deposit the product's value to the agent's account
agent.balance += prod.value
else:
debug_print("Bad call: the product is faulty.")
debug_print("The agent loses {}.".format(prod.price))
#no deposit
else:
debug_print("Agent {} decides not to buy it.".format(agent))
if product_working:
debug_print("Missed opportunity: the product was in working condition.")
else:
debug_print("Good call: the product was faulty.")
#deposit the agent's independent earnings
agent.balance += DAILY_EARNINGS
#record the agent's balance
daily_balance.append(agent.balance)
debug_print("Day {}:\t{}".format(d+1, agent.balance))
return daily_balance