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


Python scipy.argmax函数代码示例

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


在下文中一共展示了argmax函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw

    def draw(self):
        """
        if sample_priors = True and random_sample = True:
           draw returns a random draw of a categorical distribution with parameters drawn from a Dirichlet distribution
           the hyperparameters on the Dirichlet are given by the bandit's metric with laplacian smoothing
        if sample_priors = False and random_sample = True:
            draw returns a random draw of a categorical distribution with parameters given by the bandit's metric
        if sample_priors = True and random_sample = False:
            draw returns argmax(random.dirichlet((x_0 + 1, ... , x_n_arms + 1))) where x_i is the ith value returned by
            the bandit's metric.
        if sample_priors = False and random_sample = False:
            become a purely greedy bandit with the selected arm given by argmax(metric)

        :return: The numerical index of the selected arm
        """
        temp = self._schedule_fn(self.total_draws)
        x = array(self._metric_fn()) * temp + 1

        if self.sample_priors:
            pvals = random.dirichlet(x)
        else:
            pvals = x / sum(x)

        if self.random_sample:
            return argmax(random.multinomial(1, pvals=pvals))
        else:
            return argmax(pvals)
开发者ID:beegieb,项目名称:MultiArmedBandits,代码行数:27,代码来源:algorithms.py

示例2: testPercentErrorIsSame

	def testPercentErrorIsSame(self):
		NN.pat = zip(self.trn_d['input'], self.trn_d['target'])		
		pyb_ws = self.net.params.copy()
		nn = NN()
		nn.wi = pyb_ws[:nn.wi.size].reshape(NN.nh, NN.ni).T
		nn.wo = pyb_ws[nn.wi.size:].reshape(NN.no, NN.nh).T
		correct = 0
		wrong = 0
		argmax_cor = 0
		argmax_wng = 0
		all_aos = []
		for i, x in enumerate(self.trn_d['input']):
			nn.activate(x)
			out = self.net.activate(x)
			# print 'ga bp trg', nn.ao, out, self.trn_d['target'][i], '++++' if not (out - self.trn_d['target'][i]).any() else '-'
			all_aos.append(nn.ao.copy())
			if not (out - self.trn_d['target'][i]).any():
				correct += 1
			else:
				wrong += 1
			if argmax(out) == argmax(self.trn_d['target'][i]):
				argmax_cor += 1
			else:
				argmax_wng += 1
		print 'actual', wrong, 'wrong', correct, 'correct', float(wrong) / (wrong + correct) * 100
		print 'using argmax', argmax_wng, 'wrong', argmax_cor, 'correct', float(argmax_wng) / (argmax_wng + argmax_cor) * 100
		argmax_perc_err = float(argmax_wng) / (argmax_wng + argmax_cor) * 100
		res = nn.sumErrors()
		nn_perc_err = 100 - res[1]
		pb_nn_perc_err = percentError(self.trainer.testOnClassData(), self.trn_d['class'])
		self.assertAlmostEqual(nn_perc_err, pb_nn_perc_err)
		self.assertAlmostEqual(nn_perc_err, pb_nn_perc_err, argmax_perc_err)
开发者ID:mfbx9da4,项目名称:neuron-astrocyte-networks,代码行数:32,代码来源:testmain.py

示例3: plot_disc_policy

