本文整理汇总了Python中random.gauss方法的典型用法代码示例。如果您正苦于以下问题:Python random.gauss方法的具体用法?Python random.gauss怎么用?Python random.gauss使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类random
的用法示例。
在下文中一共展示了random.gauss方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_value
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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))
示例2: _add_replicates
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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))
示例3: mutate_value
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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
示例4: data
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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)
示例5: splitter
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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
示例6: find_paste_location
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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
示例7: _fix
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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 ####
##############
示例8: gaussian_distribution
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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
示例9: __call__
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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
示例10: generate_reports
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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
示例11: check_args
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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()
示例12: gaussian
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
def gaussian(mean, sigma, trim_at_zero=True):
sample = random.gauss(mean, sigma)
if trim_at_zero:
if sample < 0:
sample *= -1
return sample
示例13: get_new_height
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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
示例14: sell_car
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
def sell_car(dealer):
car_life = random.gauss(dealer.attrs["avg_car_life"], CAR_LIFE_SIGMA)
return constrain_car_life(car_life)
示例15: get_tolerance
# 需要导入模块: import random [as 别名]
# 或者: from random import gauss [as 别名]
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