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


Python signal.gaussian函数代码示例

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


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

示例1: vsumsmooth_offset

def vsumsmooth_offset(x, w, center, csum, delta, offset,spacing = 0.01):
	exact=vsumexact_offset(x,w,center,csum,offset)
	if np.shape(x)==():
		gaussian = signal.gaussian(10*delta/spacing,delta/spacing)/(delta/spacing*np.sqrt(2*np.pi))
	else:
		gaussian = signal.gaussian(10*delta/(x.values[1]-x[0]),delta/((x.values[1]-x[0])))/(delta/(x.values[1]-x[0])*np.sqrt(2*np.pi))
	return signal.fftconvolve(exact,gaussian,mode='same')
开发者ID:ndr37,项目名称:DRRA,代码行数:7,代码来源:analysisprocedures.py

示例2: vdifsmooth

def vdifsmooth(x, w, center, cdif, delta,spacing=0.01):
	exact=vdifexact(x,w,center,cdif)
	if np.shape(x) == ():
		gaussian = signal.gaussian(10*delta/spacing,delta/spacing)/(delta/spacing*np.sqrt(2*np.pi))
	else:
		gaussian = signal.gaussian(10*delta/(x.values[1]-x[0]),delta/((x.values[1]-x[0])))/(delta/(x.values[1]-x[0])*np.sqrt(2*np.pi))
	return signal.fftconvolve(exact,gaussian,mode='same')
开发者ID:ndr37,项目名称:DRRA,代码行数:7,代码来源:analysisprocedures.py

示例3: makescore

def makescore(temp,dims):
    score = zeros(dims) + 1
    
    lonax = greater(dims[1],dims[0])
    londim= dims[lonax]
    sdim = dims[1-lonax]
    ldiag = arange(0,londim,1,int)
    sdiag = array(floor(ldiag * (float(sdim)/londim)),int)
    dvals = [ldiag, sdiag]
    if lonax:dvals = dvals[::-1]
    score[dvals] = 20.*temp ** .5

    if lonax: score = score.T

    #for i in range(len(score)):
    #    score[i][i] = 20.* temp **.5

    if temp > .1:
        g = ss.gaussian((londim/2)*temp**2,(londim/2)*temp**2)[:,newaxis]*\
            ss.gaussian((sdim/2)*temp**2,(sdim/2)*temp**2)[newaxis,:]

        g/= sum(g)
        score = ss.convolve2d(score,g,'same','wrap')
        
    for i in range(1,len(score)):
        score[i,arange(sdiag[i])] *= .25


        
    if lonax: score = score.T

    return score
开发者ID:bh0085,项目名称:compbio,代码行数:32,代码来源:bsort.py

示例4: fftgauss

def fftgauss(img,sigma):

    """https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.signal.fftconvolve.html"""

    kernel = np.outer(signal.gaussian(img.shape[0], sigma),
                        signal.gaussian(img.shape[1],sigma))

    return signal.fftconvolve(img, kernel, mode='same')
开发者ID:wukm,项目名称:cakepy,代码行数:8,代码来源:hfft.py

示例5: addGaussians

def addGaussians(query_fn,cand_list,tree,K):
	songs_list   = getNeighbors(query_fn,cand_list,tree,K)
	M            = 23000
	query_ann    = getAnnotationList(gt_path,[query_fn])
	query_labels = [elem[-1] for elem in query_ann[0]]
	query_ann    = np.floor((np.array(getAnnotation(query_ann))*1000)).astype(int)
	length       = query_ann[-1]
	total        = np.zeros(int(np.ceil(length)))

	neighbors_annotations_rescaled = []
	neighbors_annotations = getAnnotationList(gt_path,songs_list)

	for i, song in enumerate(songs_list):
		gt_list        = getAnnotationList(gt_path,[song])
		ann            = np.floor((np.array(getAnnotation(gt_list))*1000)).astype(int) #convert to miliseconds to mantain res
		neighbor_dur   = ann[-1]
		ann_with_sides = ann
		ann            = ann[1:-1]
		a              = np.zeros(int(np.ceil(length)))
		r              = float(length)/float(neighbor_dur) #rescale according to query duration
		ann            = np.floor(ann*r)
		ann_with_sides = np.floor(ann_with_sides*r) 

		labels = [x[-1] for x in gt_list[0]] # get the labels
		annotation_rescaled = []
		for elem in neighbors_annotations[i]:
			label = elem[-1] #save the label so it doesnt get affected by rescaling
			elem[0] = int(np.floor(float(elem[0])*1000*r)) #rescale the rest
			elem[1] = int(np.floor(float(elem[1])*1000*r))
			annotation_rescaled.append([elem[0],elem[1],label])
		neighbors_annotations_rescaled.append(annotation_rescaled)
		for i, loc in enumerate(ann,1):
			section_length = ann_with_sides[i]-ann_with_sides[i-1]
			sigma = 0.1*section_length
			# M=int(np.floor(0.6*section_length))
			g1 = signal.gaussian(M,std=sigma)
			half1 = int(np.floor(len(g1)/2))
			section_length = ann_with_sides[i+1]-ann_with_sides[i]
			sigma = 0.1*section_length
			g2 = signal.gaussian(M,std=sigma)
			half2 = int(np.floor(len(g2)/2))
			g = np.concatenate((g1[:half1],g2[half2:]))			
			if loc < np.floor(M/2):
				a += np.array(np.concatenate((g[int(np.floor(M/2)-loc):],np.zeros(int(length-loc-np.floor(M/2))))))
			elif loc + np.floor(M/2) > length:
				a += np.array(np.concatenate((np.zeros(int(loc-np.floor(M/2))),g[:int(length+np.floor(M/2)-loc)])))
			else:
				a += np.array(np.concatenate((np.zeros(int(loc-np.floor(M/2))),g,np.zeros(int(length-loc-np.floor(M/2))))))
		total += a
	total = total/float(max(total))
	peaks = getPeaks(total,neighbors_annotations)
	all_songs_segmented = [segmentLabel(elem) for elem in neighbors_annotations_rescaled]
	res_boundaries = sorted(peaks)
	res_boundaries.insert(0,0)
	res_boundaries.append(length)
	res_labels = mergeLabels(res_boundaries,all_songs_segmented)
	res_annotations = formatAnnotation(res_boundaries,res_labels)
	return res_annotations
开发者ID:gherrero,项目名称:music-structure,代码行数:58,代码来源:structure_retrieval.py

示例6: _gaussian_window

    def _gaussian_window(self, width, sigma):
        """
        Generates a gaussian window

        sigma is based on the dat being in a range 0 to 1
        """
        return (ssignal.gaussian(width[0], sigma*width[0]).reshape((-1,1,1)) *
                ssignal.gaussian(width[1], sigma*width[1]).reshape((-1,1)) *
                ssignal.gaussian(width[2], sigma*width[2]))
开发者ID:mantidproject,项目名称:mantid,代码行数:9,代码来源:DeltaPDF3D.py

示例7: heat_labels_gauss

def heat_labels_gauss(click, img_size=IMG_SIZE, k_size=KERNEL_SIZE, label_size=LABEL_SIZE):
    # take list of pixel coordinates and return 70x70 heatmap
    img = np.zeros((img_size, img_size))
    for j in range(click.shape[0]):
        x = img_size-1-click[j,1]
        y = click[j,0]
        img[x,y]=1
    kernel = np.outer(signal.gaussian(img_size+1, k_size), signal.gaussian(img_size+1, k_size))
    img = signal.convolve2d(img,kernel, mode='same')
    offset = (img_size-img_size/label_size*(label_size-1))/2
    step = img_size/label_size
    return img[offset:(img_size-offset+step):step, offset:(img_size-offset+step):step]
开发者ID:1va,项目名称:caravan,代码行数:12,代码来源:assemle_labels.py

示例8: smooth_pdf

def smooth_pdf(a, sd=None):
    """Get a smoothed pdf of an array of data for visualization
    
    Keyword arguments:
    sd -- S.D. of the gaussian kernel used to perform the smoothing (default is
        1/20 of the data range)
    
    Return 2-row (x, pdf(x)) smoothed probability density estimate.
    """
    from scipy.signal import gaussian, convolve
    from numpy import array, arange, cumsum, trapz, histogram, diff, r_, c_
    if sd is None:
        sd = 0.05 * a.ptp()
    data = a.copy().flatten() # get 1D copy of array data
    nbins = len(data) > 1000 and len(data) or 1000 # num bins >~ O(len(data))
    f, l = histogram(data, bins=nbins, normed=True) # fine pdf
    sd_bins = sd * (float(nbins) / a.ptp()) # convert sd to bin units
    kern_size = int(10*sd_bins) # sufficient convolution kernel size
    g = gaussian(kern_size, sd_bins) # generate smoothing kernel
    c = cumsum(f, dtype='d') # raw fine-grained cdf
    cext = r_[array((0,)*(2*kern_size), 'd'), c, 
        array((c[-1],)*(2*kern_size), 'd')] # wrap data to kill boundary effect
    cs = convolve(cext, g, mode='same') # smooth the extended cdf
    ps = diff(cs) # differentiate smooth cdf to get smooth pdf
    dl = l[1]-l[0] # get bin delta
    l = r_[arange(l[0]-kern_size*dl, l[0], dl), l, 
        arange(l[-1]+dl, l[-1]+kern_size*dl, dl)] # pad index to match bounds
    ps = ps[kern_size:kern_size+len(l)] # crop pdf to same length as index
    ps /= trapz(ps, x=l) # normalize pdf integral to unity
    return c_[l, ps].T # return 2-row concatenation of x and pdf(x)
开发者ID:jdmonaco,项目名称:grid-remapping-model,代码行数:30,代码来源:stats.py

示例9: smooth_color_prior

def smooth_color_prior(size=64, sigma=5, do_plot=False):

    prior_prob = np.load(os.path.join(data_dir, "CelebA_%s_prior_prob.npy" % size))
    # add an epsilon to prior prob to avoid 0 vakues and possible NaN
    prior_prob += 1E-3 * np.min(prior_prob)
    # renormalize
    prior_prob = prior_prob / (1.0 * np.sum(prior_prob))

    # Smooth with gaussian
    f = interp1d(np.arange(prior_prob.shape[0]),prior_prob)
    xx = np.linspace(0,prior_prob.shape[0] - 1, 1000)
    yy = f(xx)
    window = gaussian(2000, sigma)  # 2000 pts in the window, sigma=5
    smoothed = convolve(yy, window / window.sum(), mode='same')
    fout = interp1d(xx,smoothed)
    prior_prob_smoothed = np.array([fout(i) for i in range(prior_prob.shape[0])])
    prior_prob_smoothed = prior_prob_smoothed / np.sum(prior_prob_smoothed)

    # Save
    file_name = os.path.join(data_dir, "CelebA_%s_prior_prob_smoothed.npy" % size)
    np.save(file_name, prior_prob_smoothed)

    if do_plot:
        plt.plot(prior_prob)
        plt.plot(prior_prob_smoothed, "g--")
        plt.plot(xx, smoothed, "r-")
        plt.yscale("log")
        plt.show()
开发者ID:MiG-Kharkov,项目名称:DeepLearningImplementations,代码行数:28,代码来源:make_dataset.py

示例10: make_gaussian

def make_gaussian(k, std):
  '''Create a gaussian kernel.
  
  Input:

  k - the radius of the kernel.
  
  std - the standard deviation of the kernel.
  
  Output:

  output - a numpy array of shape (2k+1, 2k+1) and dtype float.
  
  If gaussian_1d is a gaussian filter of length 2k+1 in one dimension, 
  kernel[i,j] should be filled with the product of gaussian_1d[i] and 
  gaussian_1d[j].
 
  Once all the points are filled, the kernel should be scaled so that the sum
  of all cells is equal to one.'''
  kernel = np.zeros((2*k+1, 2*k+1), dtype = float)
  gaussian1d = signal.gaussian(2*k+1, std)
  for i in range(0,kernel.shape[0]):
    for j in range(0,kernel.shape[1]):
       kernel[i,j] = gaussian1d[i]*gaussian1d[j]
  kernel = kernel/kernel.sum()

  # Insert your code here.----------------------------------------------------

  #---------------------------------------------------------------------------
  return kernel
开发者ID:rajacheers,项目名称:courses,代码行数:30,代码来源:part1.py

示例11: process_dir

