Python random.gauss() Examples
The following are 30
code examples of random.gauss().
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 also want to check out all available functions/classes of the module
random
, or try the search function
.

Example #1
Source File: attributes.py From neat-python with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #2
Source File: utils.py From training_results_v0.5 with Apache License 2.0 | 6 votes |
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 #3
Source File: linear_discriminant_analysis.py From Python with MIT License | 6 votes |
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 #4
Source File: asn1.py From CyberScan with GNU General Public License v3.0 | 6 votes |
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 #5
Source File: asn1.py From smod-1 with GNU General Public License v2.0 | 6 votes |
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 #6
Source File: hipparcos_numerical_prepare.py From hadrian with Apache License 2.0 | 6 votes |
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
Source File: hipparcos_segmented_prepare.py From hadrian with Apache License 2.0 | 6 votes |
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 #8
Source File: testCart.py From hadrian with Apache License 2.0 | 6 votes |
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 #9
Source File: attributes.py From neat-python with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #10
Source File: asn1.py From CVE-2016-6366 with MIT License | 6 votes |
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 #11
Source File: create_svhn_dataset.py From stn-ocr with GNU General Public License v3.0 | 6 votes |
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 #12
Source File: random-report-gen.gmp.py From gvm-tools with GNU General Public License v3.0 | 6 votes |
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 #13
Source File: gen-random-targets.gmp.py From gvm-tools with GNU General Public License v3.0 | 6 votes |
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 #14
Source File: populationdistribution.py From CAMISIM with Apache License 2.0 | 6 votes |
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 #15
Source File: asn1.py From mptcp-abuse with GNU General Public License v2.0 | 6 votes |
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
Source File: volatile.py From CVE-2016-6366 with MIT License | 5 votes |
def _fix(self): return int(round(random.gauss(self.mu, self.sigma)))
Example #17
Source File: BatAlgorithm.py From BatAlgorithm with MIT License | 5 votes |
def move_bat(self): S = [[0.0 for i in range(self.D)] for j in range(self.NP)] self.init_bat() for t in range(self.N_Gen): for i in range(self.NP): rnd = np.random.uniform(0, 1) self.Q[i] = self.Qmin + (self.Qmax - self.Qmin) * rnd for j in range(self.D): self.v[i][j] = self.v[i][j] + (self.Sol[i][j] - self.best[j]) * self.Q[i] S[i][j] = self.Sol[i][j] + self.v[i][j] S[i][j] = self.simplebounds(S[i][j], self.Lb[j], self.Ub[j]) rnd = np.random.random_sample() if rnd > self.r: for j in range(self.D): S[i][j] = self.best[j] + 0.001 * random.gauss(0, 1) S[i][j] = self.simplebounds(S[i][j], self.Lb[j], self.Ub[j]) Fnew = self.Fun(self.D, S[i]) rnd = np.random.random_sample() if (Fnew <= self.Fitness[i]) and (rnd < self.A): for j in range(self.D): self.Sol[i][j] = S[i][j] self.Fitness[i] = Fnew if Fnew <= self.f_min: for j in range(self.D): self.best[j] = S[i][j] self.f_min = Fnew print(self.f_min)
Example #18
Source File: dgsn_simulator.py From orbitdeterminator with MIT License | 5 votes |
def calc(self): """Calculates the satellite state at current time and calls itself after a certain amount of time.""" interval = random.randint(1,self.period) calc_period = max(0,interval/self.speed) self.calc_thr = threading.Timer(calc_period, self.calc) self.calc_thr.start() self.t += interval self.s = propagate_state(self.s,self.t0,self.t) self.t0 = self.t r = self.s[0:3] r[0] += random.gauss(0,self.r_jit) r[1] += random.gauss(0,self.r_jit) r[2] += random.gauss(0,self.r_jit) #r[0] += random.uniform(-self.r_jit,self.r_jit) #r[1] += random.uniform(-self.r_jit,self.r_jit) #r[2] += random.uniform(-self.r_jit,self.r_jit) if self.dgsn_omega is not None: prob = abs(np.cos(self.dgsn_omega*self.t)) if (prob >= self.dgsn_thresh): self.op_writer.write(self.t,r) else: self.op_writer.write(self.t0,r)
Example #19
Source File: bandwagonAttack.py From SDLib with GNU General Public License v3.0 | 5 votes |
def getSelectedItems(self): mu = int(self.selectedSize * len(self.itemProfile)) sigma = int(0.1 * mu) markedItemsCount = abs(int(round(random.gauss(mu, sigma)))) markedIndexes = np.random.randint(len(self.hotItems), size=markedItemsCount) markedItems = [self.hotItems[index][0] for index in markedIndexes] return markedItems
Example #20
Source File: bandwagonAttack.py From SDLib with GNU General Public License v3.0 | 5 votes |
def getFillerItems(self): mu = int(self.fillerSize*len(self.itemProfile)) sigma = int(0.1*mu) markedItemsCount = int(round(random.gauss(mu, sigma))) if markedItemsCount < 0: markedItemsCount = 0 markedItems = np.random.randint(len(self.itemProfile), size=markedItemsCount) return markedItems
Example #21
Source File: volatile.py From smod-1 with GNU General Public License v2.0 | 5 votes |
def _fix(self): return int(round(random.gauss(self.mu, self.sigma)))
Example #22
Source File: predix_example.py From thingflow-python with Apache License 2.0 | 5 votes |
def sample(self): if self.events_remaining>0: self.events_remaining -= 1 return random.gauss(100, 5) else: raise StopIteration
Example #23
Source File: attack.py From SDLib with GNU General Public License v3.0 | 5 votes |
def getFillerItems(self): mu = int(self.fillerSize*len(self.itemProfile)) sigma = int(0.1*mu) markedItemsCount = abs(int(round(random.gauss(mu, sigma)))) markedItems = np.random.randint(len(self.itemProfile), size=markedItemsCount) return markedItems.tolist()
Example #24
Source File: session.py From okcupyd with MIT License | 5 votes |
def wait(self): if self.rate_limit is None: return if self.last_request is not None: wait_time = random.gauss(self.rate_limit, self.wait_std_dev) elapsed = time.time() - self.last_request if elapsed < wait_time: time.sleep(wait_time - elapsed) self.last_request = time.time()
Example #25
Source File: generate_graph.py From clevr-graph with The Unlicense | 5 votes |
def gen_n(base, noise = 0.2): return base return round(random.gauss(base, noise*base))
Example #26
Source File: benchmark.py From signac with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _make_job(project, num_keys, num_doc_keys, data_size, data_std, i): size = max(0, int(random.gauss(data_size, data_std))) job = project.open_job(_make_doc(i, num_keys, size)) if num_doc_keys > 0: size = max(0, int(random.gauss(data_size, data_std))) job.document.update(_make_doc(i, num_doc_keys, size)) else: job.init()
Example #27
Source File: models.py From Dallinger with MIT License | 5 votes |
def perturbed_contents(self): """Perturb the given animal.""" animal = json.loads(self.contents) for prop, prop_range in self.properties.items(): range = prop_range[1] - prop_range[0] jittered = animal[prop] + random.gauss(0, 0.1 * range) animal[prop] = max(min(jittered, prop_range[1]), prop_range[0]) return json.dumps(animal)
Example #28
Source File: poisson_disc.py From xy with MIT License | 5 votes |
def poisson_disc(x1, y1, x2, y2, r, n): grid = Grid(r) active = [] for i in range(1): x = x1 + random.random() * (x2 - x1) y = y1 + random.random() * (y2 - y1) x = (x1 + x2) / 2.0 y = (y1 + y2) / 2.0 a = random.random() * 2 * pi if grid.insert(x, y): active.append((x, y, a, 0, 0, i)) pairs = [] while active: ax, ay, aa, ai, ad, ag = record = choice(active) for i in range(n): # a = random.random() * 2 * pi a = aa + (random.random() - 0.5) * max_angle(ai, ad) # a = random.gauss(aa, pi / 8) d = random.random() * r + r x = ax + cos(a) * d y = ay + sin(a) * d if x < x1 or y < y1 or x > x2 or y > y2: continue if ad + d > 150: continue pair = ((ax, ay), (x, y)) line = LineString(pair) if not grid.insert(x, y, line): continue pairs.append(pair) active.append((x, y, a, ai + 1, ad + d, ag)) active.sort(key=lambda x: -x[4]) # if random.random() < 0.5: # active.remove(record) break else: active.remove(record) return grid.points.values(), pairs
Example #29
Source File: test_ops_nn.py From ngraph-python with Apache License 2.0 | 5 votes |
def test_convolution_nchw_no_pad_no_bias(): workspace.ResetWorkspace() # shape is in NCHW format # [batch, input_feature_map, spatial, output_feature_map, kernel, stride] n, ifm, spatial, ofm, kernel, stride = [2, 3, 8, 1, 2, 2] shape_x = (n, ifm, spatial, spatial) shape_w = (ofm, ifm, kernel, kernel) shape_b = (ofm,) data_x = [random.gauss(mu=0, sigma=10) for i in range(np.prod(shape_x))] data_w = [random.gauss(mu=0, sigma=10) for i in range(np.prod(shape_w))] data_b = [0. for i in range(np.prod(shape_b))] net = core.Net("net") X = net.GivenTensorFill([], ["X"], shape=shape_x, values=data_x, name="X") W = net.GivenTensorFill([], ["W"], shape=shape_w, values=data_w, name="W") B = net.GivenTensorFill([], ["B"], shape=shape_b, values=data_b, name="B") net.Conv([X, W, B], 'Y', kernel=kernel, stride=stride, order='NCHW') # Execute via Caffe2 workspace.RunNetOnce(net) # Import caffe2 network into ngraph importer = C2Importer() importer.parse_net_def(net.Proto(), verbose=False) # Get handle f_ng = importer.get_op_handle("Y") # Execute with ExecutorFactory() as ex: f_result = ex.executor(f_ng)() # compare Caffe2 and ngraph results assert (np.allclose(f_result, workspace.FetchBlob("Y"), atol=1e-4, rtol=1e-3, equal_nan=False))
Example #30
Source File: test_ops_nn.py From ngraph-python with Apache License 2.0 | 5 votes |
def test_convolution_nhwc_no_pad_no_bias(): workspace.ResetWorkspace() # shape is in NCHW format # [batch, input_feature_map, spatial, output_feature_map, kernel, stride] n, ifm, spatial, ofm, kernel, stride = [2, 3, 8, 1, 2, 2] shape_x = (n, spatial, spatial, ifm) shape_w = (ofm, kernel, kernel, ifm) shape_b = (ofm, ) data_x = [random.gauss(mu=0, sigma=10) for i in range(np.prod(shape_x))] data_w = [random.gauss(mu=0, sigma=10) for i in range(np.prod(shape_w))] data_b = [0. for i in range(np.prod(shape_b))] net = core.Net("net") X = net.GivenTensorFill([], ["X"], shape=shape_x, values=data_x, name="X") W = net.GivenTensorFill([], ["W"], shape=shape_w, values=data_w, name="W") B = net.GivenTensorFill([], ["B"], shape=shape_b, values=data_b, name="B") net.Conv([X, W, B], 'Y', kernel=kernel, stride=stride, order='NHWC') # Execute via Caffe2 workspace.RunNetOnce(net) # Import caffe2 network into ngraph importer = C2Importer() importer.parse_net_def(net.Proto(), verbose=False) # Get handle f_ng = importer.get_op_handle("Y") # Execute with ExecutorFactory() as ex: f_result = ex.executor(f_ng)() # compare Caffe2 and ngraph results assert(np.allclose(f_result, workspace.FetchBlob("Y"), atol=1e-4, rtol=1e-3, equal_nan=False))