예제 #1
0
    def local_error_test(self):
        """Test MeanSquaredError.local_error."""
        localErrors = [0.04, 0.09, 0.16, 0.25, 0.25, 0.09, 0.04, 0.36, 0.09, 0.25, 0]

        mse = MeanSquaredError()

        for i in range(len(self.dataOrg)):
            calc_local_error = mse.local_error([self.dataOrg[i]], [self.dataCalc[i]])
            self.assertEquals("%.3f" % calc_local_error,"%.3f" % localErrors[i])
예제 #2
0
    def error_calculation_test(self):
        """Test the calculation of the MeanSquaredError."""
        tsOrg  = TimeSeries()
        tsCalc = TimeSeries()

        for idx in range(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])
예제 #3
0
    def error_calculation_test(self):
        """Test for a valid error calculation."""
        dataOrg         = [[0,0], [1,1], [2,2], [3,3], [4,4], [5,5], [6,  6], [7,7], [8,8],   [9,9]]
        dataCalc        = [[0,1], [1,3], [2,5], [3,0], [4,3], [5,5], [6.1,6], [7,3], [8.1,8], [9,8]]
        # difference:         1      2      3      3      1      0       NA      4       NA      1
        # local errors:       1      4      9      9      1      0       NA     16       NA      1

        tsOrg  = TimeSeries.from_twodim_list(dataOrg)
        tsCalc = TimeSeries.from_twodim_list(dataCalc)

        tsOrg  = TimeSeries.from_twodim_list(dataOrg)
        tsCalc = TimeSeries.from_twodim_list(dataCalc)

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

        assert str(mse.get_error()) == "5.125"
예제 #4
0
    def number_of_comparisons_test(self):
        """ Test BaseErrorMeasure.initialize for behaviour if not enough dates match."""
        dataOrg  = [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9]]
        dataCalc = [[0,0],[1,1],[2,2],[3,3],[4,4],[5.1,5],[6.1,6],[7.1,7],[8.1,8],[9.1,9]]

        tsOrg  = TimeSeries.from_twodim_list(dataOrg)
        tsCalc = TimeSeries.from_twodim_list(dataCalc)

        bem = BaseErrorMeasure(60.0)

        #prevent NotImplementedError
        bem.local_error = lambda a,b: 1

        mse = MeanSquaredError(80.0)
        # only 50% of the original TimeSeries have a corresponding partner
        if mse.initialize(tsOrg, tsCalc):
            assert False    # pragma: no cover

        if not mse.initialize(tsOrg, tsOrg):
            assert False    # pragma: no cover