def test_fit_with_fixed_parameter(self): """ Linear fit for y=ax+b where a is fixed. """ # Create invariant object. Background and scale left as defaults. fit = invariant.Extrapolator(data=self.data) p, dp = fit.fit(power=-1.0) # Test results self.assertAlmostEquals(p[0], 1.0, 5) self.assertAlmostEquals(p[1], 0.0, 5)
def test_fit_linear_data(self): """ Simple linear fit """ # Create invariant object. Background and scale left as defaults. fit = invariant.Extrapolator(data=self.data) #a,b = fit.fit() p, dp = fit.fit() # Test results self.assertAlmostEquals(p[0], 1.0, 5) self.assertAlmostEquals(p[1], 0.0, 5)
def test_fit_line_data_fixed_no_weight(self): """ Fit_Test_2: test linear fit, ax +b, with 'a' fixed """ # Create invariant object. Background and scale left as defaults. fit = invariant.Extrapolator(data=self.data) #With holding a = -power =4 p, dp = fit.fit(power=-4) # Test results self.assertAlmostEquals(p[0], 4) self.assertAlmostEquals(p[1], -7.8, 3)
def skip_test_fit_line_data_no_weight(self): """ Fit_Test_1: test linear fit, ax +b, without fixed """ # Create invariant object. Background and scale left as defaults. fit = invariant.Extrapolator(data=self.data) ##Without holding p, dp = fit.fit(power=None) # Test results self.assertAlmostEquals(p[0], 2.4727, 3) self.assertAlmostEquals(p[1], 0.6, 3)
def test_fit_linear_data_with_noise_and_fixed_par(self): """ Simple linear fit with noise """ import random, math for i in range(len(self.data.y)): self.data.y[i] = self.data.y[i] + .1 * (random.random() - 0.5) # Create invariant object. Background and scale left as defaults. fit = invariant.Extrapolator(data=self.data) p, dp = fit.fit(power=-1.0) # Test results self.assertTrue(math.fabs(p[0] - 1.0) < 0.05) self.assertTrue(math.fabs(p[1]) < 0.1)