Exemplo n.º 1
0
 def test_input_shape_tabular_valid(self):
     test_num_samples = [1, 2, 1024]
     test_num_features = [1, 2, 1024]
     for num_samples in test_num_samples:
         for num_features in test_num_features:
             x = np.random.random_sample(size=(num_samples, num_features))
             n, input_dim = Validation.get_input_dimension(x)
             self.assertEqual(n, num_samples)
             self.assertEqual(input_dim, (num_features,))
Exemplo n.º 2
0
 def test_input_shape_time_series_variable_valid(self):
     test_num_samples = [2, 3, 1024]
     test_num_lens = [1, 2, 256]
     test_num_features = [1, 2, 1024]
     for num_samples in test_num_samples:
         for num_features in test_num_features:
             x = [np.random.random_sample(size=(test_num_lens[i % len(test_num_lens)], num_features))
                  for i in range(num_samples)]
             n, input_dim = Validation.get_input_dimension(x)
             self.assertEqual(n, num_samples)
             self.assertEqual(input_dim, (None, num_features))
Exemplo n.º 3
0
 def test_input_shape_time_series_fixed_valid(self):
     test_num_samples = [1, 2, 1024]
     test_num_lens = [1, 2, 256]
     test_num_features = [1, 2, 1024]
     for num_samples in test_num_samples:
         for ts_length in test_num_lens:
             for num_features in test_num_features:
                 x = np.random.random_sample(size=(num_samples, ts_length, num_features))
                 n, input_dim = Validation.get_input_dimension(x)
                 self.assertEqual(n, num_samples)
                 self.assertEqual(input_dim, (ts_length, num_features))
Exemplo n.º 4
0
 def test_input_shape_invalid_1dim(self):
     with self.assertRaises(ValueError):
         Validation.get_input_dimension([1])
     with self.assertRaises(ValueError):
         Validation.get_input_dimension([1, 2, 3])
     with self.assertRaises(ValueError):
         Validation.get_input_dimension([None])
Exemplo n.º 5
0
 def test_input_shape_image_fixed_valid(self):
     test_num_samples = [1, 2, 1024]
     test_num_rows = [1, 2, 256]
     test_num_cols = [1, 2, 256]
     test_num_channels = [1, 2, 3]
     for num_samples in test_num_samples:
         for rows in test_num_rows:
             for cols in test_num_cols:
                 for num_channels in test_num_channels:
                     x = np.random.random_sample(size=(num_samples, rows, cols, num_channels))
                     n, input_dim = Validation.get_input_dimension(x)
                     self.assertEqual(n, num_samples)
                     self.assertEqual(input_dim, (rows, cols, num_channels))
Exemplo n.º 6
0
 def test_input_shape_volume_fixed_valid(self):
     test_num_samples = [1, 2, 128]
     test_num_voxels = [1, 2, 64]
     test_num_channels = [1, 2, 3]
     for num_samples in test_num_samples:
         for rows in test_num_voxels:
             for cols in test_num_voxels:
                 for depth in test_num_voxels:
                     for num_channels in test_num_channels:
                         x = np.random.random_sample(size=(num_samples, rows, cols, depth, num_channels))
                         n, input_dim = Validation.get_input_dimension(x)
                         self.assertEqual(n, num_samples)
                         self.assertEqual(input_dim, (rows, cols, depth, num_channels))
Exemplo n.º 7
0
 def test_input_shape_volume_variable_valid(self):
     test_num_samples = [2, 3, 128]
     test_num_lens = [2, 3, 64]
     test_num_features = [1, 2, 3]
     for num_samples in test_num_samples:
         for num_features in test_num_features:
             x = [np.random.random_sample(size=(test_num_lens[i % len(test_num_lens)],
                                                test_num_lens[(i + 1) % len(test_num_lens)],
                                                test_num_lens[(i + 2) % len(test_num_lens)],
                                                num_features))
                  for i in range(num_samples)]
             n, input_dim = Validation.get_input_dimension(x)
             self.assertEqual(n, num_samples)
             self.assertEqual(input_dim, (None, None, None, num_features))
Exemplo n.º 8
0
    def _build_model(self, X, y):
        Validation.check_dataset(X, y)

        if Validation.is_variable_length(X):
            raise ValueError("Variable length inputs to CXPlain are currently not supported.")

        n, p = Validation.get_input_dimension(X)
        output_dim = Validation.get_output_dimension(y)

        if self.model is None:
            if self.num_models == 1:
                build_fun = self._build_single
            else:
                build_fun = self._build_ensemble

            self.model, self.prediction_model = build_fun(input_dim=p, output_dim=output_dim)
Exemplo n.º 9
0
 def test_input_shape_invalid_none(self):
     with self.assertRaises(ValueError):
         Validation.get_input_dimension(None)