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

Python random.paretovariate函数代码示例

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

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



在下文中一共展示了paretovariate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:kand,项目名称:depaul-csc521,代码行数:52,代码来源:final.py


示例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))
开发者ID:JaimieMurdock,项目名称:ants,代码行数:14,代码来源:cell_maze.py


示例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
开发者ID:jfinkels,项目名称:numbertiles,代码行数:14,代码来源:model.py


示例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
开发者ID:bsmith89,项目名称:mgs,代码行数:7,代码来源:make_pops.py


示例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
开发者ID:mitchjcarlson,项目名称:simulating-network-traffic,代码行数:27,代码来源:simulation.py


示例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
开发者ID:ethankennerly,项目名称:hotel-vs-gozilla,代码行数:27,代码来源:mock_client.py


示例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
开发者ID:PeterMalkin,项目名称:fin2py,代码行数:34,代码来源:finance.py


示例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
开发者ID:tfleish,项目名称:caesar-web,代码行数:26,代码来源:task_simulation.py


示例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
开发者ID:VinGorilla,项目名称:thinkstats,代码行数:7,代码来源:pareto_world.py


示例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
开发者ID:alemic,项目名称:luajit-talk,代码行数:27,代码来源:generate_data.py


示例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
开发者ID:alex-kozik,项目名称:atgc-xyz,代码行数:7,代码来源:BallTest_IvanK_Modified_2005_09_27.py


示例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)
开发者ID:kand,项目名称:depaul-csc521,代码行数:59,代码来源:hw4.py


示例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()
开发者ID:neoalvin,项目名称:HTTP-Client,代码行数:8,代码来源:http_client.py


示例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()
开发者ID:giovannipbonin,项目名称:thinkComplexity,代码行数:8,代码来源:plotCcdf.py


示例16: pareto

def pareto():
    PARETO_USAGE = 'Usage: ' + url_for('.pareto') + '?alpha=&lt;integer&gt;[k=&lt;integer&gt;&amp;test=true|false]'

    func = lambda args: random.paretovariate(alpha=float(args['alpha'])) + float(request.args.get('k'))

    alpha = request.args.get('alpha')

    return get_response(request, PARETO_USAGE, func, None, alpha=alpha)
开发者ID:CloudScale-Project,项目名称:Response-Generator,代码行数:8,代码来源:server.py


示例17: workload_generator

def workload_generator():
    workload = []
    random.seed(RANDOM_SEED)
    for i in range(WORKLOAD_LENGTH):
        t = random.paretovariate(2)-1
        if t > 3:
            t = 3
        workload.append(int(t/3*100*1000))
    return workload
开发者ID:hfx1991818,项目名称:cpufreq-interactive-opt,代码行数:9,代码来源:20170721-1-8T-0.18.py


示例18: next_vehicle

 def next_vehicle(self):
     vehicle = Vehicle()
     vehicle.lane = self.lane
     vehicle.v0 = random.gauss(vehicle.v0, 4.)
     vehicle.th0 = vehicle.th0 + random.paretovariate(3.)
     vehicle.a = random.gauss(vehicle.a, 0.05)
     vehicle.b = random.gauss(vehicle.b, 0.05)
     vehicle.p = random.gauss(0.5, 0.3)
     return vehicle
开发者ID:brianbreitsch,项目名称:pyidmsim,代码行数:9,代码来源:simulation.py


示例19: ParetovariateTest

def ParetovariateTest():
	results = []
	a=1
	xm=0.5
	for i in range(1000):
		results.append(random.paretovariate(a)*xm)
	cdf = Cdf.MakeCdfFromList(results)
	myplot.Clf()
	myplot.Cdf(cdf,complement=True,xscale = 'log',yscale = 'log')
	myplot.show()
开发者ID:elephantzhai,项目名称:Learn,代码行数:10,代码来源:chapter04.py


示例20: next_point

def next_point(prev,ALPHA):
    angle = random.uniform(0,(2*math.pi))
#    angle = random.normalvariate(0,1.8)
    distance = 2 * random.paretovariate(ALPHA)/1100
#    distance = 2 * random.weibullvariate(1.0, 0.9)
    # cap distance at DMAX
#    if distance > DMAX:
#        distance = DMAX
    point = ((math.sin(angle) * distance)+prev[0], (math.cos(angle) * distance)+prev[1])
    return point
开发者ID:shawu810,项目名称:attraction-avoidance-plus,代码行数:10,代码来源:levy.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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