Esempio n. 1
0
 def test_anova(self):
     "Tests anova"
     (E, NOx, _, _, _, results) = self.d        
     gas = loess(E,NOx, span=2./3.)
     gas.fit()
     gas_null = loess(E, NOx, span=1.0)
     gas_null.fit()
     gas_anova = loess_anova(gas, gas_null)
     gas_anova_theo = results[4]
     assert_almost_equal(gas_anova.dfn, gas_anova_theo[0], 5)
     assert_almost_equal(gas_anova.dfd, gas_anova_theo[1], 5)
     assert_almost_equal(gas_anova.F_value, gas_anova_theo[2], 5)
     assert_almost_equal(gas_anova.Pr_F, gas_anova_theo[3], 5)
Esempio n. 2
0
    def test_mask(self):
        NOx = marray([4.818, 2.849, 3.275, 4.691, 4.255, 5.064, 2.118, 4.602,
                      2.286, 0.970, 3.965, 5.344, 3.834, 1.990, 5.199, 5.283,
                      -9999, -9999, 3.752, 0.537, 1.640, 5.055, 4.937, 1.561])
        NOx = maskedarray.masked_values(NOx, -9999)
        E = marray([0.831, 1.045, 1.021, 0.970, 0.825, 0.891, 0.71, 0.801,
                    1.074, 1.148, 1.000, 0.928, 0.767, 0.701, 0.807, 0.902,
                    -9999, -9999, 0.997, 1.224, 1.089, 0.973, 0.980, 0.665])
        gas_fit_E = numpy.array([0.665, 0.949, 1.224])
        newdata = numpy.array([0.6650000, 0.7581667, 0.8513333, 0.9445000,
                               1.0376667, 1.1308333, 1.2240000])
        coverage = 0.99

        rfile = open(os.path.join('tests','gas_result'), 'r')
        results = []
        for i in range(8):
            rfile.readline()
            z = fromiter((float(v) for v in rfile.readline().rstrip().split()),
                         float_)
            results.append(z)   
        #
        gas = loess(E,NOx)
        gas.model.span = 2./3.
        gas.fit()
        assert_almost_equal(gas.outputs.fitted_values.compressed(), results[0], 6)
        assert_almost_equal(gas.outputs.enp, 5.5, 1)
        assert_almost_equal(gas.outputs.s, 0.3404, 4) 
Esempio n. 3
0
 def test_1dpredict(self):
     "Basic test 1d - prediction"
     (E, NOx, gas_fit_E, _, _, results) = self.d
     gas = loess(E,NOx, span=2./3.)
     gas.fit()
     gas.predict(gas_fit_E, stderror=False)
     assert_almost_equal(gas.predicted.values, results[2], 6)
Esempio n. 4
0
 def __init__(self, *args, **kwds):
     NumpyTestCase.__init__(self, *args, **kwds)
     dfile = open(os.path.join('tests','madeup_data'), 'r')
     dfile.readline()
     x = fromiter((float(v) for v in dfile.readline().rstrip().split()),
                  float_).reshape(-1,2)
     x = marray(x) 
     dfile.readline()
     y = fromiter((float(v) for v in dfile.readline().rstrip().split()),
                  float_)
     y = marray(y)
     #
     rfile = open(os.path.join('tests','madeup_result'), 'r')
     results = []
     for i in range(8):
         rfile.readline()
         z = fromiter((float(v) for v in rfile.readline().rstrip().split()),
                      float_)
         results.append(z)
     #
     newdata1 = numpy.array([[-2.5, 0.0, 2.5], [0., 0., 0.]])
     newdata2 = numpy.array([[-0.5, 0.5], [0., 0.]])
     #
     madeup = loess(x,y)
     self.d = (x, y, results, newdata1, newdata2, madeup)
Esempio n. 5
0
 def test_1dbasic_alt(self):
     "Basic test 1d - part #2"
     (E, NOx, _, _, _, results) = self.d
     gas_null = loess(E, NOx)
     gas_null.model.span = 1.0
     gas_null.fit()
     assert_almost_equal(gas_null.outputs.fitted_values, results[1], 5)
     assert_almost_equal(gas_null.outputs.enp, 3.5, 1)
     assert_almost_equal(gas_null.outputs.s, 0.5197, 4)
Esempio n. 6
0
 def test_1dbasic(self):
     "Basic test 1d"
     (E, NOx, _, _, _, results) = self.d
     gas = loess(E,NOx)
     gas.model.span = 2./3.
     gas.fit()
     assert_almost_equal(gas.outputs.fitted_values, results[0], 6)
     assert_almost_equal(gas.outputs.enp, 5.5, 1)
     assert_almost_equal(gas.outputs.s, 0.3404, 4)
Esempio n. 7
0
 def test_2dbasic(self):
     "2D standard"
     (x, y, results, _, _, madeup) = self.d
     madeup = loess(x,y)
     madeup.model.span = 0.5
     madeup.model.normalize = True
     madeup.fit()
     assert_almost_equal(madeup.outputs.fitted_values, results[0], 5)
     assert_almost_equal(madeup.outputs.enp, 14.9, 1)
     assert_almost_equal(madeup.outputs.s, 0.9693, 4)
Esempio n. 8
0
 def test_1dpredict_2(self):
     "Basic test 1d - new predictions"
     (E, NOx, _, newdata, _, results) = self.d        
     gas = loess(E,NOx, span=2./3.)
     gas.predict(newdata, stderror=True)
     gas.predicted.confidence(0.99)
     assert_almost_equal(gas.predicted.confidence_intervals.lower,
                         results[3][0::3], 6)
     assert_almost_equal(gas.predicted.confidence_intervals.fit,
                         results[3][1::3], 6)
     assert_almost_equal(gas.predicted.confidence_intervals.upper,
                         results[3][2::3], 6)
Esempio n. 9
0
 def test_2d_modflags_tot(self):
     "2D - modification of model flags"
     (x, y, results, _, _, madeup) = self.d
     madeup = loess(x,y)
     madeup.model.span = 0.8
     madeup.model.drop_square_flags = [True, False]
     madeup.model.parametric_flags = [True, False]
     assert_equal(madeup.model.parametric_flags[:2],[1,0])
     madeup.fit()        
     assert_almost_equal(madeup.outputs.fitted_values, results[1], 5)
     assert_almost_equal(madeup.outputs.enp, 6.9, 1)
     assert_almost_equal(madeup.outputs.s, 1.4804, 4)
Esempio n. 10
0
 def test_failures(self):
     "Tests failures"
     (E, NOx, gas_fit_E, _, _, _) = self.d       
     gas = loess(E,NOx, span=2./3.)
     # This one should fail (all parametric)
     gas.model.parametric_flags = True
     self.assertRaises(ValueError, gas.fit)
     # This one also (all drop_square)
     gas.model.drop_square_flags = True
     self.assertRaises(ValueError, gas.fit)
     gas.model.degree = 1
     self.assertRaises(ValueError, gas.fit)
     # This one should not (revert to std)
     gas.model.parametric_flags = False
     gas.model.drop_square_flags = False
     gas.model.degree = 2
     gas.fit()
     # Now, for predict .................
     gas.predict(gas_fit_E, stderror=False)
     # This one should fail (extrapolation & blending)
     self.assertRaises(ValueError, 
                       gas.predict, gas.predicted.values, stderror=False)
     # But this one should not ..........
     gas.predict(gas_fit_E, stderror=False)