本文整理汇总了Python中library.Library.transform_input方法的典型用法代码示例。如果您正苦于以下问题:Python Library.transform_input方法的具体用法?Python Library.transform_input怎么用?Python Library.transform_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类library.Library
的用法示例。
在下文中一共展示了Library.transform_input方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WeightedDataTemplates
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import transform_input [as 别名]
class WeightedDataTemplates(object):
def __init__(self, config):
"""
This class implements the data-template-based trend detection technique
presented by Nikolov
(http://dspace.mit.edu/bitstream/handle/1721.1/85399/870304955.pdf)
The auxiliary module "library" (or equivalent code) is required.
"""
# set up basic member variables
self.current_count = None
self.total_series = []
self.trend_weight = None
self.non_trend_weight = None
self.SMALL_NUMBER = 0.001
# manage everything related to distance measurements
self.set_up_distance_measures(config)
# config handling
if "series_length" in config:
self.series_length = int(config["series_length"])
else:
self.series_length = 50
if "reference_length" in config:
self.reference_length = int(config["reference_length"])
else:
self.reference_length = 210
if "lambda" in config:
self.Lambda = float(config["lambda"])
else:
self.Lambda = 1
#if "logger" in config:
# self.logger = config["logger"]
#else:
# self.logger = logging.getLogger("default_template_logger")
#self.logger = logr
from library import Library
if "library_file_name" in config:
self.library = pickle.load(open(config["library_file_name"]))
else:
self.library = Library(config={})
self.config = config
def update(self, **kwargs):
"""
Calculate trend weights for time series based on latest data.
"""
# this must always exist
current_count = kwargs["count"]
check_for_self = False
if "check_for_self" in kwargs:
check_for_self = kwargs["check_for_self"]
# add current data point to series
self.total_series.append(current_count)
# don't return anything meaningful until total_series is long enough
if len(self.total_series) < self.reference_length or sum(self.total_series) == 0:
self.trend_weight = float(0)
self.non_trend_weight = float(0)
return
# transform a "reference_length"-sized sub-series
#transformed_series = self.total_series[-self.reference_length:]
#for transformation in self.library.test_transformations:
# transformed_series = transformation(transformed_series,self.config)
transformed_series = self.library.transform_input(self.total_series[-self.reference_length:],is_test_series=True,config=self.config)
# get correctly-sized test series
test_series = transformed_series[-self.series_length:]
self.trend_weight = float(0)
for reference_series in self.library.trends:
weight = self.weight(reference_series,test_series,check_for_self)
#self.logger.debug("trend wt: {}".format(weight))
self.trend_weight += weight
self.non_trend_weight = float(0)
for reference_series in self.library.non_trends:
weight = self.weight(reference_series,test_series,check_for_self)
#self.logger.debug("non trend wt: {}".format(weight))
self.non_trend_weight += weight
def get_result(self):
"""
Return result or figure-of-merit (ratio of weights, in this case) defined by the mode of operation
"""
if self.trend_weight is None or self.non_trend_weight is None:
return -1
if self.non_trend_weight == 0:
self.non_trend_weight = self.SMALL_NUMBER
#.........这里部分代码省略.........