Example #1
0
 def test_run_optimize_no_prior(self):
     "Tests for exception when there is no default theta_init"
     t = np.arange(0, 1, 0.01)
     S = np.random.random(t.size)
     kursl = KurslMethod()
     with self.assertRaises(ValueError) as error:
         kursl.run_optimize(t, S)
     self.assertEqual("No prior parameters were assigned.",
                      str(error.exception))
Example #2
0
    def test_run_optimize_default(self):
        """Tests optmization with default scipy optimization method,
        which is L-BFGS and so it takes a while.
        """
        t = np.arange(0, 1, 0.01)
        theta = np.array([
            [10, 0, 1, 0],
            [18, 0, 2, 0],
        ])
        c1 = theta[0, 2] * np.cos(theta[0, 0] * t + theta[0, 1])
        c2 = theta[1, 2] * np.cos(theta[1, 0] * t + theta[1, 1])
        S = c1 + c2

        theta_init = theta.copy()
        theta_init[0, 0] -= 1
        theta_init[1, 0] += 1

        kursl = KurslMethod()
        _theta = kursl.run_optimize(t, S, theta_init=theta_init, maxiter=20)
        self.assertEqual(_theta.shape, theta.shape, "Results in same shape")
        self.assertTrue(np.allclose(theta, _theta, rtol=1e-1, atol=1e-1),
                        "Expecting fit to be similar to theta initial value")