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.assertAlmostEqual(p[0], 1.0, 5) self.assertAlmostEqual(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.assertAlmostEqual(p[0], 1.0, 5) self.assertAlmostEqual(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) # Fixing a = -power =4 p, dp = fit.fit(power=-4) # Test results self.assertAlmostEqual(p[0], 4) self.assertAlmostEqual(p[1], -7.8, 3)
def skip_test_fit_line_data_no_weight(self): """ Fit_Test_1: test linear fit, ax +b, without fixing the power a """ # Create invariant object. Background and scale left as defaults. fit = invariant.Extrapolator(data=self.data) # Let the power float (not fixed) p, dp = fit.fit(power=None) # Test results self.assertAlmostEqual(p[0], 2.4727, 3) self.assertAlmostEqual(p[1], 0.6, 3)
def test_fit_line_data(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.3983, 3) self.assertAlmostEquals(p[1], 0.87833, 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)
def test_fit_line_data(self): """ Fit_Test_1: test linear fit, ax +b. The power law is calculated on the log data so that B * x^A becomes logB + A logX = ax+b. For the extrapolation a can be fixed (usually to -4) or floating. Here we test letting it float. """ # Create invariant object. Background and scale left as defaults. fit = invariant.Extrapolator(data=self.data) # Let the power float (not fixed) p, dp = fit.fit(power=None) # Test results self.assertAlmostEqual(p[0], 2.3983, 3) self.assertAlmostEqual(p[1], 0.87833, 3)