def plot_disc_policy():
    #First compute policy function...==========================================
    N = 500
    w = sp.linspace(0,100,N)
    w = w.reshape(N,1)
    u = lambda c: sp.sqrt(c)
    util_vec = u(w)
    alpha = 0.5
    alpha_util = u(alpha*w)
    alpha_util_grid = sp.repeat(alpha_util,N,1)
    
    m = 20
    v = 200
    f = discretelognorm(w,m,v)
    
    VEprime = sp.zeros((N,1))
    VUprime    = sp.zeros((N,N))
    EVUprime = sp.zeros((N,1))
    psiprime = sp.ones((N,1))
    gamma = 0.1
    beta = 0.9
    
    m = 15
    tol = 10**-9
    delta = 1+tol
    it = 0
    while (delta >= tol):
        it += 1
        
        psi = psiprime.copy()
        arg1 = sp.repeat(sp.transpose(VEprime),N,0)
        arg2 = sp.repeat(EVUprime,N,1)
        arg = sp.array([arg2,arg1])
        psiprime = sp.argmax(arg,axis = 0) 
        
        for j in sp.arange(0,m):
            VE = VEprime.copy()
            VU = VUprime.copy()
            EVU = EVUprime.copy()
            VEprime = util_vec + beta*((1-gamma)*VE + gamma*EVU)
            arg1 = sp.repeat(sp.transpose(VE),N,0)*psiprime
            arg2 = sp.repeat(EVU,N,1)*(1-psiprime)
            arg = arg1+arg2
            VUprime = alpha_util_grid + beta*arg
            EVUprime = sp.dot(VUprime,f)  
    
        
    
        delta = sp.linalg.norm(psiprime -psi) 

    wr_ind = sp.argmax(sp.diff(psiprime), axis = 1)
    wr = w[wr_ind]
    print w[250],wr[250]
        
    #Then plot=================================================================
    plt.plot(w,psiprime[250,:]) 
    plt.ylim([-.5,1.5])      
    plt.xlabel(r'$w\prime$')
    plt.yticks([0,1])
    plt.savefig('disc_policy.pdf')
开发者ID:byuimpactrevisions,项目名称:numerical_computing,代码行数:60,代码来源:job_plots.py

示例4: bandpower

def bandpower(f, Pxx, fmin, fmax):
    """ integrate the power spectral density between fmin and fmax
        using the trapezoidal method
    """
    ind_min = scipy.argmax(f > fmin) - 1
    ind_max = scipy.argmax(f > fmax) - 1
    return scipy.trapz(Pxx[ind_min: ind_max], f[ind_min: ind_max])
开发者ID:bwrc,项目名称:midas-nodes,代码行数:7,代码来源:ecg_utilities.py

示例5: plot_REL_ERR_SU2

 def plot_REL_ERR_SU2(self,which_case):
      i=0;
      thermo1 = self.select[which_case][0]
      thermo2 = self.select[which_case][1]
      get_REL_ERR_SU2(self,which_case)
      
      print 'Median error SU2', sp.median(self.REL_ERR)
      print 'Mean error SU2', sp.mean(self.REL_ERR)
      print 'Max error SU2', max(self.REL_ERR)
      print 'Min error SU2', min(self.REL_ERR)
      x = getattr(self.SU2[which_case],thermo1)
      y = getattr(self.SU2[which_case],thermo2)
      #trusted_values = sp.where(self.REL_ERR>0<0.9*max(self.REL_ERR))
      self.REL_ERR = self.REL_ERR[trusted_values]
      x = x[trusted_values]
      y = y[trusted_values]
      scat=plt.scatter(x,y,c=self.REL_ERR, s=1)                
      plt.grid(which='both')
      scat.set_array(self.REL_ERR)        
      plt.colorbar(scat)
      plt.xlim((min(x)*0.95,max(x)*1.05));
      plt.ylim((min(y)*0.95,max(y)*1.05));
      print 'x argmax %i , x_val: %f ' %(sp.argmax(self.REL_ERR),x[sp.argmax(self.REL_ERR)])
      print 'y argmax %i , y_val: %f ' %(sp.argmax(self.REL_ERR),y[sp.argmax(self.REL_ERR)])
      return;
开发者ID:MatejKosec,项目名称:LUTStandAlone,代码行数:25,代码来源:ConvergenceLibrary.py

示例6: error

    def error(self, results, expected):

        err = 0
        for i in range(results.shape[1]):

            err += self.lsexp(results[:, i]) - sp.dot(expected[:, i], results[:, i])

        misclassified = sp.sum(sp.argmax(results, axis=0) != sp.argmax(expected, axis=0))

        return err, misclassified
开发者ID:quentinms,项目名称:PCML---Mini-Project,代码行数:10,代码来源:LogisticLinearClassifier.py

示例7: Problem6Real