def process_dir(sDir, iResample=None, iSmooth = 50, iSigmaSecs=0.01):
    """
    take input dir and output smoothed, correlated array
    iSigmaSecs:  standard deviation of gaussian in seconds
    iSmooth = smoothing window size for linear smoother
    """
    from scipy import signal
    import numpy as np
    iSampleRate, aTime, aOrigAudio = audio2array(sDir, iResample)
    
    #only positive
    aAudio = [abs(i) for i in aOrigAudio]
    
    #audio files must be right format
    aOrigAudio = np.asarray(aOrigAudio, dtype=np.int16)
    
    if not iSmooth == None:
        #smooth
        aAudio = smooth(aAudio, iSmooth)
    
    #standard deviation for gaussian function
    iSigma = float(iSigmaSecs * iSampleRate)
    aGaussian = signal.gaussian(10*iSigma, iSigma)
    
    #gaussian correlated with audio signal
    aCorr = np.correlate(aAudio, aGaussian, 'same')
    
    
    return iSampleRate, aTime, aAudio, aCorr, aOrigAudio
开发者ID:RomHartmann,项目名称:useful_scripts,代码行数:29,代码来源:isolate_audio_segments.py

示例12: simulSpectra

 def simulSpectra(self,fileSpectra, nBin, continuumLevel, sigma, linePositionChan, lineWidth, lineIntensity, startFreq = 0., resFreq =1.):
     """ Save in fileSpectra of nBin channels with the linePosition, lineWidth and lineIntensity list 
     starFreq and resFreq are optional"""
     
     freq = np.arange(nBin)
     spectra = np.random.normal(continuumLevel, sigma, nBin)
     
     index = 0
     for pos in linePositionChan:
         
         nChan = 4 * int(lineWidth[index] / resFreq)    
         spec = lineIntensity[index] * signal.gaussian(nChan,lineWidth[index])
         
         startPos = pos - nChan / 4
         spectra[pos:pos+nChan] = spectra[pos:pos+nChan] + spec
     
         index += 1
         
         
     f = open(fileSpectra,"w")
     
     index = 0
     for frequency  in freq :
         strOut = "%f   %f \n"%(frequency, spectra[index])
         f.write(strOut)
         index += 1
         
     f.close()
开发者ID:ridlo,项目名称:alma-calibrator,代码行数:28,代码来源:calibratorLines.py

示例13: make_gaussian

def make_gaussian(k, std):
  '''Create a gaussian kernel.
  
  Input:

  k - the radius of the kernel.
  
  std - the standard deviation of the kernel.
  
  Output:

  output - a numpy array of shape (2k+1, 2k+1) and dtype float.
  
  If gaussian_1d is a gaussian filter of length 2k+1 in one dimension, 
  kernel[i,j] should be filled with the product of gaussian_1d[i] and 
  gaussian_1d[j].
 
  Once all the points are filled, the kernel should be scaled so that the sum
  of all cells is equal to one.'''
  kernel = None
  # Insert your code here.----------------------------------------------------
  l = 2 * k + 1
  kernel = np.zeros(l * l)
  kernel.shape = (l, l)
  from scipy import signal
  gaussian1d = signal.gaussian(l, std)
  for i in xrange(l):
    for j in xrange(l):
      kernel[i, j] = gaussian1d[i] * gaussian1d[j]
  s = np.sum(kernel)
  kernel = np.divide(kernel, s)
  #---------------------------------------------------------------------------
  return kernel
开发者ID:kmaragos,项目名称:comp.photo,代码行数:33,代码来源:part1.py

示例14: moving_average

def moving_average(series,sigma = 3,window_time = 39):
    #### Moving weighted gaussian average with window = 39
    b = gaussian(window_time,sigma)
    average = filters.convolve1d(series,b/b.sum())
    var = filters.convolve1d(np.power(series-average,2),b/b.sum())
    
    return average,var
开发者ID:leolorenzoii,项目名称:Development-Codes,代码行数:7,代码来源:UnivariateSplineWithWeightedAverage.py

示例15: compute_gaussian_krnl

def compute_gaussian_krnl(M):
    """Creates a gaussian kernel following Foote's paper."""
    g = signal.gaussian(M, M / 3., sym=True)
    G = np.dot(g.reshape(-1, 1), g.reshape(1, -1))
    G[M / 2:, :M / 2] = -G[M / 2:, :M / 2]
    G[:M / 2, M / 2:] = -G[:M / 2, M / 2:]
    return G
开发者ID:beckgom,项目名称:SegmenterMIREX2014,代码行数:7,代码来源:utils.py


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