• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python random.random函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scipy.random.random函数的典型用法代码示例。如果您正苦于以下问题:Python random函数的具体用法?Python random怎么用?Python random使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了random函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: make

def make(**kw):
    step, noise, decay = [float(kw[k]) for k in ['--step','--noise','--decay']]
    X, Y = [int(kw[k]) for k in ['--width', '--height']]
    H = X/2

    gray = ones((Y,X),dtype=float)
    for x in range(H):
        dI = step * exp(-decay*float(H-x))
        gray[:,0+x+0] += dI
        gray[:,X-x-1] -= dI

    scatter = ((random.random((Y,X))*2)-1) * noise
    image = (gray+scatter)*127

    saved = fromarray(image)
    name = 'egray/egray.s.%f.n.%f.d.%f.gif' % (step, noise, decay)
    saved.save(name)
    toimage(saved)
开发者ID:jlettvin,项目名称:NoisyGrayStep,代码行数:18,代码来源:egray.py


示例17: run

    def run(self):
        raw_file = open('res_sirs.txt', 'w+')
        #same as while I > 0
        while len(self.iAgentList) > 0:
            tempIAgentList = []
            newI = 0

            for iAgent in self.iAgentList:
                for agent in self.adjacencyList[iAgent]:
                    if agent in self.sAgentList:
                        if random.random() < self.b:
                            newI += self.infectAgent(agent)
                            tempIAgentList.append(agent)

            # then get the list of who is recovering
            recoverList = self.recoverAgents()
            susceptibleList = self.susceptibleAgent()
            # for recoveries
            for recoverAgent in recoverList:
                self.iAgentList.remove(recoverAgent)
                self.rAgentList.append(recoverAgent)
                self.susAgent(recoverAgent)

            for susceptibleAgent in susceptibleList:
                self.rAgentList.remove(susceptibleAgent)
                self.sAgentList.append(susceptibleAgent)

            self.iAgentList.extend(tempIAgentList)

            self.sList.append(len(self.sAgentList))
            self.iList.append(len(self.iAgentList))
            self.rList.append(len(self.sAgentList))
            self.newIList.append(newI)


            self.t += 1

            print('t', self.t, 'numS', len(self.sAgentList), 'numI', len(self.iAgentList), 'numR', len(self.rAgentList))
            raw_file.write(str(self.t) + ' ' + str(len(self.sAgentList)) + ' ' + str(len(self.iAgentList)) +
                           ' ' + str(len(self.rAgentList)) + '\n')

            random.shuffle(self.iAgentList)

        return [self.sList, self.iList, self.rList, self.newIList]
开发者ID:raihan2108,项目名称:urban_hw2,代码行数:44,代码来源:sirs.py


示例18: make

def make(**kw):
    step  = kw.get( 'step', 3e-2)
    scale = kw.get('scale', 3e-1)
    shape = (Y, X) = [kw.get(edge, 512) for edge in ['Y', 'X']]
    X0, X1, X2, X3 = 0, X/2-1, X/2, X-1

    gray = ones(shape, dtype=float)
    gray[:,X0:X1] -= step
    gray[:,X2:X3] += step

    noise = ((random.random((Y,X))*2)-1) * scale

    image = (gray+noise)*127
    print gray.max(), noise.max(), image.max()
    print gray.min(), noise.min(), image.min()

    saved = fromarray(image)
    name = 'gray/gray.step.%f.scale.%f.gif' % (step, scale)
    print name
    saved.save(name)
开发者ID:jlettvin,项目名称:NoisyGrayStep,代码行数:20,代码来源:gray.py


示例19: __init__

    def __init__(self, shape=(10, 20), spacing=(1., 1.), origin=(0., 0.),
                 alpha=1.):
        """Create a new heat model.

        Paramters
        ---------
        shape : array_like, optional
            The shape of the solution grid as (*rows*, *columns*).
        spacing : array_like, optional
            Spacing of grid rows and columns.
        origin : array_like, optional
            Coordinates of lower left corner of grid.
        alpha : float
            Alpha parameter in the heat equation.
        """
        self._shape = shape
        self._spacing = spacing
        self._origin = origin
        self._time = 0.
        self._alpha = alpha
        self._time_step = min(spacing) ** 2 / (4. * self._alpha)

        self._temperature = random.random(self._shape)
        self._next_temperature = np.empty_like(self._temperature)
开发者ID:katmratliff,项目名称:bmi-python,代码行数:24,代码来源:heat.py


示例20: _forwardImplementation

 def _forwardImplementation(self, inbuf, outbuf):
     outbuf[:] = inbuf <= random.random(inbuf.shape)
开发者ID:HKou,项目名称:pybrain,代码行数:2,代码来源:samplelayer.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python random.seed函数代码示例发布时间:2022-05-27
下一篇:
Python random.normal函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap