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


Python TimeSeries.add_entry方法代码示例

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


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

示例1: execute

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def execute(self, timeSeries):
        """Creates a new TimeSeries containing the SMA values for the predefined windowsize.

        :param TimeSeries timeSeries:    The TimeSeries used to calculate the simple moving average values.

        :return:    TimeSeries object containing the smooth moving average.
        :rtype:     TimeSeries

        :raise:   Raises a :py:exc:`ValueError` wif the defined windowsize is larger than the number of elements
            in timeSeries

        :note:    This implementation aims to support independent for loop execution.
        """
        windowsize    = self._parameters["windowsize"]

        if len (timeSeries) < windowsize:
            raise ValueError("windowsize is larger than the number of elements in timeSeries.")

        tsLength      = len(timeSeries)
        nbrOfLoopRuns = tsLength - windowsize + 1

        res = TimeSeries()
        for idx in xrange(nbrOfLoopRuns):
            end = idx + windowsize
            data = timeSeries[idx:end]

            timestamp = data[windowsize//2][0]
            value     = sum([i[1] for i in data])/windowsize

            res.add_entry(timestamp, value)

        res.sort_timeseries()
        return res
开发者ID:T-002,项目名称:pycast,代码行数:35,代码来源:simplemovingaverage.py

示例2: train_target

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
 def train_target(self, data_list, model_list):# data_list: [date, value]
     orig = TimeSeries(isNormalized=True)
     for i in range(len(data_list)):
         orig.add_entry(data_list[i][0], data_list[i][1])
     gridSearch = GridSearch(SMAPE)
     optimal_forecasting, error, optimal_params = gridSearch.optimize(orig, model_list)
     #print "======" + str(optimal_forecasting._parameters)
     return optimal_forecasting
开发者ID:THUIR,项目名称:TianchiCompetition,代码行数:10,代码来源:pycast_predictor.py

示例3: is_normalized_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
 def is_normalized_test(self):
     """Test TimeSeries.is_normalized()."""
     ts = TimeSeries(isNormalized=True)
     assert ts.is_normalized()
     ts = TimeSeries(isNormalized=False)
     assert ts.is_normalized()
     ts.add_entry(0.1, 3.2)
     ts.add_entry(0.4, 3.2)
     ts.add_entry(0.3, 3.2)
     assert False == ts.is_normalized()
开发者ID:fleupold,项目名称:pycast,代码行数:12,代码来源:timeseriesmiscellaneoustest.py

示例4: list_initialization_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def list_initialization_test(self):
        """Test TimeSeries initialization from a given list."""
        data = [[0.0, 0.0], [0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4], [0.5, 0.5]]

        tsOne = TimeSeries()
        for entry in data:
            tsOne.add_entry(*entry)

        tsTwo = TimeSeries.from_twodim_list(data)

        if not (len(tsOne) == len(tsTwo)): raise AssertionError
        if not (tsOne == tsTwo):          raise AssertionError
开发者ID:fleupold,项目名称:pycast,代码行数:14,代码来源:timeseriesmiscellaneoustest.py

示例5: error_calculation_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def error_calculation_test(self):
        """Test the calculation of the MeanSquaredError."""
        tsOrg  = TimeSeries()
        tsCalc = TimeSeries()

        for idx in xrange(len(self.dataOrg)):
            tsOrg.add_entry(float(idx),  self.dataOrg[idx])
            tsCalc.add_entry(float(idx), self.dataCalc[idx])

        mse = MeanSquaredError()
        mse.initialize(tsOrg, tsCalc)

        self.assertEquals("0.1472", str(mse.get_error())[:6])
开发者ID:T-002,项目名称:pycast,代码行数:15,代码来源:meansquarederrortest.py

示例6: error_calculation_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def error_calculation_test(self):
        """Test the calculation of the MeanAbsolutePercentageError."""
        tsOrg  = TimeSeries()
        tsCalc = TimeSeries()

        for idx in xrange(len(self.dataOrg)):
            tsOrg.add_entry(float(idx),  self.dataOrg[idx])
            tsCalc.add_entry(float(idx), self.dataCalc[idx])

        mape = MeanAbsolutePercentageError()
        mape.initialize(tsOrg, tsCalc)

        self.assertEquals("139.78", str(mape.get_error())[:6])
开发者ID:T-002,项目名称:pycast,代码行数:15,代码来源:meanabsolutepercentageerrortest.py

示例7: error_calculation_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def error_calculation_test(self):

        msd = MeanSignedDifferenceError()

        tsOrg  = TimeSeries()
        tsCalc = TimeSeries()

        for idx in xrange(len(self.dataOrg)):
            tsOrg.add_entry(float(idx),  self.dataOrg[idx])
            tsCalc.add_entry(float(idx), self.dataCalc[idx])

        msd.initialize(tsOrg, tsCalc)

        self.assertEquals(str(msd.get_error())[:6], '0.0727')
开发者ID:T-002,项目名称:pycast,代码行数:16,代码来源:meansigneddifferenceerrortest.py

示例8: error_calculation_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def error_calculation_test(self):
        """ Test error calculation for MedianAbsolutePercentageError"""
        mdape = MedianAbsolutePercentageError()

        tsOrg  = TimeSeries()
        tsCalc = TimeSeries()

        for idx in xrange(len(self.dataOrg)):
            tsOrg.add_entry(float(idx),  self.dataOrg[idx])
            tsCalc.add_entry(float(idx), self.dataCalc[idx])

        mdape.initialize(tsOrg, tsCalc)

        self.assertEqual(mdape.get_error(), 100)
        self.assertEqual(mdape.get_error(20.0, 50.0), 50)
开发者ID:T-002,项目名称:pycast,代码行数:17,代码来源:medianabsolutepercentageerrortest.py

示例9: error_calculation_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def error_calculation_test(self):
        """Test the calculation of the SymmetricMeanAbsolutePercentageError."""
        dataPtsOrg  = [2.30,     .373,           .583,          1.88,  1.44,         -0.0852, -.341,  .619,  .131,  1.27, 0]
        dataPtsCalc = [-1.21,   -.445,           .466,          .226, -.694,           -.575,  2.73, -1.49, -1.45, -.193, 0]

        tsOrg  = TimeSeries()
        tsCalc = TimeSeries()
        
        for idx in xrange(len(dataPtsOrg)):
            tsOrg.add_entry(float(idx),  dataPtsOrg[idx])
            tsCalc.add_entry(float(idx), dataPtsCalc[idx])

        smape = SymmetricMeanAbsolutePercentageError()
        smape.initialize(tsOrg, tsCalc)

        ## compare the strings due to accuracy
        assert "1.5706" == str(smape.get_error())[:6]
开发者ID:744996162,项目名称:ali_match,代码行数:19,代码来源:errormeasuretest.py

示例10: error_calculation_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def error_calculation_test(self):
        """Test the calculation of the Mean Absolute Deviation Error."""
        #dataPtsOrg  = [2.30,     .373,           .583,          1.88,  1.44,         -0.0852, -.341,  .619,  .131,  1.27, 0]
        #dataPtsCalc = [-1.21,   -.445,           .466,          .226, -.694,           -.575,  2.73, -1.49, -1.45, -.193, 0]

        tsOrg  = TimeSeries()
        tsCalc = TimeSeries()

        for idx in xrange(len(self.dataOrg)):
            tsOrg.add_entry(float(idx),  self.dataOrg[idx])
            tsCalc.add_entry(float(idx), self.dataCalc[idx])

        mad = MeanAbsoluteDeviationError()
        mad.initialize(tsOrg, tsCalc)

        # compare the strings due to accuracy
        self.assertEqual("0.3454", str(mad.get_error())[:6])
开发者ID:T-002,项目名称:pycast,代码行数:19,代码来源:meanabsolutedeviationerrortest.py

示例11: check_for_consistency_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def check_for_consistency_test(self):
        """Tests if database initialization and manual initialization create equal TimeSeries instances."""
        ## read the number of rows from the database
        cur = self._db.cursor().execute("""SELECT COUNT(*) from TestTable""")
        nbrOfTuples = cur.fetchall()[0][0]

        ## SQL extraction statement
        sqlstmt = """SELECT timestamp, value FROM TestTable ORDER BY timestamp ASC"""

        ## Initialize one TimeSeries instance manually
        tsManual = TimeSeries()
        data     = self._db.cursor().execute(sqlstmt).fetchall()
        for entry in data:
            tsManual.add_entry(*entry)

        ## Initialize one TimeSeries from SQL cursor
        tsAuto = TimeSeries()
        tsAuto.initialize_from_sql_cursor(self._db.cursor().execute(sqlstmt))

        ## check if those TimeSeries are equal
        if not (nbrOfTuples   == len(tsManual)): raise AssertionError
        if not (nbrOfTuples   == len(tsAuto)):   raise AssertionError
        if not (len(tsManual) == len(tsAuto)):   raise AssertionError
        if not (tsManual      == tsAuto):        raise AssertionError
开发者ID:fleupold,项目名称:pycast,代码行数:26,代码来源:timeseriesdatabasetest.py

示例12: validity_of___str___test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def validity_of___str___test(self):
        """Test the validity of __str__ for a given TimeSeries."""
        ts = TimeSeries()
        ts.add_entry(0.0, 0.0)
        ts.add_entry(0.1, 0.1)
        ts.add_entry(0.2, 0.2)
        ts.add_entry(0.3, 0.3)
        ts.add_entry(0.4, 0.4)

        matchres = re.match("TimeSeries\(\[(.*)\]\)", ts.__str__())
        
        assert (None != matchres)
开发者ID:fleupold,项目名称:pycast,代码行数:14,代码来源:timeseriesmiscellaneoustest.py

示例13: json_serialization_formatfree_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def json_serialization_formatfree_test(self):
        """Test the json serialialization without predefined format."""
        tsOrg = TimeSeries()
        tsOrg.add_entry(0.0, 0.0)
        tsOrg.add_entry(0.1, 0.1)
        tsOrg.add_entry(0.2, 0.2)
        tsOrg.add_entry(0.3, 0.3)
        tsOrg.add_entry(0.4, 0.4)
        json = tsOrg.to_json()

        tsNew = TimeSeries.from_json(json)

        if not (len(tsOrg) == len(tsNew)): raise AssertionError
        if not (tsOrg == tsNew):           raise AssertionError
开发者ID:fleupold,项目名称:pycast,代码行数:16,代码来源:timeseriesmiscellaneoustest.py

示例14: json_serialization_format_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def json_serialization_format_test(self):
        """Test the json serialialization with predefined format."""
        tsOrg = TimeSeries()
        tsOrg.add_entry(0.0, 0.0)
        tsOrg.add_entry(1.0, 0.1)
        tsOrg.add_entry(2.0, 0.2)
        tsOrg.add_entry(3.0, 0.3)
        tsOrg.add_entry(4.0, 0.4)
        tsOrg.set_timeformat("%Y-%m-%d_%H:%M:%S")
        json = tsOrg.to_json()

        tsNew = TimeSeries.from_json(json, format="%Y-%m-%d_%H:%M:%S")

        if not (len(tsOrg) == len(tsNew)): raise AssertionError
        if not (tsOrg == tsNew):          raise AssertionError
开发者ID:fleupold,项目名称:pycast,代码行数:17,代码来源:timeseriesmiscellaneoustest.py

示例15: method_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import add_entry [as 别名]
    def method_test(self):
        """Test if TimeSeries apply branches work correctly.

        This is mainly to increase code coverage."""
        mOne   = BaseMethod([], hasToBeSorted=True, hasToBeNormalized=True)
        mTwo   = BaseMethod([], hasToBeSorted=False, hasToBeNormalized=True)
        mThree = BaseMethod([], hasToBeSorted=True, hasToBeNormalized=False)
        mFour  = BaseMethod([], hasToBeSorted=False, hasToBeNormalized=False)

        ts = TimeSeries(isNormalized=True)
        ts.add_entry(0.0, 0.0)
        ts.add_entry(0.1, 0.1)
        ts.add_entry(0.2, 0.2)
        ts.add_entry(0.3, 0.3)
        ts.add_entry(0.4, 0.4)

        try:
            ts.apply(mOne)
        except NotImplementedError:
            pass
        else:
            assert False    # pragma: no cover

        try:
            ts.apply(mTwo)
        except NotImplementedError:
            pass
        else:
            assert False    # pragma: no cover

        try:
            ts.apply(mThree)
        except NotImplementedError:
            pass
        else:
            assert False    # pragma: no cover

        try:
            ts.apply(mFour)
        except NotImplementedError:
            pass
        else:
            assert False    # pragma: no cover
开发者ID:fleupold,项目名称:pycast,代码行数:45,代码来源:timeseriesmiscellaneoustest.py


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