Python random.gauss() Examples

The following are 30 code examples for showing how to use random.gauss(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module random , or try the search function .

Example 1
Project: CAMISIM   Author: CAMI-challenge   File: populationdistribution.py    License: Apache License 2.0 6 votes vote down vote up
def _add_replicates(self, list_population, mu, sigma):
		"""
			Adding gaussian noise to the first drawn abundances

			@attention:

			@param list_population: Main list for all distributions
			@type : list[list[float]]
			@param mu: Mean
			@type mu: float
			@param sigma: standard deviation
			@type sigma: float

			@return: Nothing
			@rtype: None
		"""
		assert isinstance(list_population, list)
		assert isinstance(mu, (float, int, long))
		assert isinstance(sigma, (float, int, long))
		for index_p in xrange(len(list_population)):
			initial_log_distribution = list_population[index_p][0]
			for index_i in xrange(len(list_population[index_p])-1):
				list_population[index_p][index_i+1] = self.lt_zero(initial_log_distribution + random.gauss(mu, sigma)) 
Example 2
Project: neat-python   Author: CodeReclaimers   File: attributes.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def init_value(self, config):
        mean = getattr(config, self.init_mean_name)
        stdev = getattr(config, self.init_stdev_name)
        init_type = getattr(config, self.init_type_name).lower()

        if ('gauss' in init_type) or ('normal' in init_type):
            return self.clamp(gauss(mean, stdev), config)

        if 'uniform' in init_type:
            min_value = max(getattr(config, self.min_value_name),
                            (mean - (2 * stdev)))
            max_value = min(getattr(config, self.max_value_name),
                            (mean + (2 * stdev)))
            return uniform(min_value, max_value)

        raise RuntimeError("Unknown init_type {!r} for {!s}".format(getattr(config,
                                                                            self.init_type_name),
                                                                    self.init_type_name)) 
Example 3
Project: neat-python   Author: CodeReclaimers   File: attributes.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def mutate_value(self, value, config):
        # mutate_rate is usually no lower than replace_rate, and frequently higher -
        # so put first for efficiency
        mutate_rate = getattr(config, self.mutate_rate_name)

        r = random()
        if r < mutate_rate:
            mutate_power = getattr(config, self.mutate_power_name)
            return self.clamp(value + gauss(0.0, mutate_power), config)

        replace_rate = getattr(config, self.replace_rate_name)

        if r < replace_rate + mutate_rate:
            return self.init_value(config)

        return value 
Example 4
Project: hadrian   Author: modelop   File: testCart.py    License: Apache License 2.0 6 votes vote down vote up
def data():
        while True:
            x = random.uniform(0, 10)
            y = random.uniform(0, 10)
            if x < 4.0:
                if y < 6.0:
                    z = random.gauss(5, 1)
                else:
                    z = random.gauss(8, 1)
            else:
                if y < 2.0:
                    z = random.gauss(1, 1)
                else:
                    z = random.gauss(2, 1)
            if z < 0.0:
                z = 0.0
            elif z >= 10.0:
                z = 9.99999

            a = "A" + str(int(x))
            b = "B" + str(int(y/2) * 2)
            c = "C" + str(int(z/3) * 3)

            yield (x, y, z, a, b, c) 
Example 5
Project: hadrian   Author: modelop   File: hipparcos_segmented_prepare.py    License: Apache License 2.0 6 votes vote down vote up
def splitter():
    splitField = ["ra", "dec", "dist", "mag", "absmag", "x", "y", "z", "vx", "vy", "vz"][random.randint(0, 10)]
    if splitField == "ra":
        splitValue = random.uniform(1, 23)
    elif splitField == "dec":
        splitValue = random.uniform(-87, 87)
    elif splitField == "dist":
        splitValue = math.exp(random.gauss(5.5, 1))
    elif splitField == "mag":
        splitValue = random.gauss(8, 1)
    elif splitField == "absmag":
        splitValue = random.gauss(2, 2)
    elif splitField == "x":
        splitValue = math.exp(random.gauss(5, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "y":
        splitValue = math.exp(random.gauss(5, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "z":
        splitValue = math.exp(random.gauss(5, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "vx":
        splitValue = math.exp(random.gauss(-12, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "vy":
        splitValue = math.exp(random.gauss(-12, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "vz":
        splitValue = math.exp(random.gauss(-12, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    return splitField, splitValue 
Example 6
Project: hadrian   Author: modelop   File: hipparcos_numerical_prepare.py    License: Apache License 2.0 6 votes vote down vote up
def splitter():
    splitField = ["ra", "dec", "dist", "mag", "absmag", "x", "y", "z", "vx", "vy", "vz"][random.randint(0, 10)]
    if splitField == "ra":
        splitValue = random.uniform(1, 23)
    elif splitField == "dec":
        splitValue = random.uniform(-87, 87)
    elif splitField == "dist":
        splitValue = math.exp(random.gauss(5.5, 1))
    elif splitField == "mag":
        splitValue = random.gauss(8, 1)
    elif splitField == "absmag":
        splitValue = random.gauss(2, 2)
    elif splitField == "x":
        splitValue = math.exp(random.gauss(5, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "y":
        splitValue = math.exp(random.gauss(5, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "z":
        splitValue = math.exp(random.gauss(5, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "vx":
        splitValue = math.exp(random.gauss(-12, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "vy":
        splitValue = math.exp(random.gauss(-12, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    elif splitField == "vz":
        splitValue = math.exp(random.gauss(-12, 1)) * (1 if random.randint(0, 1) == 1 else -1)
    return splitField, splitValue 
Example 7
Project: stn-ocr   Author: Bartzi   File: create_svhn_dataset.py    License: GNU General Public License v3.0 6 votes vote down vote up
def find_paste_location(self, bbox, already_pasted_bboxes):

        while True:
            x_derivation = random.gauss(0, self.variance) * (self.image_size // 2)
            y_derivation = random.gauss(0, self.variance) * (self.image_size // 2)
            center = Point(x=self.image_size // 2, y=self.image_size // 2)

            bbox.left = max(min(center.x + x_derivation, self.image_size), 0)
            bbox.top = max(min(center.y + y_derivation, self.image_size), 0)

            if bbox.left + bbox.width > self.image_size:
                bbox.left = self.image_size - bbox.width
            if bbox.top + bbox.height > self.image_size:
                bbox.top = self.image_size - bbox.height

            if not any(intersects(bbox, box) for box in already_pasted_bboxes):
                return bbox 
Example 8
Project: CyberScan   Author: medbenali   File: asn1.py    License: GNU General Public License v3.0 6 votes vote down vote up
def _fix(self, n=0):
        o = random.choice(self.objlist)
        if issubclass(o, ASN1_INTEGER):
            return o(int(random.gauss(0,1000)))
        elif issubclass(o, ASN1_IPADDRESS):
            z = RandIP()._fix()
            return o(z)
        elif issubclass(o, ASN1_STRING):
            z = int(random.expovariate(0.05)+1)
            return o("".join([random.choice(self.chars) for i in range(z)]))
        elif issubclass(o, ASN1_SEQUENCE) and (n < 10):
            z = int(random.expovariate(0.08)+1)
            return o(map(lambda x:x._fix(n+1), [self.__class__(objlist=self.objlist)]*z))
        return ASN1_INTEGER(int(random.gauss(0,1000)))


##############
#### ASN1 ####
############## 
Example 9
Project: Python   Author: TheAlgorithms   File: linear_discriminant_analysis.py    License: MIT License 6 votes vote down vote up
def gaussian_distribution(mean: float, std_dev: float, instance_count: int) -> list:
    """
    Generate gaussian distribution instances based-on given mean and standard deviation
    :param mean: mean value of class
    :param std_dev: value of standard deviation entered by usr or default value of it
    :param instance_count: instance number of class
    :return: a list containing generated values based-on given mean, std_dev and
        instance_count

    >>> gaussian_distribution(5.0, 1.0, 20) # doctest: +NORMALIZE_WHITESPACE
    [6.288184753155463, 6.4494456086997705, 5.066335808938262, 4.235456349028368,
     3.9078267848958586, 5.031334516831717, 3.977896829989127, 3.56317055489747,
      5.199311976483754, 5.133374604658605, 5.546468300338232, 4.086029056264687,
       5.005005283626573, 4.935258239627312, 3.494170998739258, 5.537997178661033,
        5.320711100998849, 7.3891120432406865, 5.202969177309964, 4.855297691835079]
    """
    seed(1)
    return [gauss(mean, std_dev) for _ in range(instance_count)]


# Make corresponding Y flags to detecting classes 
Example 10
Project: training_results_v0.5   Author: mlperf   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def __call__(self, img):
        img = torch.Tensor(np.array(img))
        # Transform from HWC to CHW
        img = img.permute(2, 0 ,1)
        return img
        alpha0 = random.gauss(sigma=0.1, mu=0)
        alpha1 = random.gauss(sigma=0.1, mu=0)
        alpha2 = random.gauss(sigma=0.1, mu=0)

        channels = alpha0*self.eigval[0]*self.eigvec[0, :] + \
                   alpha1*self.eigval[1]*self.eigvec[1, :] + \
                   alpha2*self.eigval[2]*self.eigvec[2, :]
        channels = channels.view(3, 1, 1)
        img += channels

        return img 
Example 11
Project: smod-1   Author: theralfbrown   File: asn1.py    License: GNU General Public License v2.0 6 votes vote down vote up
def _fix(self, n=0):
        o = random.choice(self.objlist)
        if issubclass(o, ASN1_INTEGER):
            return o(int(random.gauss(0,1000)))
        elif issubclass(o, ASN1_IPADDRESS):
            z = RandIP()._fix()
            return o(z)
        elif issubclass(o, ASN1_STRING):
            z = int(random.expovariate(0.05)+1)
            return o("".join([random.choice(self.chars) for i in range(z)]))
        elif issubclass(o, ASN1_SEQUENCE) and (n < 10):
            z = int(random.expovariate(0.08)+1)
            return o(map(lambda x:x._fix(n+1), [self.__class__(objlist=self.objlist)]*z))
        return ASN1_INTEGER(int(random.gauss(0,1000)))


##############
#### ASN1 ####
############## 
Example 12
Project: CVE-2016-6366   Author: RiskSense-Ops   File: asn1.py    License: MIT License 6 votes vote down vote up
def _fix(self, n=0):
        o = random.choice(self.objlist)
        if issubclass(o, ASN1_INTEGER):
            return o(int(random.gauss(0,1000)))
        elif issubclass(o, ASN1_IPADDRESS):
            z = RandIP()._fix()
            return o(z)
        elif issubclass(o, ASN1_STRING):
            z = int(random.expovariate(0.05)+1)
            return o("".join([random.choice(self.chars) for i in range(z)]))
        elif issubclass(o, ASN1_SEQUENCE) and (n < 10):
            z = int(random.expovariate(0.08)+1)
            return o(map(lambda x:x._fix(n+1), [self.__class__(objlist=self.objlist)]*z))
        return ASN1_INTEGER(int(random.gauss(0,1000)))


##############
#### ASN1 ####
############## 
Example 13
Project: gvm-tools   Author: greenbone   File: random-report-gen.gmp.py    License: GNU General Public License v3.0 6 votes vote down vote up
def generate_reports(task, n_reports, with_gauss, **kwargs):
    reports = []

    if with_gauss:
        n_reports = abs(int(gauss(n_reports, 1)))
        if n_reports == 0:
            n_reports += 1

    for _ in range(n_reports):
        if with_gauss:
            n_results = abs(int(gauss(n_results, 2)))

        report_elem = generate_report_elem(task, **kwargs)
        report_elem = e.tostring(report_elem)
        reports.append(report_elem)

    return reports 
Example 14
Project: gvm-tools   Author: greenbone   File: gen-random-targets.gmp.py    License: GNU General Public License v3.0 6 votes vote down vote up
def check_args(args):
    len_args = len(args.script) - 1
    if len_args < 2:
        message = """
        This script generates random task data and feeds it to\
    a desired GSM
        It needs two parameters after the script name.

        1. <host_number> -- number of dummy hosts to select from
        2. <number>      -- number of targets to be generated

        In addition, if you would like for the number of targets generated
    to be randomized on a Gaussian distribution, add 'with-gauss'

        Example:
            $ gvm-script --gmp-username name --gmp-password pass \
    ssh --hostname <gsm> scripts/gen-random-targets.gmp.py 3 40 with-gauss
        """
        print(message)
        quit() 
Example 15
Project: mptcp-abuse   Author: Neohapsis   File: asn1.py    License: GNU General Public License v2.0 6 votes vote down vote up
def _fix(self, n=0):
        o = random.choice(self.objlist)
        if issubclass(o, ASN1_INTEGER):
            return o(int(random.gauss(0,1000)))
        elif issubclass(o, ASN1_IPADDRESS):
            z = RandIP()._fix()
            return o(z)
        elif issubclass(o, ASN1_STRING):
            z = int(random.expovariate(0.05)+1)
            return o("".join([random.choice(self.chars) for i in range(z)]))
        elif issubclass(o, ASN1_SEQUENCE) and (n < 10):
            z = int(random.expovariate(0.08)+1)
            return o(map(lambda x:x._fix(n+1), [self.__class__(objlist=self.objlist)]*z))
        return ASN1_INTEGER(int(random.gauss(0,1000)))


##############
#### ASN1 ####
############## 
Example 16
Project: indras_net   Author: gcallah   File: utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def gaussian(mean, sigma, trim_at_zero=True):
    sample = random.gauss(mean, sigma)
    if trim_at_zero:
        if sample < 0:
            sample *= -1
    return sample 
Example 17
Project: indras_net   Author: gcallah   File: height.py    License: GNU General Public License v3.0 5 votes vote down vote up
def get_new_height(self):
        """
        Calculate the height of my child.
        We use parent_height to generate reversion to the mean.
        """
        mu = (self.height + self.parent_height) / 2
        new_height = random.gauss(mu, mu / CHILD_HEIGHT_VAR)
        return new_height 
Example 18
Project: indras_net   Author: gcallah   File: dealer_factory.py    License: GNU General Public License v3.0 5 votes vote down vote up
def sell_car(dealer):
    car_life = random.gauss(dealer.attrs["avg_car_life"], CAR_LIFE_SIGMA)
    return constrain_car_life(car_life) 
Example 19
Project: indras_net   Author: gcallah   File: segregation.py    License: GNU General Public License v3.0 5 votes vote down vote up
def get_tolerance(default_tolerance, sigma):
    """
    `tolerance` measures how *little* of one's own group one will
    tolerate being among.
    """
    tol = random.gauss(default_tolerance, sigma)
    # a low tolerance number here means high tolerance!
    tol = min(tol, MAX_TOL)
    tol = max(tol, MIN_TOL)
    return tol 
Example 20
Project: CAMISIM   Author: CAMI-challenge   File: populationdistribution.py    License: Apache License 2.0 5 votes vote down vote up
def _add_timeseries_gauss(self, list_population, mu, sigma):
		"""
			Adding gaussian noise sequentially to the previous sample

			@attention:

			@param list_population: Main list for all distributions
			@type : list[list[float]]
			@param mu: Mean
			@type mu: float
			@param sigma: standard deviation
			@type sigma: float

			@return: Nothing
			@rtype: None
		"""
		assert isinstance(list_population, list)
		assert isinstance(mu, (float, int, long))
		assert isinstance(sigma, (float, int, long))
		for index_p in xrange(len(list_population)):
			for index_i in xrange(len(list_population[index_p])-1):
				if list_population[index_p][index_i] > 0:
					list_population[index_p][index_i+1] = self.lt_zero(list_population[index_p][index_i] + random.gauss(mu, sigma))
				else:
					# extinction
					list_population[index_p][index_i+1] = 0.0 
Example 21
Project: neat-python   Author: CodeReclaimers   File: cart_pole.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def noisy_continuous_actuator_force(action):
    a = action[0] + random.gauss(0, 0.2)
    return 10.0 if a > 0.5 else -10.0 
Example 22
Project: neat-python   Author: CodeReclaimers   File: cart_pole.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def noisy_discrete_actuator_force(action):
    a = action[0] + random.gauss(0, 0.2)
    return 10.0 if a > 0.5 else -10.0 
Example 23
Project: neat-python   Author: CodeReclaimers   File: evolve.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def mutate(self, config):
        super().mutate(config)
        self.discount += random.gauss(0.0, 0.05)
        self.discount = max(0.01, min(0.99, self.discount)) 
Example 24
Project: hadrian   Author: modelop   File: testKMeans.py    License: Apache License 2.0 5 votes vote down vote up
def data(*centers):
        while True:
            center, = random.sample(centers, 1)
            x = random.gauss(center[0], 1)
            y = random.gauss(center[1], 1)
            z = random.gauss(center[2], 1)
            yield (x, y, z) 
Example 25
Project: Quiver-alfred   Author: danielecook   File: sqlite_udf.py    License: MIT License 5 votes vote down vote up
def gauss_distribution(mean, sigma):
    try:
        return random.gauss(mean, sigma)
    except ValueError:
        return None 
Example 26
Project: kuryr-kubernetes   Author: openstack   File: lbaasv2.py    License: Apache License 2.0 5 votes vote down vote up
def _provisioning_timer(self, timeout,
                            interval=_LB_STS_POLL_FAST_INTERVAL):
        # REVISIT(ivc): consider integrating with Retry
        max_interval = 15
        with timeutils.StopWatch(duration=timeout) as timer:
            while not timer.expired():
                yield timer.leftover()
                interval = interval * 2 * random.gauss(0.8, 0.05)
                interval = min(interval, max_interval)
                interval = min(interval, timer.leftover())
                if interval:
                    time.sleep(interval) 
Example 27
Project: BiblioPixel   Author: ManiacalLabs   File: envelope.py    License: MIT License 5 votes vote down vote up
def _call(self, x):
        return random.gauss(self.mean, self.stdev) 
Example 28
Project: PokemonGo-Bot   Author: PokemonGoF   File: human_behaviour.py    License: MIT License 5 votes vote down vote up
def gps_noise_rng(radius):
    '''
    Simulates gps noise.
    '''
    noise = gauss(0, radius/3.0)
    noise = min(max(-radius, noise), radius)
    return noise 
Example 29
Project: lambda-packs   Author: ryfeus   File: params_ops.py    License: MIT License 5 votes vote down vote up
def Nt(mu, sigma, limit=3.0):
  """Normally distributed floating point number with truncation."""
  return min(max(random.gauss(mu, sigma), mu-limit*sigma), mu+limit*sigma)


# pylint: enable=invalid-name 
Example 30
Project: lrrbot   Author: mrphlip   File: pubsub.py    License: Apache License 2.0 5 votes vote down vote up
def _ping(self):
		timeout = 5 * 60
		while True:
			next_timeout = random.gauss(3 * timeout / 4, timeout / 8)
			next_timeout = max(1, min(next_timeout, timeout))
			log.debug("Sending a PING in %f seconds", next_timeout)
			await asyncio.sleep(next_timeout)
			log.debug("Sending a PING.")
			await self._send({
				'type': 'PING',
			})
			self.disconnect_task = asyncio.ensure_future(self._disconnect(), loop=self.loop)
			self.disconnect_task.add_done_callback(utils.check_exception)