def Problem6Real():
    N = 500
    w = sp.linspace(0,100,N)
    w = w.reshape(N,1)
    u = lambda c: sp.sqrt(c)
    util_vec = u(w)
    alpha = 0.5
    alpha_util = u(alpha*w)
    alpha_util_grid = sp.repeat(alpha_util,N,1)
    
    m = 20
    v = 200
    f = discretelognorm(w,m,v)
    
    VEprime = sp.zeros((N,1))
    VUprime    = sp.zeros((N,N))
    EVUprime = sp.zeros((N,1))
    psiprime = sp.ones((N,1))
    gamma = 0.1
    beta = 0.9
    
    m = 15
    tol = 10**-9
    delta = 1+tol
    it = 0
    while (delta >= tol):
        it += 1
        
        psi = psiprime.copy()
        arg1 = sp.repeat(sp.transpose(VEprime),N,0)
        arg2 = sp.repeat(EVUprime,N,1)
        arg = sp.array([arg2,arg1])
        psiprime = sp.argmax(arg,axis = 0)    
        
        for j in sp.arange(0,m):
            VE = VEprime.copy()
            VU = VUprime.copy()
            EVU = EVUprime.copy()
            VEprime = util_vec + beta*((1-gamma)*VE + gamma*EVU)
            arg1 = sp.repeat(sp.transpose(VE),N,0)*psiprime
            arg2 = sp.repeat(EVU,N,1)*(1-psiprime)
            arg = arg1+arg2
            VUprime = alpha_util_grid + beta*arg
            EVUprime = sp.dot(VUprime,f)  
    
        
    
        delta = sp.linalg.norm(psiprime -psi)
        #print(delta)    
        
    wr_ind = sp.argmax(sp.diff(psiprime), axis = 1)
    wr = w[wr_ind]
    plt.plot(w,wr)
    plt.show()
    return wr
开发者ID:davidreber,项目名称:Labs,代码行数:55,代码来源:solutionstester.py

示例8: generate

def generate(hmm,observation_space,n_sim):
	A = hmm[0]
	B = hmm[1]
	pi = hmm[2]
	states = sp.zeros(n_sim)
	observations = []
	states[0] = sp.argmax(sp.random.multinomial(1,pi))
	observations.append(observation_space[sp.argmax(sp.random.multinomial(1,B[states[0],:]))])
	for i in range(1,n_sim):
		states[i] = sp.argmax(sp.random.multinomial(1,A[states[i-1],:]))
		observations.append(observation_space[sp.argmax(sp.random.multinomial(1,B[states[i],:]))])
	return states,observations
开发者ID:KathleenF,项目名称:numerical_computing,代码行数:12,代码来源:hmm.py

示例9: pitch

def pitch(x, fs, pitchrange=[12,120], mode='corr'):
    if mode=='corr':
        corr = scipy.correlate(x, x, mode='full')[len(x)-1:]
        corr[:int(fs/midi2hz(pitchrange[1]))] = 0
        corr[int(fs/midi2hz(pitchrange[0])):] = 0
        indmax = scipy.argmax(corr)
    elif mode=='ceps':
        y = rceps(x)
        y[:int(fs/midi2hz(pitchrange[1]))] = 0
        y[int(fs/midi2hz(pitchrange[0])):] = 0
        indmax = scipy.argmax(y)
    return hz2midi(fs/indmax)
开发者ID:zangsir,项目名称:pymir,代码行数:12,代码来源:mir.py

示例10: calcError

def calcError(trainer, dataset=None):
    if dataset == None:
        dataset = trainer.ds
    dataset.reset()
    out = []
    targ = []
    for seq in dataset._provideSequences():
        trainer.module.reset()
        for input, target in seq:
            res = trainer.module.activate(input)
            out.append(argmax(res))
            targ.append(argmax(target))
    return percentError(out, targ) / 100
开发者ID:JackHolland,项目名称:Brains,代码行数:13,代码来源:BioANN.py

示例11: generateGaussianHMM

def generateGaussianHMM(hmm,n_sim):
	A = hmm[0]
	means = hmm[1]
	covars = hmm[2]
	pi = hmm[3]
	states = sp.zeros(n_sim).astype(int)
	K = len(means[0,:])
	observations = sp.zeros((n_sim,K))
	states[0] = int(sp.argmax(sp.random.multinomial(1,pi)))
	observations[0,:] = sp.random.multivariate_normal(means[states[0],:],covars[states[0],:,:])
	for i in range(1,n_sim):
		states[i] = int(sp.argmax(sp.random.multinomial(1,A[states[i-1],:])))
		observations[i,:] = sp.random.multivariate_normal(means[states[i],:],covars[states[i],:,:])
	return states,observations
开发者ID:KathleenF,项目名称:numerical_computing,代码行数:14,代码来源:cdhmm.py

示例12: digshc

