python类normalvariate()的实例源码

test_bandit.py 文件源码 项目:embedded-jubatus-python 作者: jubatus 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test(self):
        x = Bandit(CONFIG)

        player = 'player'
        slots = {
            'a': [
                lambda: random.random() < 0.1,
                lambda: random.normalvariate(50, 10),
            ],
            'b': [
                lambda: random.random() < 0.01,
                lambda: random.normalvariate(600, 100),
            ],
            'c': [
                lambda: random.random() < 0.001,
                lambda: random.normalvariate(8000, 1000),
            ],
        }
        keys = list(slots.keys())
        for k in keys:
            self.assertTrue(x.register_arm(k))
        self.assertFalse(x.register_arm(keys[0]))
        self.assertFalse(x.reset(player))

        for _ in range(10):
            arm = x.select_arm(player)
            f0, f1 = slots[arm]
            self.assertTrue(arm in keys)
            x.register_reward(player, arm, f1() if f0() else 0.0)
        info = x.get_arm_info(player)
        self.assertEqual(3, len(info))
        self.assertTrue(isinstance(info[keys[0]], ArmInfo))

        model = x.save_bytes()
        x = Bandit(CONFIG)
        x.load_bytes(model)
        self.assertEqual(CONFIG, json.loads(x.get_config()))
        info = x.get_arm_info(player)
        self.assertEqual(3, len(info))
        self.assertTrue(isinstance(info[keys[0]], ArmInfo))
kitti_seg_input.py 文件源码 项目:KittiSeg 作者: MarvinTeichmann 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def random_resize(image, gt_image, lower_size, upper_size, sig):
    factor = random.normalvariate(1, sig)
    if factor < lower_size:
        factor = lower_size
    if factor > upper_size:
        factor = upper_size
    image = scipy.misc.imresize(image, factor)
    shape = gt_image.shape
    gt_zero = np.zeros([shape[0], shape[1], 1])
    gt_image = np.concatenate((gt_image, gt_zero), axis=2)
    gt_image = scipy.misc.imresize(gt_image, factor, interp='nearest')
    gt_image = gt_image[:, :, 0:2]/255
    return image, gt_image
simulator.py 文件源码 项目:4156project 作者: PsychicWaffle 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def bwalk(min, max, std):
    """ Generates a bounded random walk. """
    rng = max - min
    while True:
        max += normalvariate(0, std)
        yield abs((max % (rng * 2)) - rng) + min
simulator.py 文件源码 项目:4156project 作者: PsychicWaffle 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def orders(hist):
    """ Generates a random set of limit orders (time, side, price, size) from
        a series of market conditions.
    """
    for t, px, spd in hist:
        side, d  = ('sell', 2) if random() > 0.5 else ('buy', -2)
        order = round(normalvariate(px + (spd / d), spd / OVERLAP), 2)
        size  = int(abs(normalvariate(0, 100)))
        yield t, side, order, size


################################################################################
#
# Order Book
component.py 文件源码 项目:deb-python-autobahn 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def next_delay(self):
        if self.connect_attempts == 0:
            # if we never tried before, try immediately
            return 0
        elif self.connect_attempts >= self.max_retries:
            raise RuntimeError('max reconnects reached')
        else:
            self.retry_delay = self.retry_delay * self.retry_delay_growth
            self.retry_delay = random.normalvariate(self.retry_delay, self.retry_delay * self.retry_delay_jitter)
            if self.retry_delay > self.max_retry_delay:
                self.retry_delay = self.max_retry_delay
            return self.retry_delay
binary_optimization.py 文件源码 项目:binary_swarm_intelligence 作者: Sanbongawa 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def levy_flight(beta,best,est,alpha):
    sg=sigma(beta)
    u=np.random.normal(0,sg**2)
    v=abs(np.random.normal(0,1))
    step=u/pow(v,1/beta)
    step_size=alpha+step#+(step*(est-best))
    new=est+step_size#*np.random.normal()#random.normalvariate(0,sg)
    return new
binary_optimization_multi.py 文件源码 项目:binary_swarm_intelligence 作者: Sanbongawa 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def levy_flight(beta,best,est,alpha):
    sg=sigma(beta)
    u=np.random.normal(0,sg**2)
    v=abs(np.random.normal(0,1))
    step=u/pow(v,1/beta)
    step_size=alpha+step#+(step*(est-best))
    new=est+step_size#*np.random.normal()#random.normalvariate(0,sg)
    return new
Machine shop SimPy.py 文件源码 项目:salabim 作者: salabim 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def time_per_part():
    """Return actual processing time for a concrete part."""
    return random.normalvariate(PT_MEAN, PT_SIGMA)
Machine shop.py 文件源码 项目:salabim 作者: salabim 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def time_per_part():
    """Return actual processing time for a concrete part."""
    return random.normalvariate(PT_MEAN, PT_SIGMA)
Machine shop animated.py 文件源码 项目:salabim 作者: salabim 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def time_per_part():
    """Return actual processing time for a concrete part."""
    return random.normalvariate(PT_MEAN, PT_SIGMA)
