本文整理汇总了Python中scipy.random.normal函数的典型用法代码示例。如果您正苦于以下问题:Python normal函数的具体用法?Python normal怎么用?Python normal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: g
def g():
d = len(Mu)
assert Mu.shape == (d,), "Mu must be a vector"
assert A.shape == (d, d), "A must be a square matrix"
assert (A.T == A).all(), "and symmetric"
assert V.shape == (d, d), "V must be a square matrix"
assert (V.T == V).all(), "and symmetric"
a = chol(A)
v = chol(V)
B = dot(V, inv(V + A))
_a2 = V - dot(B, V)
_a2 = chol(_a2)
Y, U = array([0.0] * d), array([0.0] * d)
for i in range(n + burnin):
for _ in range(thin): # skipe
# sample Y | U ~ N(U, V)
Y = U + dot(v, random.normal(size=d))
# sample U | Y ~ N(A(A+V)^-1)(Y-Mu) + Mu,
# A - A(A+V)^-1A)
U = dot(B, (Mu - Y)) + Y + +dot(_a2, random.normal(size=d))
if i >= burnin:
yield [U, Y]
示例2: testRewardFunction
def testRewardFunction(self, x, typ, noise=0.000001):
if typ == "growSin":
return (sin((x - self.rangeMin) / 3.0) + 1.5 + x / self.distRange) / 4.0 + random.normal(0, noise)
if typ == "rastrigin":
n = x / self.distRange * 10.0
if abs(n) > 5.0: n = 0.0
# FIXME: imprecise reimplementation of the Rastrigin function that exists already
# in rl/environments/functions...
return (20.0 + n ** 2 - 10.0 * cos(2.0 * 3.1416 * n)) / 55.0 + random.normal(0, noise)
if typ == "singleGaus":
return self.getStND(x) + random.normal(0, noise)
return 0.0
示例3: quadthermo_agent_gen
def quadthermo_agent_gen():
targetT=spr.normal(18,2)
tolerance=2
absmax=max(spr.normal(21,1),targetT+tolerance) #no support
absmin=min(spr.gamma(4,1),targetT-tolerance) #no support
vec=[0.0,0.21,0.135,0.205,0.115,0.115,0.095,0.065,0.03,0.03]
r=sp.random.uniform()
nres=1
i=0
while i<7 and r>vec[i]:
r-=vec[i]
i+=1
nres=i+1
occ=active.get_occ_p(nres)
cons=[]
for p in occ:
p.extend([targetT,tolerance])
cons.append(p)
q=sp.exp(sp.random.normal(-9.3,2.0))
fa=28.39+sp.random.gamma(shape=2.099,scale=28.696) #floor area from cabe dwelling survey
flat=sp.random.uniform(0,1)<0.365 # flat or house
if flat:
U = 3.3*sp.sqrt(fa) #insulation in W/K floor area
else:
U= 3.6*sp.sqrt(fa)+0.14*fa
k=U #insulation in W/K
cm=1000*sp.exp(sp.random.normal(5.5,0.35)) #thermal capacity in J
P=sp.random.uniform(6000,15000)# power in W
Prequ=k*20
if Prequ>P:
print "!!!!!!!!!!!"
s=str(["quadthermo_agent",absmax,absmin,cons,q,P,cm,k])
return s
示例4: newEpisode
def newEpisode(self):
if self.learning:
params = ravel(self.explorationlayer.module.params)
target = ravel(sum(self.history.getSequence(self.history.getNumSequences()-1)[2]) / 500)
if target != 0.0:
self.gp.addSample(params, target)
if len(self.gp.trainx) > 20:
self.gp.trainx = self.gp.trainx[-20:, :]
self.gp.trainy = self.gp.trainy[-20:]
self.gp.noise = self.gp.noise[-20:]
self.gp._calculate()
# get new parameters where mean was highest
max_cov = diag(self.gp.pred_cov).max()
indices = where(diag(self.gp.pred_cov) == max_cov)[0]
pick = indices[random.randint(len(indices))]
new_param = self.gp.testx[pick]
# check if that one exists already in gp training set
if len(where(self.gp.trainx == new_param)[0]) > 0:
# add some normal noise to it
new_param += random.normal(0, 1, len(new_param))
self.explorationlayer.module._setParameters(new_param)
else:
self.explorationlayer.drawRandomWeights()
# don't call StateDependentAgent.newEpisode() because it randomizes the params
LearningAgent.newEpisode(self)
示例5: main
def main():
ITERATIONS = 100
mc = zeros(ITERATIONS)
og = zeros(ITERATIONS)
#farby =
QS = 10
colors = [
[0, 0, 0],
[0, 0, 1],
[0, 1, 0],
[1, 0, 0],
[0, 1, 1],
[1, 0, 1],
[0, 1, 1],
]
for qpre in range(QS):
q = qpre + 2
for it in range(ITERATIONS):
W = random.normal(0, 0.1, [q, q])
WI = random.uniform(-.1, .1, [q, 1])
mc[it] = sum(memory_capacity(W, WI, memory_max=200, runs=1, iterations_coef_measure=5000)[0][:q+2])
og[it] = matrix_orthogonality(W)
print(qpre, QS, it, ITERATIONS)
plt.scatter(og, mc, marker='+', label=q, c=(colors[qpre % len(colors)]))
plt.xlabel("orthogonality")
plt.ylabel("memory capacity")
plt.grid(True)
plt.legend()
plt.show()
开发者ID:pe-ge,项目名称:Computational-analysis-of-memory-capacity-in-echo-state-networks,代码行数:35,代码来源:ovmc.py
示例6: drop_object
def drop_object(self):
"""Drops a random object (box, sphere) into the scene."""
# choose between boxes and spheres
if random.uniform() > 0.5:
(body, geom) = self._create_sphere(self.space, 10, 0.4)
else:
(body, geom) = self._create_box(self.space, 10, 0.5, 0.5, 0.5)
# randomize position slightly
body.setPosition((random.normal(-6.5, 0.5), 6.0, random.normal(-6.5, 0.5)))
# body.setPosition( (0.0, 3.0, 0.0) )
# randomize orientation slightly
#theta = random.uniform(0,2*pi)
#ct = cos (theta)
#st = sin (theta)
# rotate body and append to (body,geom) tuple list
# body.setRotation([ct, 0., -st, 0., 1., 0., st, 0., ct])
self.body_geom.append((body, geom))
示例7: GaussianRandomInitializer
def GaussianRandomInitializer(gridShape, sigma=0.2, seed=None, slipSystem=None, slipPlanes=None, slipDirections=None, vacancy=None, smectic=None):
oldgrid = copy.copy(gridShape)
if len(gridShape) == 1:
gridShape = (128,)
if len(gridShape) == 2:
gridShape = (128,128)
if len(gridShape) == 3:
gridShape = (128,128,128)
""" Returns a random initial set of fields of class type PlasticityState """
if slipSystem=='gamma':
state = SlipSystemState.SlipSystemState(gridShape,slipPlanes=slipPlanes,slipDirections=slipDirections)
elif slipSystem=='betaP':
state = SlipSystemBetaPState.SlipSystemState(gridShape,slipPlanes=slipPlanes,slipDirections=slipDirections)
else:
if vacancy is not None:
state = VacancyState.VacancyState(gridShape,alpha=vacancy)
elif smectic is not None:
state = SmecticState.SmecticState(gridShape)
else:
state = PlasticityState.PlasticityState(gridShape)
field = state.GetOrderParameterField()
Ksq_prime = FourierSpaceTools.FourierSpaceTools(gridShape).kSq * (-sigma**2/4.)
if seed is None:
seed = 0
n = 0
random.seed(seed)
Ksq = FourierSpaceTools.FourierSpaceTools(gridShape).kSq.numpy_array()
for component in field.components:
temp = random.normal(scale=gridShape[0],size=gridShape)
ktemp = fft.rfftn(temp)*(sqrt(pi)*sigma)**len(gridShape)*exp(-Ksq*sigma**2/4.)
field[component] = numpy.real(fft.irfftn(ktemp))
#field[component] = GenerateGaussianRandomArray(gridShape, temp ,sigma)
n += 1
"""
t, s = LoadState("2dstate32.save", 0)
for component in field.components:
for j in range(0,32):
field[component][:,:,j] = s.betaP[component].numpy_array()
"""
## To make seed consistent across grid sizes and convergence comparison
gridShape = copy.copy(oldgrid)
if gridShape[0] != 128:
state = ResizeState(state,gridShape[0],Dim=len(gridShape))
state = ReformatState(state)
state.ktools = FourierSpaceTools.FourierSpaceTools(gridShape)
return state
示例8: keplerSim
def keplerSim(tau, e, T0, K, w, sig, tlo, thi, n):
dt = (thi-tlo)/(n-1)
data = zeros((n,2), Float)
data[:,0] = r.uniform(tlo, thi, (n))
# for i in range(n):
# data[i,0] = tlo + i*dt
data[:,1] = v_rad(K, w, tau, e, T0, data[:,0])+r.normal(0.,sig,(n))
print "Created data."
return data
示例9: perturbation
def perturbation(self):
""" Generate a difference vector with the given standard deviations """
#print self.sigList
#print "_*_*_*_*_*_*_*_"
#raw_input("Press Enter to continue")
#time.sleep(3)
return random.normal(0., self.sigList)
示例10: drawSample
def drawSample(self):
sum = 0.0
rndFakt = random.random()
for g in range(self.numOGaus):
sum += self.sigmo(self.alpha[g])
if rndFakt < sum:
if self.sigma[g] < self.minSig: self.sigma[g] = self.minSig
x = random.normal(self.mue[g], self.sigma[g])
break
return x
示例11: fill_region
def fill_region(l,r,sigma,v):
if (l == r or l == r-1):
pass
else:
m = int(round((r+l)*0.5))
a = v[l] + (v[r]-v[l])*(m - l)/float(r - l)
s = sigma*sqrt((m-l)*(r-m)/float(r-l))
v[m] = a + s * random.normal()
fill_region(l,m,sigma,v)
fill_region(m,r,sigma,v)
示例12: add_noise
def add_noise(self, temp):
"""
Add per-pixel Gaussian random noise.
"""
self.noise = random.normal(0,temp,[self.npix,self.npix])
self.Fnoise = ft.fftshift(ft.fft2(self.noise))
self.Txy = self.Txy + self.noise
self.Fxy = ft.fftshift(ft.fft2(self.Txy))
self.Clnoise = ((temp*self.mapsize_rad/self.npix)*self.Bl)**-2.e0
self.Pknoise = np.interp(self.modk, self.k, self.Clnoise)
示例13: generate_data
def generate_data(N=100, true_params=secret_true_params,
seed = 42):
x = np.linspace(-2.5, 2.5, N)
y1 = my_model(x, *true_params)
y2 = 1.0 * random.normal(size=N)
# Create the data
data = np.array([x,y1+y2]).T
# Shuffle the data
permuted_data = random.permutation(data)
# Save the data
np.savetxt("dataN%d.txt"%N, data)
return data
示例14: __init__
def __init__(self, statedim, actiondim, sigma= -2.):
Explorer.__init__(self, actiondim, actiondim)
self.statedim = statedim
self.actiondim = actiondim
# initialize parameters to sigma
ParameterContainer.__init__(self, actiondim, stdParams=0)
self.sigma = [sigma] * actiondim
# exploration matrix (linear function)
self.explmatrix = random.normal(0., expln(self.sigma), (statedim, actiondim))
# store last state
self.state = None
示例15: drawSample
def drawSample(self, dm):
sum = 0.0
rndFakt = random.random()
if dm == "max":
for g in range(self.numOGaus):
sum += self.sigmo(self.alpha[g])
if rndFakt < sum:
if self.sigma[g] < self.minSig: self.sigma[g] = self.minSig
x = random.normal(self.mue[g], self.sigma[g])
break
return x
if dm == "dist":
return rndFakt * self.distRange + self.rangeMin
return 0.0