Esempio n. 1
0
 def TestErroneous(self):
     """
     Test weird shapes, like flat lines other things
     """
     t = np.arange(self.t_max) / float(self.t_max)
     x_1 = np.exp(-t) + np.random.randn(self.t_max)
     x_flat = np.ones(self.t_max)
     self.assertTrue(fit(t, x_flat)[0] > fit(t, x_1)[0],
                     msg="Constant better than exponential")
Esempio n. 2
0
 def TestNan(self):
     """
     Test that nan values are higher than any non nan value
     """
     t = np.arange(1E5)
     x_1 = np.exp(-t)
     nan_idx = np.random.randint(1E5, size=5)
     x_nan = np.exp(-2 * t)
     x_nan[nan_idx] = np.nan
     self.assertTrue(fit(t, x_nan)[0] > fit(t, x_1)[0],
                     msg="Nan fit failure")
Esempio n. 3
0
 def TestErroneous(self):
     """
     Test weird shapes, like flat lines other things
     """
     t = np.arange(self.t_max) / float(self.t_max)
     x_1 = np.exp(-t) + np.random.randn(self.t_max)
     x_flat = np.ones(self.t_max)
     self.assertTrue(
         fit(t, x_flat)[0] > fit(t, x_1)[0],
         msg="Constant better than exponential"
     )
Esempio n. 4
0
 def TestLongTrial(self):
     """
     Test extra long trial to check for floating point craziness
     """
     t = np.arange(1E5)
     x_1 = np.exp(-t)
     x_2 = np.exp(-2 * t)
     x_1_noise = np.exp(-t) + 0.1 * np.random.randn(1E5)
     x_2_noise = np.exp(-2 * t) + 0.1 * np.random.randn(1E5)
     self.assertTrue(fit(t, x_1)[0] > fit(t, x_2)[0],
                     msg="Long trial monotonicity failure")
     self.assertTrue(fit(t, x_1_noise)[0] > fit(t, x_2_noise)[0],
                     msg="Long trial noisy monotonicity failure")
Esempio n. 5
0
 def TestNan(self):
     """
     Test that nan values are higher than any non nan value
     """
     t = np.arange(1E5)
     x_1 = np.exp(-t)
     nan_idx = np.random.randint(1E5, size=5)
     x_nan = np.exp(-2 * t)
     x_nan[nan_idx] = np.nan
     self.assertTrue(
         fit(t, x_nan)[0] > fit(t, x_1)[0],
         msg="Nan fit failure"
     )
Esempio n. 6
0
 def TestLongTrial(self):
     """
     Test extra long trial to check for floating point craziness
     """
     t = np.arange(1E5)
     x_1 = np.exp(-t)
     x_2 = np.exp(-2 * t)
     x_1_noise = np.exp(-t) + 0.1 * np.random.randn(1E5)
     x_2_noise = np.exp(-2 * t) + 0.1 * np.random.randn(1E5)
     self.assertTrue(
         fit(t, x_1)[0] > fit(t, x_2)[0],
         msg="Long trial monotonicity failure"
     )
     self.assertTrue(
         fit(t, x_1_noise)[0] > fit(t, x_2_noise)[0],
         msg="Long trial noisy monotonicity failure"
     )
Esempio n. 7
0
 def TestMonotonicity(self):
     """
     Tests to see that objective function is monotonic
     """
     t = np.arange(self.t_max) / float(self.t_max)
     x_1 = np.exp(-t)
     x_2 = np.exp(-2 * t)
     x_3 = np.exp(-3 * t)
     self.assertTrue(fit(t, x_1)[0] > fit(t, x_2)[0],
                     msg="Monotonicity failure")
     self.assertTrue(fit(t, x_2)[0] > fit(t, x_3)[0],
                     msg="Monotonicity failure")
     self.assertTrue(fit(t, x_1)[0] > fit(t, x_3)[0],
                     msg="Monotonicity failure")
