当前位置: 首页>>代码示例>>Python>>正文


Python random.random函数代码示例

本文整理汇总了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'
开发者ID:Angeliqe,项目名称:pybrain,代码行数:7,代码来源:lsh.py

示例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
开发者ID:sideshownick,项目名称:Sources,代码行数:29,代码来源:make_function_runfile.py

示例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
开发者ID:Angeliqe,项目名称:pybrain,代码行数:25,代码来源:kohonen.py

示例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
开发者ID:adocherty,项目名称:polymode,代码行数:8,代码来源:Solver.py

示例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))
开发者ID:gdl-civestav-localization,项目名称:cinvestav_location_fingerprinting,代码行数:9,代码来源:rbf.py

示例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
开发者ID:Boblogic07,项目名称:pybrain,代码行数:10,代码来源:mogpuremax.py

示例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
开发者ID:sideshownick,项目名称:NetWorks,代码行数:11,代码来源:functions.py

示例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
开发者ID:HKou,项目名称:pybrain,代码行数:13,代码来源:egreedy.py

示例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
开发者ID:Angeliqe,项目名称:pybrain,代码行数:13,代码来源:egreedy.py

示例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))
开发者ID:viralTipping,项目名称:viralTipping,代码行数:38,代码来源:viral.py

示例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]
开发者ID:May-tree,项目名称:MachineLearningAlgs,代码行数:23,代码来源:EM.py

示例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
开发者ID:Angeliqe,项目名称:pybrain,代码行数:14,代码来源:mixtureofgaussian.py

示例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
开发者ID:minorl,项目名称:hackcu,代码行数:14,代码来源:hackedexplorer.py

示例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)
开发者ID:jeepq,项目名称:pybrain,代码行数:16,代码来源:ga.py

示例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
开发者ID:jaegs,项目名称:AI_Practicum,代码行数:17,代码来源:egreedy.py


注:本文中的scipy.random.random函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。