crv_types.py 文件源码 项目:Python-iBeacon-Scan 作者: NikNitro 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def sample(self):
        return random.normalvariate(self.mean, self.std)
generate_testdata.py 文件源码 项目:tensorboard 作者: tensorflow 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def WriteHistogramSeries(writer, tag, mu_sigma_tuples, n=20):
  """Write a sequence of normally distributed histograms to writer."""
  step = 0
  wall_time = _start_time
  for [mean, stddev] in mu_sigma_tuples:
    data = [random.normalvariate(mean, stddev) for _ in xrange(n)]
    histo = _MakeHistogram(data)
    summary = tf.Summary(value=[tf.Summary.Value(tag=tag, histo=histo)])
    event = tf.Event(wall_time=wall_time, step=step, summary=summary)
    writer.add_event(event)
    step += 10
    wall_time += 100
corporate_bullshit.py 文件源码 项目:corporate_bullshit 作者: franciscouzo 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def sentences():
    ret = []
    for _ in xrange(max(3, int(random.normalvariate(30, 10)))):
        ret.append(sentence())
    return " ".join(ret)
protocol.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def retry(self, connector=None):
        """
        Have this connector connect again, after a suitable delay.
        """
        if not self.continueTrying:
            if self.noisy:
                log.msg("Abandoning %s on explicit request" % (connector,))
            return

        if connector is None:
            if self.connector is None:
                raise ValueError("no connector to retry")
            else:
                connector = self.connector

        self.retries += 1
        if self.maxRetries is not None and (self.retries > self.maxRetries):
            if self.noisy:
                log.msg("Abandoning %s after %d retries." %
                        (connector, self.retries))
            return

        self.delay = min(self.delay * self.factor, self.maxDelay)
        if self.jitter:
            self.delay = random.normalvariate(self.delay,
                                              self.delay * self.jitter)

        if self.noisy:
            log.msg("%s will retry in %d seconds" % (connector, self.delay,))

        def reconnector():
            self._callID = None
            connector.connect()
        if self.clock is None:
            from twisted.internet import reactor
            self.clock = reactor
        self._callID = self.clock.callLater(self.delay, reconnector)
lines.py 文件源码 项目:tcnc 作者: utlco 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def spacing_jitter_scale(self):
        """
        """
        mu = 0
        sigma = 0.4
        jitter = random.normalvariate(mu, sigma)
        return jitter * self.spacing_jitter
personality.py 文件源码 项目:talktown 作者: james-owen-ryan 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _determine_personality_feature(self, feature_type):
        """Determine a value for a Big Five personality trait."""
        config = self.person.sim.config
        feature_will_get_inherited = (
            self.person.biological_mother and
            random.random() < config.big_five_heritability_chance[feature_type]
        )
        if feature_will_get_inherited:
            # Inherit this trait (with slight variance)
            takes_after = random.choice([self.person.biological_father, self.person.biological_mother])
            feature_value = random.normalvariate(
                self._get_a_persons_feature_of_type(person=takes_after, feature_type=feature_type),
                config.big_five_inheritance_sd[feature_type]
            )
        else:
            takes_after = None
            # Generate from the population mean
            feature_value = random.normalvariate(
                config.big_five_mean[feature_type], config.big_five_sd[feature_type]
            )
        if feature_value < config.big_five_floor:
            feature_value = config.big_five_floor
        elif feature_value > config.big_five_cap:
            feature_value = config.big_five_cap
        feature_object = Feature(value=feature_value, inherited_from=takes_after)
        return feature_object
mind.py 文件源码 项目:talktown 作者: james-owen-ryan 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _init_ex_nihilo_memory(self):
        """Determine this person's base memory capability."""
        config = self.person.sim.config
        memory = random.normalvariate(config.memory_mean, config.memory_sd)
        if self.person.male:  # Men have slightly worse memory (studies show)
            memory -= config.memory_sex_diff
        if memory > config.memory_cap:
            memory = config.memory_cap
        elif memory < config.memory_floor:
            memory = config.memory_floor
        feature_object = Feature(value=memory, inherited_from=None)
        return feature_object
dns-queue.py 文件源码 项目:dns-parallel-prober 作者: lorenzog 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def run(self):
        # sleep for a small amount of time, between 0.1 and 0.9
        _sleep_for = abs(random.normalvariate(0.5, 0.5))
        log.debug("Mock probe {} sleeping for {}...".format(self.name, _sleep_for))
        time.sleep(_sleep_for)
        print("Mock prober {} done".format(self.name))
rosenbrock_function.py 文件源码 项目:csa 作者: structurely 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def probe(solution, tgen):
    sigma = 100 * tgen
    probe_solution = []
    for x in solution:
        probe_solution.append(x + random.normalvariate(0, sigma))
    return probe_solution
test_rosenbrock.py 文件源码 项目:csa 作者: structurely 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def probe(solution, tgen):
    sigma = 100 * tgen
    probe_solution = []
    for x in solution:
        probe_solution.append(x + random.normalvariate(0, sigma))
    return probe_solution


问题


面经


文章

微信
公众号

扫码关注公众号