Esempio n. 8
0
 def TestNoise(self):
     """
     Monotonicity plus varying amount of noise
     """
     perc_noise = 0.01
     t = np.arange(self.t_max) / float(self.t_max)
     x_1 = np.exp(-t) + np.random.randn(self.t_max) * perc_noise
     x_2 = np.exp(-2 * t) + np.random.randn(self.t_max) * perc_noise
     x_3 = np.exp(-3 * t) + np.random.randn(self.t_max) * perc_noise
     self.assertTrue(fit(t, x_1)[0] > fit(t, x_2)[0],
                     msg="Monotonicity failure")
     self.assertTrue(fit(t, x_2)[0] > fit(t, x_3)[0],
                     msg="Monotonicity failure")
     self.assertTrue(fit(t, x_1)[0] > fit(t, x_3)[0],
                     msg="Monotonicity failure")
Esempio n. 9
0
 def TestEndNoise(self):
     """
     Test that a bunch of noise at the end doesn't bork everything
     """
     t = np.arange(self.t_max) / float(self.t_max)
     x_1 = np.exp(-2 * t)
     x_rand_end = np.ones(self.t_max)
     x_rand_end[-3:] = 10 * np.random.randn(3)
     x_pos_end = np.ones(self.t_max)
     x_pos_end[-3:] *= 100
     x_neg_end = np.ones(self.t_max)
     x_neg_end[-3:] *= -100
     self.assertTrue(fit(t, x_rand_end)[0] > fit(t, x_1)[0],
                     msg="Random end noise does better than exponential")
     self.assertTrue(fit(t, x_pos_end)[0] > fit(t, x_1)[0],
                     msg="Positive end noise wins")
     self.assertTrue(fit(t, x_neg_end)[0] > fit(t, x_1)[0],
                     msg="Negative end noise wins")
Esempio n. 10
0
 def TestMonotonicity(self):
     """
     Tests to see that objective function is monotonic
     """
     t = np.arange(self.t_max) / float(self.t_max)
     x_1 = np.exp(-t)
     x_2 = np.exp(-2 * t)
     x_3 = np.exp(-3 * t)
     self.assertTrue(
         fit(t, x_1)[0] > fit(t, x_2)[0],
         msg="Monotonicity failure"
     )
     self.assertTrue(
         fit(t, x_2)[0] > fit(t, x_3)[0],
         msg="Monotonicity failure"
     )
     self.assertTrue(
         fit(t, x_1)[0] > fit(t, x_3)[0],
         msg="Monotonicity failure"
     )
Esempio n. 11
0
 def TestNoise(self):
     """
     Monotonicity plus varying amount of noise
     """
     perc_noise = 0.01
     t = np.arange(self.t_max) / float(self.t_max)
     x_1 = np.exp(-t) + np.random.randn(self.t_max) * perc_noise
     x_2 = np.exp(-2 * t) + np.random.randn(self.t_max) * perc_noise
     x_3 = np.exp(-3 * t) + np.random.randn(self.t_max) * perc_noise
     self.assertTrue(
         fit(t, x_1)[0] > fit(t, x_2)[0],
         msg="Monotonicity failure"
     )
     self.assertTrue(
         fit(t, x_2)[0] > fit(t, x_3)[0],
         msg="Monotonicity failure"
     )
     self.assertTrue(
         fit(t, x_1)[0] > fit(t, x_3)[0],
         msg="Monotonicity failure"
     )
Esempio n. 12
0
 def TestEndNoise(self):
     """
     Test that a bunch of noise at the end doesn't bork everything
     """
     t = np.arange(self.t_max) / float(self.t_max)
     x_1 = np.exp(-2 * t)
     x_rand_end = np.ones(self.t_max)
     x_rand_end[-3:] = 10 * np.random.randn(3)
     x_pos_end = np.ones(self.t_max)
     x_pos_end[-3:] *= 100
     x_neg_end = np.ones(self.t_max)
     x_neg_end[-3:] *= -100
     self.assertTrue(
         fit(t, x_rand_end)[0] > fit(t, x_1)[0],
         msg="Random end noise does better than exponential"
     )
     self.assertTrue(
         fit(t, x_pos_end)[0] > fit(t, x_1)[0],
         msg="Positive end noise wins"
     )
     self.assertTrue(
         fit(t, x_neg_end)[0] > fit(t, x_1)[0],
         msg="Negative end noise wins"
     )