本文整理汇总了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:
#.........这里部分代码省略.........