class ComputeListNbCoeffParametersTest(unittest.TestCase):

    N = 3
    M = 3
    M_list = [3, 2, 3]
    basis = LaguerreBasis(0.1, M)
    basis_list = [LaguerreBasis(0.1, m) for m in M_list]
    result = {
        'volterra': [3, 6, 10],
        'hammerstein': list([
            M,
        ] * N)
    }
    result_list = {'volterra': [3, 3, 10], 'hammerstein': M_list}

    def test_proj(self):
        for basis, is_list, result in [(self.basis, False, self.result),
                                       (self.basis_list, True,
                                        self.result_list)]:
            for sys_type in {'volterra', 'hammerstein'}:
                with self.subTest(i=(sys_type, basis)):
                    nb_coeff = _compute_list_nb_coeff(self.N, sys_type, None,
                                                      basis, is_list)
                    self.assertEqual(nb_coeff, result[sys_type])

    def test_no_proj(self):
        for M, is_list, result in [(self.M, False, self.result),
                                   (self.M_list, False, self.result_list)]:
            for sys_type in {'volterra', 'hammerstein'}:
                with self.subTest(i=(sys_type, M)):
                    nb_coeff = _compute_list_nb_coeff(self.N, sys_type, M,
                                                      None, is_list)
                    self.assertEqual(nb_coeff, result[sys_type])
 def compute_basis_func(self, sig, sorted_by):
     if isinstance(self.M, int):
         orthogonal_basis = LaguerreBasis(self.pole,
                                          self.M,
                                          unit_delay=self.unit_delay)
     else:
         orthogonal_basis = [
             LaguerreBasis(self.pole, m, unit_delay=self.unit_delay)
             for m in self.M
         ]
     return projected_hammerstein_basis(sig,
                                        self.N,
                                        orthogonal_basis,
                                        sorted_by=sorted_by)
    def _make_estim(self, form):
        poles = np.random.uniform(size=(self.N, ))

        for iter_nb in range(self.iter_max):
            basis = [
                LaguerreBasis(pole, self.K, unit_delay=self.unit_delay)
                for pole in poles
            ]
            est_kernels = order_method(self.sig,
                                       self.outputs,
                                       self.N,
                                       orthogonal_basis=basis,
                                       out_form=form)
            for n, proj in est_kernels.items():
                poles[n - 1] = laguerre_pole_optimization(
                    poles[n - 1], proj, n, self.K)
        return poles
    def setUp(self):
        self.sig = np.random.normal(size=(self.L, ))
        basis = [
            LaguerreBasis(pole, self.K, unit_delay=self.unit_delay)
            for pole in self.poles.values()
        ]
        phi = projected_volterra_basis(self.sig,
                                       self.N,
                                       basis,
                                       True,
                                       sorted_by='order')
        self.outputs = np.zeros((self.N, self.L))
        for n, val in phi.items():
            self.outputs[n - 1, :] = np.dot(val, self.coeff[n])

        self.results = np.zeros((len(self.tests), self.N))
        for ind, form in enumerate(self.tests):
            self.results[ind, :] = self._make_estim(form)
class CheckParametersTest(unittest.TestCase):

    N = 3
    basis = LaguerreBasis(0.1, 3)

    def test_wrong_system_type_error(self):
        self.assertRaises(ValueError, _check_parameters, self.N, '', 5, None)

    def test_no_M_and_no_basis_error(self):
        self.assertRaises(ValueError, _check_parameters, self.N, 'volterra',
                          None, None)

    def test_n_M_and_basis_error(self):
        self.assertWarns(UserWarning, _check_parameters, self.N, 'volterra', 5,
                         self.basis)

    def test_wrong_M_error(self):
        for M in (0.5, [0.5, 2, 3]):
            with self.subTest(i=M):
                self.assertRaises(TypeError, _check_parameters, self.N,
                                  'volterra', M, None)

    def test_wrong_basis_error(self):
        for basis in (0.5, [self.basis, self.basis, dict()]):
            with self.subTest(i=basis):
                self.assertRaises(TypeError, _check_parameters, self.N,
                                  'volterra', None, basis)

    def test_is_list_false(self):
        M, orthogonal_basis_is_list = _check_parameters(
            self.N, 'volterra', None, self.basis)
        self.assertFalse(orthogonal_basis_is_list)

    def test_is_list_true(self):
        M, orthogonal_basis_is_list = _check_parameters(
            self.N, 'volterra', None, (self.basis, ) * 3)
        self.assertTrue(orthogonal_basis_is_list)
Exemple #6
0
 def _set_kwargs(self):
     return {'orthogonal_basis': [LaguerreBasis(0.01, 3),
                                  LaguerreBasis(0.01, 5),
                                  LaguerreBasis(0.01, 0),
                                  LaguerreBasis(0.01, 5)]}
Exemple #7
0
 def _set_kwargs(self):
     return {'orthogonal_basis': LaguerreBasis(0.01, 3)}