本文整理汇总了Python中scipy.random.random函数的典型用法代码示例。如果您正苦于以下问题:Python random函数的具体用法?Python random怎么用?Python random使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makePoint
def makePoint():
"""Return a random point and its satellite information.
Satellite is 'blue' if point is in the circle, else 'red'."""
point = random.random((2,)) * 10
vectorLength = lambda x: dot(x.T, x)
return point, 'blue' if vectorLength(point - center) < 25 else 'red'
示例2: gen_IC
def gen_IC(sigma,rn,outfile="workfile",icdir="ICs", M=5, N=50, lapfile="Laplacian.txt", tries=10, iclist=[]):
lap = loadtxt(lapfile)
spa = sparse.csr_matrix(lap)
success=0
attempts=0
while success==0 and attempts<tries:
try:
tag='s%.2fr%.3d'%(sigma,rn)
tag=tag.replace(".", "")
parameters = [35.0, 16.0, 9.0, 0.4, 0.12, sigma]
x0=10*(random.random(2*N)-0.5)
tic=time.time()
trajectory = integrate.odeint(mimura, x0, range(0,1000), args=(parameters,spa))
print "integration took", time.time()-tic, "seconds"
x1=trajectory[-1]
sol=fsolve(mimura3, x1, args=(parameters,spa),full_output=True)
x2=sol[0]
if x2 not in iclist:
savetxt(icdir+'/init_cond_'+tag+'.txt',x2)
write_mimu(lap,par=parameters,ic=x2,outfile=outfile)
iclist.append(x2)
success=1
tries+=1
except: pass
return iclist
示例3: __init__
def __init__(self, dim, nNeurons, name=None, outputFullMap=False):
if outputFullMap:
outdim = nNeurons ** 2
else:
outdim = 2
Module.__init__(self, dim, outdim, name)
# switch modes
self.outputFullMap = outputFullMap
# create neurons
self.neurons = random.random((nNeurons, nNeurons, dim))
self.difference = zeros(self.neurons.shape)
self.winner = zeros(2)
self.nInput = dim
self.nNeurons = nNeurons
self.neighbours = nNeurons
self.learningrate = 0.01
self.neighbourdecay = 0.9999
# distance matrix
distx, disty = mgrid[0:self.nNeurons, 0:self.nNeurons]
self.distmatrix = zeros((self.nNeurons, self.nNeurons, 2))
self.distmatrix[:, :, 0] = distx
self.distmatrix[:, :, 1] = disty
示例4: __call__
def __call__(self, shape):
from scipy import random
if self.index >= len(self.cache):
self.cache += [random.random(shape)]
x = self.cache[self.index]
self.index += 1
return x
示例5: __init__
def __init__(self, input_length, hidden_length, out_lenght):
self.input_length = input_length
self.out_lenght = out_lenght
self.hidden_length = hidden_length
self.centers = []
for i in xrange(hidden_length):
self.centers.append(random.uniform(-1, 1, input_length))
self.variance = 1
self.W = random.random((self.hidden_length, self.out_lenght))
示例6: 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
示例7: ic_binary
def ic_binary(G,fr):
data={}
for n in G.nodes():
rval=random.random()
if rval <= fr:
G.node[n]['state']=1.0
data[n]=1.0
else:
data[n] = 0.0
G.node[n]['state']=0.0
return data
示例8: getAction
def getAction(self):
""" activates the module with the last observation and stores the result as last action. """
# get greedy action
action = LearningAgent.getAction(self)
# explore by chance
if random.random() < self.epsilon:
action = array([random.randint(self.module.numActions)])
# reduce epsilon
self.epsilon *= self.epsilondecay
return action
示例9: _forwardImplementation
def _forwardImplementation(self, inbuf, outbuf):
""" Draws a random number between 0 and 1. If the number is less
than epsilon, a random action is chosen. If it is equal or
larger than epsilon, the greedy action is returned.
"""
assert self.module
if random.random() < self.epsilon:
outbuf[:] = array([random.randint(self.module.numActions)])
else:
outbuf[:] = inbuf
self.epsilon *= self.decay
示例10: chenSIR
def chenSIR(graph, iIn, y, runs):
"""
In: graph,indices of an initial set of infected nodes,recovery parameter (usually ~3),total number of simulation runs
-returns the average number of infected nodes under the SIR Model specified in the
-chen 12 paper "Identifying influential nodes in complex networks"
-the recovery parameter is the average number of steps until a node
"""
sumI = 0.0
n = []
for x in range(runs):
i = []
for restock in iIn:
i.append(restock)
r = []
while len(i) > 0:
infect = -1
newI = []
newR = []
for j in i:
if random.random() < (1.0/y):
newR.append(j)
else:
n = graph.neighborss(j)
for e in r:
if e in n:
n.remove(e)
infect = int(len(n)*random.random())
if len(n) > 0:
if n[infect] not in i:
newI.append(n[infect])
for l in newR:
i.remove(l)
r.append(l)
for k in newI:
if k not in i:
i.append(k)
sumI = sumI + (len(r)*1.0)
return (sumI/(runs*1.0))
示例11: initialize
def initialize(input):
# to initialize the MLE parameters
a = random.uniform(0, 150)
b = random.uniform(0, 150)
c = random.uniform(0, 150)
miu = [
input[:, a],
input[:, b],
input[:, c],
] # set the initial mu to be the same as randomly chosen input from the original inputs
cov = [
np.matrix(np.eye(4)),
np.matrix(np.eye(4)),
np.matrix(np.eye(4)),
] # set the initial covariances to be identities
a = random.random()
b = random.random()
c = random.random()
a1 = a / a + b + c
b1 = b / a + b + c
c1 = c / a + b + c
pai = [a1, b1, c1] # set the initial pi to be three normalized random figure, and sums up to 1
return [pai, miu, cov]
示例12: 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
示例13: _forwardImplementation
def _forwardImplementation(self, inbuf, outbuf):
""" Draws a random number between 0 and 1. If the number is less
than epsilon, a random action is chosen. If it is equal or
larger than epsilon, the greedy action is returned.
"""
assert self.module
# print "Getting moves"
if random.random() < self.epsilon:
outbuf[:] = array(pyrand.sample(self.env.valid_moves, 1))
else:
outbuf[:] = inbuf
self.epsilon *= self.decay
示例14: initPopulation
def initPopulation(self):
if self.xBound is not None:
self.initBoundaries()
if self.initialPopulation is not None:
self.currentpop = self.initialPopulation
else:
self.currentpop = [self._initEvaluable]
for _ in range(self.populationSize-1):
if self.xBound is None:
self.currentpop.append(self._initEvaluable+randn(self.numParameters)
*self.mutationStdDev*self.initRangeScaling)
else:
position = rd.random(self.numParameters)
position *= (self.maxs-self.mins)
position += self.mins
self.currentpop.append(position)
示例15: _forwardImplementation
def _forwardImplementation(self, inbuf, outbuf):
""" Draws a random number between 0 and 1. If the number is less
than epsilon, a random action is chosen. If it is equal or
larger than epsilon, the greedy action is returned.
"""
assert self.module
if random.random() < self.epsilon:
#only the actions that have a Q value > -infinity are valid
actionValues = self.module.getActionValues(self.state)
#print(actionValues)
actions = [a for a in xrange(len(actionValues)) if actionValues[a] > float("-inf")]
outbuf[:] = random.choice(actions)
else:
outbuf[:] = self.module.getMaxAction(self.state)
self.epsilon *= self.decay