Esempio n. 1
0
    def test_compute_prior_default(self):
        """Test default setting for computing prior parameters.
        Assumes single order for KurSL."""
        t = np.arange(0, 5, 0.001)
        c1 = 2 * np.cos(2 * 2 * np.pi * t + 0)
        c2 = 1.1 * np.cos(5 * 2 * np.pi * t + 1)
        S = c1 + c2

        kursl = KurslMethod()
        kursl.compute_prior(t, S)
        params = kursl.theta_init
        params[:, 1] = (params[:, 1] + 2 * np.pi) % (2 * np.pi)

        oscN = kursl.oscN
        paramN = kursl.paramN
        # Testing for number
        self.assertEqual(oscN, 2, "2 oscillators")
        self.assertEqual(paramN, 4, "4 params per oscillator")
        self.assertEqual(params.shape, (2, 4), "Two oscillators (W, ph, A, K)")

        # Testing for frequency
        self.assertTrue(
            abs(params[0, 0] - 5 * 2 * np.pi) < 0.05,
            "Expected {} rad/s, Got {} [rad/s]".format(5 * 2 * np.pi,
                                                       params[0, 0]))
        self.assertTrue(
            abs(params[1, 0] - 2 * 2 * np.pi) < 0.05,
            "Expected {} rad/s, Got {} [rad/s]".format(2 * 2 * np.pi,
                                                       params[1, 0]))

        # Testing for phase
        self.assertTrue(
            abs(params[0, 1] - 1) < 0.001,
            "Expected phase {}, Got {}.".format(1, params[0, 1]))
        self.assertTrue(
            abs(params[1, 1] - 0) < 0.001,
            "Expected phase {}, Got {}.".format(0, params[1, 1]))

        # Testing for amplitude
        self.assertTrue(
            abs(params[0, 2] - 1.1) < 0.1,
            "Expected amp {}, Got {}.".format(1.1, params[0, 2]))
        self.assertTrue(
            abs(params[1, 2] - 2) < 0.1,
            "Expected amp {}, Got {}.".format(2, params[1, 2]))

        # Testing for coupling
        self.assertEqual(params[0, 3], 0, "First->Second coupling should be 0")
        self.assertEqual(params[1, 3], 0, "Second->First coupling should be 0")
Esempio n. 2
0
    def test_compute_prior_high_order(self):
        t = np.arange(0, 5, 0.001)
        c1 = 2 * np.cos(2 * 2 * np.pi * t + 0)
        c2 = 1.1 * np.cos(5 * 2 * np.pi * t + 1)
        c3 = 4.3 * np.cos(8 * 2 * np.pi * t + 5)
        S = c1 + c2 + c3

        nH = 4
        oscN, paramN = 3, 3 + nH * 2
        kursl = KurslMethod(nH)
        kursl.compute_prior(t, S)
        params = kursl.theta_init

        self.assertEqual(kursl.nH, nH)
        self.assertEqual(kursl.oscN, 3, "Three oscillators")
        self.assertEqual(
            params.shape, (oscN, paramN),
            "Expected number of parameters: oscN*( 3 + nH*(oscN-1) )")