本文整理汇总了Python中random.paretovariate函数的典型用法代码示例。如果您正苦于以下问题:Python paretovariate函数的具体用法?Python paretovariate怎么用?Python paretovariate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了paretovariate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: workload_generator
def workload_generator():
workload = []
# random.seed(RANDOM_SEED) #due to result unstable
for i in range(WORKLOAD_LENGTH):
t = random.paretovariate(1) - 1
if t > 2:
t = random.paretovariate(1) - 1
if t > 2:
t = 2
# t = 3
workload.append(int(t/2*97*1000 + 3000))
return workload
开发者ID:hfx1991818,项目名称:cpufreq-interactive-opt,代码行数:12,代码来源:cpufreq_interactive_stimulator_20171024-bench.py
示例2: simulate_once
def simulate_once(self, servers, track_history = False):
if(track_history): self.one_sim_once_hist = []
# set up some useful variables
max_wait = 5
total_minutes = 60 * 24
# prepare array of request slots
request_slots = [0.0] * servers
# start simulation
requests = dropped = 0
t = random.expovariate(1.0)
while(t < total_minutes):
# check if request can be served on any servers
request_taken = False
for i in range(0, servers):
server_finish_time = request_slots[i]
if(not request_taken):
# request not taken, serve if possible
if(server_finish_time < t):
# server is open, assign new req with finish time
request_slots[i] = t + 5 * random.paretovariate(2.5)
request_taken = True
break
elif(server_finish_time < t + max_wait):
# server will be open sometime within the max wait
# threshold, calc new time as finish time + new time
request_slots[i] = server_finish_time + 5 * random.paretovariate(2.5)
request_taken = True
break
# track some variables
if(not request_taken): dropped += 1
requests += 1
if(track_history): self.one_sim_once_hist.append((t, requests, dropped))
# calculate next request time
t += random.expovariate(1.0)
# scale simulation up to 1 year
days = 365
requests *= days
dropped *= days
# calculate cost
cost = servers * 300 + dropped * 10
return cost
示例3: __init__
def __init__(self, options={}):
super(CellMazeMap, self).__init__(options)
report('random seed {0}'.format(self.random_seed))
self.name = 'cell_maze'
self.players = self.get_random_option(options.get('players', max(2, min(10, int((betavariate(2.5, 3.0) * 10) + 1)))))
report('players {0}'.format(self.players))
self.area = self.get_random_option(options.get('area', self.players * randrange(400, 40000 / self.players)))
report('area {0}'.format(self.area))
self.cell_width = self.get_random_option(options.get('cell_width', min(paretovariate(2), 7.0)))
report('cell width: {0}'.format(self.cell_width))
self.cell_size = self.get_random_option(options.get('cell_size', int(min(paretovariate(2) + 4.0, 20.0) + int(self.cell_width) + 1)))
report('cell size: {0}'.format(self.cell_size))
self.openness = self.get_random_option(options.get('openness', betavariate(1.0, 3.0)))
report('openness: {0}'.format(self.openness))
示例4: bounded_pareto_variate
def bounded_pareto_variate(alpha, upper_bound):
"""Repeatedly draws a random variable from the Pareto distribution
until the variable meets the given upper bound.
`alpha` is the parameter for the Pareto distribution.
`upper_bound` is the upper bound which the random variable must
meet.
"""
result = random.paretovariate(alpha)
while result >= upper_bound:
result = random.paretovariate(alpha)
return result
示例5: pareto_dist_orgs
def pareto_dist_orgs(organism, alpha=1):
"""Implementation of the Pareto distribution for species member counts.
See http://en.wikipedia.org/wiki/Pareto_distribution#Generating_bounded_Pareto_random_variables
"""
rand = random.paretovariate(alpha)
return rand
示例6: generate
def generate(self, packet_params): # generates bursts
meanTBA = packet_params["mean-arrival"]
min_packet_duration = packet_params["min-duration"]
packet_duration_concentration = packet_params["duration-concentration"]
i = 0
while True:
# initialize burst at random time in future with random duration
burst = Burst(name="Burst %s" % i, sim=self.sim)
# generate next burst time
# yield to next burst time
# arrival time of burst a Poisson distr
interarrival_time = expovariate(1.0 / meanTBA)
# hold suspends until interarrival time has passed
yield hold, self, interarrival_time
#print "%s arrived at %s" % (self.name, self.sim.now())
# generate duration
# Pareto distribution for burst durtion
duration = ceil(paretovariate(packet_duration_concentration)) +
min_packet_duration
# activate burst with a duration and load balancer
self.sim.activate(burst, burst.visit(duration))
i += 1
示例7: mock_lag
def mock_lag(lower_bound = 1.0 / 16, upper_bound = 4.0):
'''Randomly generate seconds of network lag.
>>> lags = [mock_lag() for i in range(1000)]
>>> get_out_of_bounds(lags)
>>> lags = [mock_lag() for i in range(1000)]
>>> get_out_of_bounds(lags)
>>> lags = [mock_lag() for i in range(1000)]
>>> get_out_of_bounds(lags)
Speed up for tests.
>>> mock_speed = 16
>>> lo, hi = 0.5 / mock_speed, 1.0 / mock_speed
>>> lags = [mock_lag(lo, hi) for i in range(1000)]
>>> out = get_out_of_bounds(lags, lo, hi)
>>> if out:
... lo, out, hi
Other values. Thin tail means upper bound is rarely approached.
>>> lags = [mock_lag(1.0, 2.0) for i in range(1000)]
>>> get_out_of_bounds(lags, 1.0, 2.0)
'''
lag = random.paretovariate(14) - 1
range = upper_bound - lower_bound
unfiltered = lag * range + lower_bound
high_pass = max(lower_bound, unfiltered)
bounded = min(upper_bound, high_pass)
return bounded
示例8: simulate_once
def simulate_once(self):
"""Simulate once.
Return
------
This will return the amount of operational loss simulated for the
given time period.
Example:
r=OpRiskModel(stor4)
lower, mu, upper = r.simulate_many()
print "Bootstrap: ",lower,mu,upper
Output:
0.68% between 127760271.155 and 162467836.895
0.8% between 122874286.419 and 167353821.63
0.9% between 116569621.33 and 173658486.72
0.95% between 111101264.604 and 179126843.445
0.98% between 104743118.138 and 185484989.911
0.99% between 100413671.581 and 189814436.469
0.995% between 96401399.4999 and 193826708.549
0.998% between 91486833.5654 and 198741274.484
0.999% between 88010967.5982 and 202217140.451
0.9999% between 77597567.1919 and 212630540.857
0.99999% between 68459385.7079 and 221768722.341
Bootstrap: 138714608.714 145114054.025 150873917.501
"""
t=random.expovariate(self.params.lamb)
loss=0.0
while t<self.params.days:
t+=random.expovariate(self.params.lamb)
amount=self.params.xm*random.paretovariate(self.params.alpha)
loss+=amount
return loss
示例9: generate_users
def generate_users(student_count, reputation_alpha=REPUTATION_SHAPE):
role_distribution = (
('student', student_count, 0),
('staff', int(student_count * STAFF_PER_STUDENT),
REPUTATION_STAFF_SHIFT),
('other', int(student_count * OTHER_PER_STUDENT), 0),
)
users = []
i = 1
counts = dict((r, 0) for r in zip(*role_distribution)[0])
for role, n, rep_shift in role_distribution:
for _ in itertools.repeat(None, n):
reputation = math.floor(random.paretovariate(reputation_alpha))
reputation += rep_shift
user = User(id=i, role=role, reputation=reputation)
counts[role] += 1
users.append(user)
i += 1
print "User statistics: "
total = 0
for role, count in counts.items():
print " %s: %d" % (role, count)
total += count
print " total: %d" % total
return users
示例10: TallestPareto
def TallestPareto(iters=2, n=10000, xmin=100, alpha=1.7):
"""Find the tallest person in Pareto World."""
tallest = 0
for i in range(iters):
t = [xmin * random.paretovariate(alpha) for i in range(n)]
tallest = max(max(t), tallest)
return tallest
示例11: generate
def generate(num_uniques, alpha):
# generate unique lines
uniques = set()
for _ in xrange(int(num_uniques)):
s = randstr(random.randrange(1, 6))
# make sure it's actually unique
while s in uniques:
s = randstr(random.randrange(1, 6))
uniques.add(s)
uniques = list(uniques)
# make sure each unique is in there once
output = list(uniques)
# add random uniques to the output until we have enough
for _ in xrange(int(1e6) - len(uniques)):
index = int(round(random.paretovariate(alpha) -1))
index = min(index, len(uniques))
output.append(uniques[index - 1])
# shuffle so the uniques are no longer in the beginning
random.shuffle(output)
return output
示例12: pickPareto
def pickPareto(maxNum):
while True:
parNum = random.paretovariate(1) - 1
if parNum <= factor - 1:
break
n = int((parNum / (factor - 1)) * testWorldBalls) + 1
return n
示例13: simulate_once
def simulate_once(self, n_traders, a_capital, days_per_year = 365):
history = []
traders = []
# calculate day of the first jump
t_jump = random.expovariate(lambd = 1.0 / (days_per_year * 10))
for d in range(days_per_year):
# calculate jump time here, since 100% corr between all traders
jump = 0
if ceil(t_jump) == d:
# time of the jump is equal to today, jump occurs
jump = 1
# calculate next jump
t_jump += random.expovariate(lambd = 1.0 / (days_per_year * 10))
# simulate actions of each trader
for n in range(n_traders):
if len(traders) < n + 1:
# create new trader if there isn't one
starting_capital = a_capital * 1.0 / n_traders
traders.append(Trader(n, starting_capital))
trader = traders[n]
r_log_return = 0.0
if jump:
# jump occurs
r_log_return = -0.33 * random.paretovariate(alpha = 1.5)
else:
# no jump
r_log_return = random.gauss(mu = 0.0005, sigma = 0.04)
# log trader info, and add to return
trader.addLogReturn(d, r_log_return)
# add to history
day_profit = sum([t.current_capital for t in traders])
day_log = sum([t.getTotLogReturn() for t in traders])
day_arith = sum([t.getTotArithReturn() for t in traders])
day_avg_profit = day_profit / n_traders
day_avg_log = day_log / n_traders
day_avg_arith = day_arith / n_traders
history.append((d, day_profit, day_log, day_arith,
day_avg_profit, day_avg_log, day_avg_arith,
jump))
# figure out bonus amount
tot_return = sum([t.current_capital for t in traders]) - a_capital
# figure bonus, if total_return - bonus <= 0, the company
# has made no money and I assume the manager won't get their bonus
bonus = 0.01 * tot_return
if tot_return <= 0:
# if loss, no bonus recieved
bonus = 0.0
return (bonus, traders, history)
示例14: sendhttp
def sendhttp(iplist,a):
ip = iplist[random.randint(0,len(iplist)-1)]
page = int(random.paretovariate(a))
print page
url = "http://" + str(ip) + "/html/" + str(page) +".html"
c = pycurl.Curl()
c.setopt(c.URL, url)
c.perform()
示例15: main
def main(script, *args):
values = [random.expovariate(10) for i in range(1000)]
pylab.subplot(2, 1, 1)
plot_ccdf(values, 'linear', 'log')
pylab.subplot(2, 1, 2)
values = [random.paretovariate(1) for i in range(1000)]
plot_ccdf(values, 'log', 'log')
pylab.show()