本文整理汇总了Python中random.gauss函数的典型用法代码示例。如果您正苦于以下问题:Python gauss函数的具体用法?Python gauss怎么用?Python gauss使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gauss函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
def execute(self, userdata):
self.world.inc_time()
if self.world.time_step >= self.experiment.max_transitions:
return "timeout"
newx = random.gauss(self.mu_x, self.si_x)
newy = random.gauss(self.mu_y, self.si_y)
newth = random.gauss(self.mu_th, self.si_th)
#denormalizing the network output
# lx = self.world.min_x
# rx = self.world.max_x
# ly = self.world.min_y
# ry = self.world.max_y
lx = 0
rx = 5
ly = -2.5
ry = 2.5
lt = -math.pi
rt = math.pi
newpos = (lx + newx *(rx-lx),
ly + newy *(ry-ly),
lt + newth *(rt-lt))
if self.world.move_robot(newpos):
return "success"
else:
return "failure"
示例2: move
def move(self, motion): # Do not change the name of this function
# ADD CODE HERE
alpha = random.gauss(motion[0], self.steering_noise) #steering angle
distance = motion[1] + random.gauss(0, self.distance_noise) #Distance moved
theta = self.orientation #Orientation of the robot
beta = distance / self.length * tan(alpha)
result = robot(self.length)
result.set(self.x, self.y, self.orientation)
result.set_noise(bearing_noise, steering_noise, distance_noise)
if beta > 0.001:
radius = distance / beta
cx = self.x - sin(theta) * radius
cy = self.y + cos(theta) * radius
result.x = cx + (sin(theta + beta) * radius)
result.y = cy - (cos(theta + beta) * radius)
theta = (theta + beta) % (2 * pi)
result.orientation = theta
else:
result.x = self.x + distance * cos(theta)
result.y = self.y + distance * sin(theta)
result.orientation = (theta + beta) % 2 * pi
return result
示例3: move
def move(self, motion): # Do not change the name of this function
(alpha, distance) = motion # alpha = lenkwinkel
alpha += random.gauss(0., self.steering_noise)
distance += random.gauss(0., self.distance_noise)
# see https://www.udacity.com/course/viewer#!/c-cs373/l-48726342/m-48693619
b = distance/self.length * tan(alpha) # turning angle
if b < 0.001:
x = self.x + distance * cos(self.orientation)
y = self.y + distance * sin(self.orientation)
o = self.orientation
else:
radius = distance / b
cx = self.x - sin(self.orientation) * radius
cy = self.y + cos(self.orientation) * radius
x = cx + sin(self.orientation + b) * radius
y = cy - cos(self.orientation + b) * radius
o = (self.orientation + b) % (2*pi)
result = robot()
result.set(x, y, o)
result.set_noise(self.bearing_noise, self.steering_noise, self.distance_noise)
return result # make sure your move function returns an instance
示例4: __init__
def __init__(self, world, space, pos, color, capsules, radius, mass=2, fixed=False, orientation=v(1, 0, 0, 0)):
"capsules is a list of (start, end) points"
self.capsules = capsules
self.body = ode.Body(world)
self.body.setPosition(pos)
self.body.setQuaternion(orientation)
m = ode.Mass()
# computing MOI assuming sphere with .5 m radius
m.setSphere(mass/(4/3*math.pi*.5**3), .5) # setSphereTotal is broken
self.body.setMass(m)
self.geoms = []
self.geoms2 = []
for start, end in capsules:
self.geoms.append(ode.GeomTransform(space))
x = ode.GeomCapsule(None, radius, (end-start).mag())
self.geoms2.append(x)
self.geoms[-1].setGeom(x)
self.geoms[-1].setBody(self.body)
x.setPosition((start+end)/2 + v(random.gauss(0, .01), random.gauss(0, .01), random.gauss(0, .01)))
a = (end - start).unit()
b = v(0, 0, 1)
x.setQuaternion(sim_math_helpers.axisangle_to_quat((a%b).unit(), -math.acos(a*b)))
self.color = color
self.radius = radius
if fixed:
self.joint = ode.FixedJoint(world)
self.joint.attach(self.body, None)
self.joint.setFixed()
示例5: run
def run(self):
sim_bam = pysam.Samfile(self.out + ".bam", "wb", header=TEST_HEADER)
# Randomly generate number from 2 to value normalized for genomic region for N value
read_range = xrange(2, self.total_reads / 500)
# pdb.set_trace()
mid_position = self.initial_mid_position
count = 0
total_reads = self.total_reads
while total_reads > 0:
N = random.sample(read_range, 1)[0]
total_reads = total_reads - N
while N > 0:
count = count + 1
N = N - 1
# Introduce jitter
tmp_mid_position = int(round(mid_position + random.uniform(-1, 1) * self.jitter))
isize = int(round(random.gauss(145, self.insert_sd)))
positions = ((tmp_mid_position - (isize / 2), isize), (tmp_mid_position + (isize / 2), -isize))
# Construct/write paired AlignedReads
for position in positions:
read = construct_read(count, 0, position[0], position[1], position[1] > 0)
sim_bam.write(read)
# Advance position by 300
advance = self.advance
if self.jitter_advance > 0:
advance = int(round(random.gauss(advance, self.jitter_advance)))
mid_position = mid_position + advance
sim_bam.close()
示例6: update
def update(self, velX, velY):
#Don't update after a crash
#if self.crashed:
# return
velY -= gravity
#Update true position
#True velocity is intentional accel + random force accel
self.posX += self.velX + random.gauss(0, self.randomForce)
self.posY += self.velY + random.gauss(0, self.randomForce)
self.velX = velX
self.velY = velY
sensorX = self.posX + random.gauss(0,self.sensorNoise)
sensorY = self.posY + random.gauss(0,self.sensorNoise)
#update naive estimated position
self.posXEst = sensorX
self.posYEst = sensorY
self.kalman(timeUpdate, sensorX, sensorY)
#Crash if we hit the ground
if self.posY < 0:
self.crashed = True
self.logGT.log(self.posX, self.posY)
self.logEst.log(self.posXEst, self.posYEst)
self.logKal.log(self.x[0], self.x[1])
self.time += 1
self.printValues()
示例7: initial
def initial(average):
a=[0 for i in range(2*NP+2)]
for i in range(0,2*NP):
a[i]=average[i]+random.gauss(0.0,0.1)
for i in range(2):
a[2*NP+i]=2.8+random.gauss(0.0,0.2)
return a
示例8: get_cuckoo
def get_cuckoo(nests, best_nest, Lb, Ub, nest_number,nd,stepsize, percentage):
import math
import scipy.special
import random
#Mantegna's Algorithm
alpha = 1.5 #flexible parameter but this works well. Also need to plug in decimal form
sigma=(scipy.special.gamma(1+alpha)*math.sin(math.pi*alpha/2)/(scipy.special.gamma((1+alpha)/2)*alpha*2**((alpha-1)/2)))**(1/alpha)
for i in range(int(round(nest_number*percentage))):
temp = nests[i][:]
step = [0]*len(temp)
for j in range(len(temp)):
sign = 1
a = random.gauss(0,1)*sigma
b = random.gauss(0,1)
if a < 0:
sign = -1
step[j] = sign*stepsize[j]*((abs(a)/abs(b))**(1/alpha))*(temp[j]-best_nest[j])
temp[j] = round(temp[j]+step[j]*random.gauss(0,1),3)
#check to see if new solution is within bounds
if temp[j] <= Lb[j]:
temp[j] = Lb[j]
elif temp[j] >= Ub[j]:
temp[j] = Ub[j]
#!!!we need second parameter to be larger than first. If conditions like these are necessary, change this section to
#!!!needed conditions. Otherwise remove or comment out.
if j == 1 and temp[j] < temp[0]:
coin = random.randint(0,1)
if coin == 0:
temp[0] = round(random.uniform(Lb[0],temp[j]),3)
else:
temp[j] = round(random.uniform(temp[0],Ub[j]),3)
nests[i][:] = temp
return nests
示例9: compute_random_cut_off
def compute_random_cut_off(self):
desired_v_removed = int(gauss(len(self.V) / 2, len(self.V)/6))
while desired_v_removed >= len(self.V) - self.threshold or desired_v_removed < self.threshold:
desired_v_removed = int(gauss(len(self.V) / 2, len(self.V)/6))
ratio = 1
estimate_block_size = int(((len(self.L) - self.received_count) / (len(self.V) - self.threshold)) * ratio)
return estimate_block_size * desired_v_removed + randint(0, estimate_block_size) - self.received_count
示例10: logPokemonDb
def logPokemonDb(p):
pokemon_id = int(p['pokemon_data']['pokemon_id'])
pokemon_name = get_pokemon_name(str(pokemon_id)).lower().encode('ascii','ignore')
last_modified_time = int(p['last_modified_timestamp_ms'])
time_until_hidden_ms = int(p['time_till_hidden_ms'])
hidden_time_unix_s = int((p['last_modified_timestamp_ms'] + p['time_till_hidden_ms']) / 1000.0)
hidden_time_utc = datetime.utcfromtimestamp(hidden_time_unix_s)
encounter_id = str(p['encounter_id'])
spawnpoint_id = str(p['spawn_point_id'])
longitude = float(p['longitude'])
latitude = float(p['latitude'])
longitude_jittered = longitude + (random.gauss(0, 0.3) - 0.5) * 0.0005
latitude_jittered = latitude + (random.gauss(0, 0.3) - 0.5) * 0.0005
#query = "INSERT INTO spotted_pokemon (name, encounter_id, last_modified_time, time_until_hidden_ms, hidden_time_unix_s, hidden_time_utc, spawnpoint_id, longitude, latitude, pokemon_id, longitude_jittered, latitude_jittered) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);"
query = "INSERT INTO spotted_pokemon (name, encounter_id, last_modified_time, time_until_hidden_ms, hidden_time_unix_s, hidden_time_utc, spawnpoint_id, longitude, latitude, pokemon_id, longitude_jittered, latitude_jittered) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON CONFLICT (encounter_id) DO UPDATE SET last_modified_time = EXCLUDED.last_modified_time, time_until_hidden_ms = EXCLUDED.time_until_hidden_ms, hidden_time_unix_s = EXCLUDED.hidden_time_unix_s, hidden_time_utc = EXCLUDED.hidden_time_utc;"
data = (pokemon_name, encounter_id, last_modified_time, time_until_hidden_ms, hidden_time_unix_s, hidden_time_utc, spawnpoint_id, longitude, latitude, pokemon_id, longitude_jittered, latitude_jittered)
try:
cursor.execute(query, data)
except Exception,e:
log.error('Postgresql error (%s)', str(e))
示例11: move
def move(self, motion): # Do not change the name of this function
alpha = random.gauss(motion[0], sqrt(self.steering_noise))
d = random.gauss(motion[1], sqrt(self.distance_noise))
beta = (d / self.length) * tan(alpha)
if(beta >= abs(0.001)):
R = d / beta
cx = self.x - sin(self.orientation) * R
cy = self.y + cos(self.orientation) * R
x = cx + sin(self.orientation + beta) * R
y = cy - cos(self.orientation + beta) * R
orientation = (self.orientation + beta) % (2*pi)
else:
x = self.x + d * cos(self.orientation)
y = self.y + d * sin(self.orientation)
orientation = (self.orientation + beta) % (2*pi)
result = robot(self.length)
result.set(x, y, orientation)
result.set_noise(self.bearing_noise, self.steering_noise, self.distance_noise)
return result
示例12: move
def move(self, motion, tol = 0.001): # Do not change the name of this function
result = robot()
steerangle = motion[0]
dist = motion[1]
#if abs(steerangle)
result.length = self.length
result.bearing_noise = self.bearing_noise
result.steering_noise = self.steering_noise
steerangle +=random.gauss(0.0, self.steering_noise)
steerangle %= (2*pi)
result.distance_noise = self.distance_noise
dist += random.gauss(0.0, self.distance_noise)
beta = dist / self.length * tan(steerangle)
if abs(beta)<= tol:
result.x = self.x + dist * cos(self.orientation)
result.y = self.y + dist * sin(self.orientation)
result.orientation = (self.orientation + beta ) % (2.0 *pi)
else:
R = dist / beta
cx = self.x - R * sin(self.orientation)
cy = self.y + R * cos(self.orientation)
result.orientation = (self.orientation + beta) % (2*pi)
result.x = cx + sin(beta + self.orientation) * R
result.y = cy - cos(beta + self.orientation) * R
return result # make sure your move function returns an instance
示例13: move
def move(self, robot, steering, distance,
tolerance = 0.001, max_steering_angle = pi / 4.0):
if steering > max_steering_angle:
steering = max_steering_angle
if steering < -max_steering_angle:
steering = -max_steering_angle
if distance < 0.0:
distance = 0.0
# apply noise
steering2 = random.gauss(steering, self.steering_noise)
distance2 = random.gauss(distance, self.distance_noise)
# Execute motion
turn = tan(steering2) * distance2 / self.length
if abs(turn) < tolerance:
# approximate by straight line motion
x = robot.pos.x + (distance2 * cos(robot.orientation))
y = robot.pos.y + (distance2 * sin(robot.orientation))
orientation = (robot.orientation + turn) % (2.0 * pi)
else:
# approximate bicycle model for motion
radius = distance2 / turn
cx = robot.pos.x - (sin(robot.orientation) * radius)
cy = robot.pos.y + (cos(robot.orientation) * radius)
orientation = (robot.orientation + turn) % (2.0 * pi)
x = cx + (sin(orientation) * radius)
y = cy - (cos(orientation) * radius)
return (x,y,orientation)
示例14: GaussLk
def GaussLk( self, newLkFile, sigma ) :
fout = open( newLkFile, "w" )
fout.write("# input data : %s\n" % "+ Gaussian error" )
percentU = percentQ = 0.
for lineStr,f1,f2 in zip (self.LeakList[0].lineStr, self.LeakList[0].f1, self.LeakList[0].f2) :
print lineStr
fout.write("#\n")
for ant in range(1,16) :
DRlist = []
DLlist = []
for Lk in self.LeakList :
if Lk.ant == ant :
for lineStr1,DR1,DL1 in zip( Lk.lineStr, Lk.DR, Lk.DL ) :
if (lineStr1 == lineStr) and (abs(DR1) > 0.) and (abs(DL1) > 0.) :
DRlist.append( DR1 )
DLlist.append( DL1 )
print "... ant %d - appending data from %s" % ( ant, Lk.legend )
if len(DRlist) > 0 :
DRmean = numpy.mean(DRlist)
DLmean = numpy.mean(DLlist)
DRnew = random.gauss(numpy.real(DRmean), sigma) + random.gauss(numpy.imag(DRmean), sigma) * 1j
DLnew = random.gauss(numpy.real(DLmean), sigma) + random.gauss(numpy.imag(DLmean), sigma) * 1j
else :
DRnew = 0. + 0j
DLnew = 0. + 0j
print ant, DRnew, DLnew
fout.write("C%02d %8.3f %8.3f %8.3f %6.3f %8.3f %6.3f %8.3f %6.3f %s\n" % \
( ant, f1, f2, DRnew.real, DRnew.imag, DLnew.real, \
DLnew.imag, percentQ, percentU, lineStr) )
fout.close()
示例15: __init__
def __init__(self, name="anonymous goblin", **kwargs):
"""creates a new goblin instance
every attribute can be overwritten with an argument like
g = Goblin(attack = 33.2)
this will overwrite the random self.attack attribute with 33.2
"""
self.name = name
self.attack = random.gauss(Config.attack, 2) # float values
self.defense = random.gauss(Config.defense, 2)
# always create an goblin with twice the "normal" hitpoints
# to make him cost real money
self.hitpoints = random.gauss(Config.hitpoints*2, 3)
self.fullhealth = self.hitpoints
self.defense_penalty = 0 # integer value
self.sleep = False # boolean
#statistics
self.damage_dealt = 0
self.damage_received = 0
self.victory = 0 # over all rounds
self.streak = 0 # victories in this combat
self.lastround = 0 # number of combatround whre goblin lost
self.lost = 0
self.fights = 0
# overwrite attributes if keywords were passed as arguments
for key in kwargs:
self.__setattr__(key, kwargs[key])
# but do not mess around with number
self.number = Goblin.number # access class attribute
Goblin.number += 1 # prepare class attribute for next goblin
# calculate value based on averages described in class Config
self.value = self.calculate_value()