def softMax(PoIs, Words, ArqOut, numeroPalavras, label):
	ArqOut = open(ArqOut,"wb")
	ArqOut.write(label + " ")
	
	# distances - Matriz n * V (número de pontos * número de palavras) que calculará apenas uma vez as distâncias
	distances = sp.cdist(PoIs, Words, 'euclidean')								# first points, after codewords. Return a len(PoIs) x len(Words) matrix of distances
	distances = [ gaussiankernel(45.0, dist) for dist in numpy.reshape(distances, (1,distances.size))[0] ]	# apply the gaussian kernel
	distances = numpy.reshape(distances, (len(PoIs), len(Words)))						# put again in the format len(PoIs) x len(Words)
	
	# distToAll - Vetor que armazenará para cada ponto o somatório das distâncias para todas as palavras
	distToAll = []
	for point in distances:
		distToAll.append(sum(point)) 
	distToAll = numpy.asarray(distToAll)
	
	features = []
	distances = numpy.transpose(distances)					# transpose. Format len(Words) x len(PoIs)
	division = numpy.divide(distances, distToAll)				# Equivalent to divide the distance of codeword i to PoI j by the summation of the distances of PoI j to all codewords
	features = [ max(dist) for dist in division ]				# get the maximum activation for each codeword
		
	
	features = common_functions.l1norm(features)
	
	for f in features:
		ArqOut.write(str(f) + " ")
	ArqOut.close()	
Ejemplo n.º 2
0
def softMax(PoIs, Words, ArqOut, numeroPalavras, label):
	ArqOut = open(ArqOut,"wb")
	ArqOut.write(label + " ")
	
	# distances - Matriz n * V (número de pontos * número de palavras) que calculará apenas uma vez as distâncias
	distances = sp.cdist(PoIs, Words, 'euclidean')								# first points, after codewords. Return a len(PoIs) x len(Words) matrix of distances
	distances = [ gaussiankernel(45.0, dist) for dist in numpy.reshape(distances, (1,distances.size))[0] ]	# apply the gaussian kernel
	distances = numpy.reshape(distances, (len(PoIs), len(Words)))						# put again in the format len(PoIs) x len(Words)
	
	# distToAll - Vetor que armazenará para cada ponto o somatório das distâncias para todas as palavras
	distToAll = []
	for point in distances:
		distToAll.append(sum(point)) 
	distToAll = numpy.asarray(distToAll)
	
	features = []
	distances = numpy.transpose(distances)					# transpose. Format len(Words) x len(PoIs)
	division = numpy.divide(distances, distToAll)				# Equivalent to divide the distance of codeword i to PoI j by the summation of the distances of PoI j to all codewords
	features = [ max(dist) for dist in division ]				# get the maximum activation for each codeword
		
	
	features = common_functions.l1norm(features)
	
	for f in features:
		ArqOut.write(str(f) + " ")
	ArqOut.close()	
def semiSoft(PoIs, Words, ArqOut, numeroPalavras, label):
	ArqOut = open(ArqOut,"wb")
	ArqOut.write(label + " ")
	distances = numpy.zeros(numeroPalavras)
	
	distances = sp.cdist(Words, PoIs, 'euclidean')								# first codewords, after PoIs. Return a len(Words) x len(PoIs) matrix of distances
	distances = [ 1/min(d) for d in distances ]
		
	
	distances = common_functions.l1norm(distances)
	
	for d in distances:
		ArqOut.write(str(d) + " ")
	ArqOut.close()
Ejemplo n.º 4
0
def semiSoft(PoIs, Words, ArqOut, numeroPalavras, label):
    ArqOut = open(ArqOut, "wb")
    ArqOut.write(label + " ")
    distances = numpy.zeros(numeroPalavras)

    distances = sp.cdist(
        Words, PoIs, 'euclidean'
    )  # first codewords, after PoIs. Return a len(Words) x len(PoIs) matrix of distances
    distances = [1 / min(d) for d in distances]

    distances = common_functions.l1norm(distances)

    for d in distances:
        ArqOut.write(str(d) + " ")
    ArqOut.close()
def hardSum(PoIs, Words, ArqOut, numeroPalavras, label):
	ArqOut = open(ArqOut,"wb")
	ArqOut.write(label + " ")
	histograma = [0 for i in range(numeroPalavras)]
	
	distMatrix = sp.cdist(PoIs, Words, 'euclidean')								# first points, after codewords. Return a len(PoIs) x len(Words) matrix of distances
	
	for i in range(len(PoIs)):
		minimum = min(distMatrix[i])
		ind = numpy.where(distMatrix[i]==minimum)[0][0]
		histograma[ind] += 1

	
	histograma = common_functions.l1norm(histograma)	
	
	for h in histograma:
		ArqOut.write(str(h) + " ")
	ArqOut.close()
Ejemplo n.º 6
0
def hardSum(PoIs, Words, ArqOut, numeroPalavras, label):
	ArqOut = open(ArqOut,"wb")
	ArqOut.write(label + " ")
	histograma = [0 for i in range(numeroPalavras)]
	
	distMatrix = sp.cdist(PoIs, Words, 'euclidean')								# first points, after codewords. Return a len(PoIs) x len(Words) matrix of distances
	
	for i in range(len(PoIs)):
		minimum = min(distMatrix[i])
		ind = numpy.where(distMatrix[i]==minimum)[0][0]
		histograma[ind] += 1

	
	histograma = common_functions.l1norm(histograma)	
	
	for h in histograma:
		ArqOut.write(str(h) + " ")
	ArqOut.close()