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


Python Helper.fadingFunction方法代码示例

本文整理汇总了Python中helper.Helper.fadingFunction方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.fadingFunction方法的具体用法?Python Helper.fadingFunction怎么用?Python Helper.fadingFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在helper.Helper的用法示例。


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

示例1: __init__

# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import fadingFunction [as 别名]
class FadingCluster:

	def __init__(self, clusterCreationTime):
		
		self.dimensionVector = [] # the dimensions which are relevant at the moment
		self.fc2Measure = {} # fc2MeasureTempeasure {dimension : measure}
		self.fc1Measure = {} # fc1MeasureTempeasure {dimension : measure}
		self.weight = 0.0    
		self.lastUpdateTime = clusterCreationTime
		self.clusterCenter = {} # center {dimension : measure}
		self.sentimentCount = {'+1' : 0, '-1' : 0, '+0' : 0}
		self.helperObject = Helper()

	
	def changeFeatureSpace(self):
		
		# load the old feature set
		oldFeatureSet = []
		fileReader = open('data/all_best_features.pkl', 'r')
		while True:
			try:
				oldFeatureSet.append(pickle.load(fileReader))
			except:
				break
		fileReader.close()
		
		# load the new evolved feature space
		newFeatureSet = []
		fileReader = open('data/best_features.pkl', 'r')
		while True:
			try:
				newFeatureSet.append(pickle.load(fileReader))
			except:
				break
		fileReader.close()
		
		# save old measures for the evolved cluster
		fc2MeasureTemp = {}
		fc1MeasureTemp = {}
		centerTemp = {}
		dimensionVectorTemp = []
		
		for featureIndex in self.fc2Measure:
			featureName = oldFeatureSet[featureIndex]
			
			newIndex = newFeatureSet.index(featureName)
			dimensionVectorTemp.append(newIndex)
			
			fc2MeasureTemp[newIndex] = self.fc2Measure[featureIndex]
			fc1MeasureTemp[newIndex] = self.fc1Measure[featureIndex]
			centerTemp[newIndex] = self.clusterCenter[featureIndex]
		
		self.fc2Measure = dict(fc2MeasureTemp)
		self.fc1Measure = dict(fc1MeasureTemp)
		self.clusterCenter = dict(centerTemp)
		self.dimensionVetor = list(dimensionVectorTemp)

	
	def decayWithTime(self, currentTime):
		
		updatedValue = self.helperObject.fadingFunction(currentTime - self.lastUpdateTime)
		
		for key in self.fc1Measure:
			self.fc1Measure[key] *= updatedValue
			self.fc2Measure[key] *= updatedValue
		
		self.weight = self.weight * updatedValue
		self.lastUpdateTime = currentTime


	def addNewDataPoint(self, currentTime, allDataPoints = False, point = []):
		
		# allDataPoints = true for adding all the data points to a cluster
		# allDataPoints = false for adding one data point to the cluster
		
		if allDataPoints == True:
			fileReader = open('data/feature_set.data', 'r')
		elif allDataPoints == False:
			fileReader = [point]
		else:
			pass
		
		self.decayWithTime(currentTime)
		
		numberOfDataPoints = sum(self.sentimentCount.values())
		
		for k in self.clusterCenter:
			self.clusterCenter[k] *=  numberOfDataPoints
		
		for line in fileReader:
			if allDataPoints == True:
				weights = line.split(',')[1:]
			else:
				weights = line
			
			i = 0
			for weight in weights:
				weightValue = float(weight)
				
				if weightValue != 0.0:
#.........这里部分代码省略.........
开发者ID:siriusblac37,项目名称:stock-market-prediction,代码行数:103,代码来源:projClustering.py


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