def digshc(docs, alpha, threshold, epsilon, hr_min):
    # Worth nothing that this takes in plaintext documents, _not_ vectors.
    shc = SimilarityHistogramClusterer(alpha, threshold, epsilon, hr_min)

    for doc in docs:
        shc.fit(doc)

    doc_clus_map = {}
    for idx, clus in enumerate(shc.formed_clusters):
        for doc_id in clus.doc_ids:
            doc_clus_map.setdefault(doc_id, [])
            doc_clus_map[doc_id].append(idx)

    labels = []
    for id in sorted(doc_clus_map):
        cluster_ids = doc_clus_map[id]
        if len(cluster_ids) == 1:
            best_cl_id = cluster_ids[0]
        else:
            clusters = [shc.get_cluster(cl_id) for cl_id in cluster_ids]
            sims = [shc.get_cluster_sim(cl, shc.get_doc(id)) for cl in clusters]
            max_i = argmax(sims)
            best_cl_id = clusters[max_i].id
        labels.append(best_cl_id)

    return labels
开发者ID:frnsys,项目名称:galaxy,代码行数:26,代码来源:__init__.py

示例13: testKernelCoeffs

 def testKernelCoeffs(self):
     for scale in [0.35, 0.5, 0.75, 1]:
         for dim in [0,1,2,3,4]:
             dgK = mango.image.discrete_gaussian_kernel(sigma=scale, dim=dim, errtol=0.001)
             self.assertAlmostEqual(1.0, sp.sum(dgK), 8)
             mxElem = sp.argmax(dgK)
             self.assertTrue(sp.all(sp.array(dgK.shape)//2 == sp.unravel_index(mxElem, dgK.shape)))
开发者ID:pymango,项目名称:pymango,代码行数:7,代码来源:_DiscreteGaussianTest.py

示例14: getPredominantColor

def getPredominantColor(filename):
    im = Image.open(filename).convert('RGB')

    # Convert to numpy array
    ar = scipy.misc.fromimage(im)

    # Get dimensions
    shape = ar.shape

    # Convert to bidimensional array of width x height rows and 3 columns (RGB)
    ar = ar.reshape(scipy.product(shape[:2]), shape[2])

    # Find cluster centers and their distortions
    # codes contains the RGB value of the centers
    codes, dist = scipy.cluster.vq.kmeans(ar.astype(float), NUM_CLUSTERS)

    # Maps all the pixels in the image to their respective centers
    vecs, dist = scipy.cluster.vq.vq(ar, codes)

    # Counts the occurances of each color (NUM_CLUSTER different colors after the mapping)
    counts, bins = scipy.histogram(vecs, len(codes))

    # Find most frequent color
    index_max = scipy.argmax(counts)
    peak = codes[index_max]

    return peak.astype(int)
开发者ID:nachogoro,项目名称:twitter-avatar-classifier,代码行数:27,代码来源:imageprocessor.py

示例15: getDominantColor

def getDominantColor(img_url):
    if r.exists(img_url):
        cache_result = r.hmget(img_url, ['r', 'g', 'b'])
        return cache_result
        
    NUM_CLUSTERS = 5
    im = Image.open(StringIO.StringIO(urllib2.urlopen(img_url).read()))
    img_arr = scipy.misc.fromimage(im)
    img_shape = img_arr.shape
    
    if len(img_shape) > 2:
        img_arr = img_arr.reshape(scipy.product(img_shape[:2]), img_shape[2])
    
    codes, _ = scipy.cluster.vq.kmeans(img_arr, NUM_CLUSTERS)
    
    original_codes = codes
    for low, hi in [(60, 200), (35, 230), (10, 250)]:
        codes = scipy.array([code for code in codes if not (all([c < low for c in code]) or all([c > hi for c in code]))])
        if not len(codes):
            codes = original_codes
        else:
            break

    vecs, _ = scipy.cluster.vq.vq(img_arr, codes)
    counts, bins = scipy.histogram(vecs, len(codes))

    index_max = scipy.argmax(counts)
    peak = codes[index_max]
    color = [int(c) for c in peak[:3]]
    r.hmset(img_url, {'r':color[0], 'g':color[1], 'b':color[2]})
    #r.expire(img_url, 86400)
    return color
开发者ID:lumilux,项目名称:lclclr,代码行数:32,代码来源:lclclr.py


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