Ejemplo n.º 1
0
	def formAnalysis(self, SSM, isViz = False, topk = 5):
		self.__TOPK = topk

		"""
		視覺化Matrix
		"""
		if isViz:
			self.__SSMViz(SSM)

		"""
		計算 SSM 中所有的 Block Family
		"""
		startTime = time.time()
		(self.__allFamilyM, cohesionM) = self.__allBlockFamily(SSM)
		endTime = time.time()
		print "LyricsForm: Family Matrix Construction Time = %.2fsec" % (endTime - startTime)

	
		"""
		產生 Cohesion Matrix
		"""
		#self.__viz.grayMatrix(cohesionM, "Cohesion Matrix")


		"""
		Block Family Combination
		"""
		self.__allFamilyM = numpy.insert(self.__allFamilyM, 0, 0, axis = 0)
		startTime = time.time()
		ff = FormFinder(self.__allFamilyM, self.__TOPK)
		combineList = ff.computing()
		endTime = time.time()

		print "LyricsForm: Block Combination Time = %.2fsec" % (endTime - startTime)
		print



		"""
		combineList 轉換成詞式格式
		"""
		lineNum = SSM.shape[0]
		formList = self.__resultForm(combineList, lineNum)


		return formList
Ejemplo n.º 2
0
	def formAnalysis(self, SSM, isViz = False):

		"""
		視覺化Matrix
		"""
		if isViz:
			self.__SSMViz(SSM)


		
		"""
		NMF test
		from nmf import nmf
		n = SSM.shape[0]
		r = 5
		w = numpy.random.random([n, r])
		h = numpy.random.random([r, n])
		
		(wo,ho) = nmf(SSM, w, h, 0.001, 1000, 100)

		if isViz:
			self.__SSMViz(numpy.dot(wo, ho))
			
			for k in range(r):
				print k
				wmask = numpy.zeros((n, r))
				wmask[:, k] = numpy.ones(n)
				hmask = numpy.zeros((r, n))
				hmask[k, :] = numpy.ones(n)

				self.__SSMViz(numpy.dot(wo * wmask, hmask * ho))
		"""




		"""
		計算 SSM 中所有的 Block Family
		"""
		startTime = time.time()
		self.__allFamilyM = self.__allBlockFamily(SSM)
		endTime = time.time()
		print "LyricsForm: Family Matrix Construction Time = %.2fsec" % (endTime - startTime)

		self.__allFamilyM = numpy.insert(self.__allFamilyM, 0, 0, axis = 0)

		"""
		Block Family Combination
		"""
		startTime = time.time()
		ff = FormFinder(self.__allFamilyM, self.__TOPK)
		combineList = ff.computing()
		endTime = time.time()

		print "LyricsForm: Block Combination Time = %.2fsec" % (endTime - startTime)
		print



		"""
		combineList 轉換成詞式格式
		"""
		lineNum = SSM.shape[0]
		formList = self.__resultForm(combineList, lineNum)


		return formList