本文整理汇总了Python中random.gauss函数的典型用法代码示例。如果您正苦于以下问题:Python gauss函数的具体用法?Python gauss怎么用?Python gauss使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gauss函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"
开发者ID:lorenzoriano,项目名称:Graph-Evolve,代码行数:31,代码来源:smach_explore.py
示例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
开发者ID:primalpop,项目名称:olc_spring,代码行数:25,代码来源:hw3-6.py
示例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
开发者ID:tyunkeow,项目名称:raspi_python,代码行数:28,代码来源:problem_set3_3.py
示例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()
开发者ID:pchojecki,项目名称:RobotX,代码行数:33,代码来源:sim_rendering_helpers.py
示例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()
开发者ID:hjanime,项目名称:seqAnalysis,代码行数:33,代码来源:readMidDistances.py
示例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()
开发者ID:jacobjenks,项目名称:CSCI532,代码行数:33,代码来源:kalman2.py
示例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
开发者ID:julywater,项目名称:WeakLensing,代码行数:7,代码来源:betappy4.py
示例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
开发者ID:AidenWang,项目名称:RIPS2014-HKO,代码行数:33,代码来源:CuckooSearch_forSWIRLS_multi_latterTimes.py
示例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
开发者ID:LukeusMaximus,项目名称:shadow-p2p,代码行数:7,代码来源:variable_modify_t.py
示例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))
开发者ID:Axelfowlie,项目名称:pogom,代码行数:27,代码来源:postgres.py
示例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
开发者ID:nebw,项目名称:CS373,代码行数:25,代码来源:impl.py
示例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
开发者ID:ouceduxzk,项目名称:AI_NN,代码行数:32,代码来源:ps_particle.py
示例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)
开发者ID:franciscodominguezmateos,项目名称:pyRobot2D,代码行数:27,代码来源:Kinematics.py
示例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()
开发者ID:richardplambeck,项目名称:tadpol,代码行数:30,代码来源:ooLeak.py
示例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()
开发者ID:Aces77,项目名称:ThePythonGameBook,代码行数:31,代码来源:slowgoblins020.py
示例16: move
def move(self, motion): # Do not change the name of this function
# ADD CODE HERE
if motion[1] < 0:
raise ValueError, 'Robot cannot move backwards'
# move, and add randomness to the motion command
dist = float(motion[1]) + random.gauss(0.0, self.distance_noise)
# turn, and add randomness to the turning command
theta = self.orientation + random.gauss(0.0, self.bearing_noise)
alpha = float(motion[0]) + random.gauss(0.0, self.steering_noise)
alpha %= 2 * pi
beta = tan(alpha) * dist / float(self.length)
if beta < 0.001:
x = self.x + dist * cos(theta)
y = self.y + dist * sin(theta)
theta = theta + beta
else:
r = dist / beta
cx = self.x - r * sin(theta)
cy = self.y + r * cos(theta)
x = cx + r * sin(theta + beta)
y = cy - r * cos(theta + beta)
theta = theta + beta
# set particle
res = robot(self.length)
res.set(x, y, theta)
res.set_noise(self.bearing_noise, self.steering_noise, self.distance_noise)
return res # make sure your move function returns an instance
开发者ID:ThomasTilli,项目名称:Artificial_Intelligence_for_Robots,代码行数:35,代码来源:robot+steering.py
示例17: resample_particles
def resample_particles(self):
""" Resample the particles according to the new particle weights.
The weights stored with each particle should define the probability that a particular
particle is selected in the resampling step. You may want to make use of the given helper
function draw_random_sample.
"""
#Primeiro de tudo, normalizar particulas
self.normalize_particles()
#Criar array do numpy vazia do tamanho do numero de particulas.
values = np.empty(self.n_particles)
#Preencher essa lista com os indices das particulas
for i in range(self.n_particles):
values[i] = i
#Criar uma lista para novas particulas
new_particles = []
#Criar lista com os indices das particulas com mais probabilidade
random_particles = ParticleFilter.weighted_values(values,[p.w for p in self.particle_cloud],self.n_particles)
for i in random_particles:
#Transformar o I em inteiro para corrigir bug de float
int_i = int(i)
#Pegar particula na possicao I na nuvem de particulas.
p = self.particle_cloud[int_i]
#Adicionar particulas somando um valor aleatorio da distribuicao gauss com media = 0 e desvio padrao = 0.025
new_particles.append(Particle(x=p.x+gauss(0,.025),y=p.y+gauss(0,.025),theta=p.theta+gauss(0,.025)))
#Igualar nuvem de particulas a novo sample criado
self.particle_cloud = new_particles
#Normalizar mais uma vez as particulas.
self.normalize_particles()
开发者ID:MarceloHarad,项目名称:robotica16,代码行数:35,代码来源:pf.py
示例18: move
def move(self, motion):
a = random.gauss(motion[0], self.steering_noise)
d = random.gauss(motion[1], self.distance_noise)
b = (d * tan(a)) / self.length
new_orientation = (b + self.orientation) % (2 * pi)
if b > 0.001:
r = d / b
cx = self.x - r * sin(self.orientation)
cy = self.y + r * cos(self.orientation)
new_x = cx + r * sin(new_orientation)
new_y = cy - r * cos(new_orientation)
else:
new_x = self.x + d * cos(new_orientation)
new_y = self.y + d * sin(new_orientation)
res = robot()
res.x = new_x
res.y = new_y
res.orientation = new_orientation
res.length = self.length
res.bearing_noise = self.bearing_noise
res.steering_noise = self.steering_noise
res.distance_noise = self.distance_noise
return res
开发者ID:zelca,项目名称:udacity-cs373-exercises,代码行数:28,代码来源:particle-filters.py
示例19: move
def move(self, motion):
# obtain steering angle and distance forward
steering = random.gauss(motion[0], self.steering_noise)
distance = random.gauss(motion[1], self.distance_noise)
# compute turning angle
turning_angle = distance / self.length * tan(steering)
if turning_angle < 0.001:
# approximate by straight line motion
new_x = self.x + (distance * cos(self.orientation))
new_y = self.y + (distance * sin(self.orientation))
new_orientation = (self.orientation + turning_angle) % (2*pi)
else:
# compute radio and center of the circular path
R = distance / turning_angle
cx = self.x - (R*sin(self.orientation))
cy = self.y + (R*cos(self.orientation))
new_x = cx + (R*sin(self.orientation+turning_angle))
new_y = cy - (R*cos(self.orientation+turning_angle))
new_orientation = (self.orientation + turning_angle) % (2*pi)
# copy values to the new robot
result = robot()
result.length = self.length
result.set(new_x, new_y, new_orientation)
result.set_noise(self.bearing_noise, self.steering_noise, self.distance_noise)
return result
开发者ID:mmmarcos,项目名称:cs373,代码行数:31,代码来源:task.py
示例20: move
def move(self, motion): # Do not change the name of this function
theta = self.orientation
length = self.length
x = self.x
y = self.y
alpha, d = motion;
alphar = random.gauss(alpha, self.steering_noise)
dr = random.gauss(d, self.distance_noise)
alpha = alphar
d = dr
beta = (d/length)*tan(alpha)
if (abs(beta) > 0.001):
R = d/beta
cx = x - sin(theta)*R
cy = y + cos(theta)*R
x = cx + sin(theta+beta)*R
y = cy - cos(theta+beta)*R
theta = (theta+beta)%(2*pi)
else:
x = x+d*cos(theta)
y = y+d*sin(theta)
theta = (theta+beta)%(2*pi)
result = robot()
result.set_noise(self.bearing_noise, self.steering_noise, self.distance_noise)
result.set(x,y,theta)
return result # make sure your move function returns an instance
开发者ID:Qworg,项目名称:cs373,代码行数:29,代码来源:task.py
注:本文中的random.gauss函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论