def setUp(self):
        self.n_signals = 4
        self.n_samples = 10

        self.arma_orders = [(3, 2), (1, 5)]
        self.dataset = RandomArmaDataset(self.n_signals, self.n_samples,
                                         self.arma_orders)
 def test_normalize_returns_same_signals_with_unit_variance(self):
     dataset_norm = RandomArmaDataset(**self.kwargs, normalize=True)
     for sig, sig_norm in zip(self.dataset, dataset_norm):
         # noinspection PyTypeChecker
         self.assertAlmostEqual(np.std(sig_norm.y), 1)
         np.testing.assert_allclose(sig_norm.y, sig.y / np.std(sig.y))
         np.testing.assert_allclose(sig_norm.u, sig.u)
         np.testing.assert_equal(sig_norm.usage_seq, sig.usage_seq)
 def setUp(self):
     self.n_signals = 3
     self.n_samples = 100
     self.arma_orders = [(3, 2), (2, 4), (1, 5), (4, 0)]
     self.kwargs = dict(n_signals=self.n_signals,
                        n_samples=self.n_samples,
                        arma_orders=self.arma_orders)
     self.dataset = RandomArmaDataset(**self.kwargs)
 def test_arma_kws_forwarded_to_make_random_arma(self):
     dataset = RandomArmaDataset(3,
                                 20,
                                 arma_orders=[(1, 1), (2, 2)],
                                 arma_kws={"bias_range": (0, 1)})
     for crt_armas in dataset.armas:
         for crt_arma in crt_armas:
             self.assertGreater(crt_arma.bias, 1e-3)
    def setUp(self):
        self.n_signals = 4
        self.n_samples = 10

        self.arma_orders = [(3, 2), (1, 5)]
        self.arma_hsmm_kws = {"min_dwell_time": 5}
        self.dataset = RandomArmaDataset(self.n_signals, self.n_samples,
                                         self.arma_orders,
                                         **self.arma_hsmm_kws)
    def test_source_is_copied_before_using(self):
        dataset = RandomArmaDataset(1,
                                    23, [(1, 2), (3, 0)],
                                    source=sources.GaussianNoise())

        sig1 = dataset[0]
        sig2 = dataset[0]

        np.testing.assert_equal(sig1.y, sig2.y)
        np.testing.assert_equal(sig1.u, sig2.u)
        np.testing.assert_equal(sig1.usage_seq, sig2.usage_seq)
    def create_dataset(self, fix_scale: Optional[float]):
        with mock.patch(
                "bioslds.dataset.sources.fix_source_scale") as MockFixScale:
            MockFixScale.side_effect = self.scales
            dataset = RandomArmaDataset(
                self.n_signals,
                self.n_samples,
                arma_orders=[(0, 0),
                             (0, 0)],  # ARMAs simply return their inputs
                fix_scale=fix_scale,
            )

        return dataset
    def test_init_kwargs_forwarded_to_arma_hsmm(self):
        start_prob = [1, 0, 0]
        trans_mat = [[0, 1, 0], [0, 0, 1], [1, 0, 0]]

        n_samples = 25
        dataset = RandomArmaDataset(
            2,
            n_samples,
            arma_orders=[(3, 0), (2, 1), (1, 3)],
            start_prob=start_prob,
            trans_mat=trans_mat,
        )
        for crt_sig in dataset:
            np.testing.assert_equal(crt_sig.usage_seq,
                                    np.arange(n_samples) % 3)
    def setUp(self):
        self.n_signals = 3
        self.n_samples = 100

        self.alphas = [0.99, 0.95]
        self.armas = [Arma([_], []) for _ in self.alphas]

        self.y0 = 1.0
        self.dataset = RandomArmaDataset(
            self.n_signals,
            self.n_samples,
            armas=self.armas,
            source=sources.Constant(0),
            initial_conditions=([self.y0], []),
        )
    def setUp(self):
        self.n_signals = 3
        self.n_samples = 100
        self.arma_orders = [(3, 3), (2, 3)]
        self.fix_scale = 1.5
        self.scales = [2.3, 0.2, 1.2, 1.5, 0.2, 1.0]

        with mock.patch(
                "bioslds.dataset.sources.fix_source_scale") as MockFixScale:
            MockFixScale.side_effect = self.scales
            self.dataset = RandomArmaDataset(
                self.n_signals,
                self.n_samples,
                arma_orders=self.arma_orders,
                fix_scale=self.fix_scale,
            )
            self.mock_fix_scale = MockFixScale
 def setUp(self):
     self.n_signals = 3
     self.n_samples = 32
     self.dataset = RandomArmaDataset(self.n_signals, self.n_samples,
                                      [(3, 0), (1, 1)])
 def create_dataset(self, rng) -> RandomArmaDataset:
     dataset = RandomArmaDataset(self.n_signals,
                                 self.n_samples,
                                 self.arma_orders,
                                 rng=rng)
     return dataset
 def test_raises_if_no_armas_and_no_arma_orders(self):
     with self.assertRaises(ValueError):
         RandomArmaDataset(3, 3)
 def setUp(self):
     self.n_signals = 5
     self.n_samples = 25
     self.dataset = RandomArmaDataset(self.n_signals, self.n_samples,
                                      [(1, 1), (2, 1)])