Beispiel #1
0
    def test_arithmetic_operators(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)

        spectral_array = np.random.rand(32)

        # Multiplication
        X_3d *= 2
        X_3d *= spectral_array
        X_4d *= 2
        X_4d *= spectral_array

        # Division
        X_3d /= 2
        X_3d /= spectral_array
        X_4d /= 2
        X_4d /= spectral_array

        # Addition
        X_3d += 2
        X_3d += spectral_array
        X_4d += 2
        X_4d += spectral_array

        # Subtraction
        X_3d -= 2
        X_3d -= spectral_array
        X_4d -= 2
        X_4d -= spectral_array
    def test_preprocessing(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)

        for preprocess_type in PREPROCESSING_TYPES:
            X_3d.preprocess(mdl=preprocess_type())

            X_4d.preprocess(mdl=preprocess_type())
Beispiel #3
0
    def test_scree(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)
        scree_3d = X_3d.scree()
        scree_4d = X_4d.scree()

        assert scree_3d.shape == (X_3d.shape[-1], )
        assert scree_4d.shape == (X_4d.shape[-1], )
Beispiel #4
0
    def test_data_types(self):
        data_empty_list = []
        data_1d = np.random.rand(20)
        data_2d = np.random.rand(2, 20)

        # data type checks
        with pytest.raises(TypeError): hp.Dataset(data_empty_list)
        with pytest.raises(TypeError): hp.Dataset(data_1d)
        with pytest.raises(TypeError): hp.Dataset(data_2d)
Beispiel #5
0
    def test_flatten(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)
        flattened_3d = X_3d.flatten()
        flattened_4d = X_4d.flatten()

        assert flattened_3d.shape == (X_3d.shape[0] * X_3d.shape[1],
                                      X_3d.shape[2])
        assert flattened_4d.shape == (X_4d.shape[0] * X_4d.shape[1] *
                                      X_4d.shape[2], X_4d.shape[3])
Beispiel #6
0
    def test_cluster(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)

        for cluster_type in CLUSTER_TYPES:
            if not type(cluster_type()) in (AffinityPropagation, DBSCAN, MeanShift):
                lbls_3d, spcs3d = X_3d.cluster(
                    mdl=cluster_type(n_clusters=2),
                    decomposed=False
                )
                lbls_4d, spcs4d = X_4d.cluster(
                    mdl=cluster_type(n_clusters=2),
                    decomposed=False
                )

                lbls_decomp_3d, spcs_decomp_3d = X_3d.cluster(
                    mdl=cluster_type(n_clusters=2),
                    decomposed=True,
                    pca_comps=2
                )
                lbls_decomp_4d, spcs_decomp_4d = X_4d.cluster(
                    mdl=cluster_type(n_clusters=2),
                    decomposed=True,
                    pca_comps=2
                )

                assert lbls_3d.shape == (8, 8)
                assert lbls_4d.shape == (8, 8, 2)
                assert spcs3d.shape == (32, 2)
                assert spcs4d.shape == (32, 2)
                assert lbls_decomp_3d.shape == (8, 8)
                assert lbls_decomp_4d.shape == (8, 8, 2)
                assert spcs_decomp_3d.shape == (32, 2)
                assert spcs_decomp_4d.shape == (32, 2)

            elif type(cluster_type()) in (AffinityPropagation, DBSCAN, MeanShift):
                X_3d.cluster(
                    mdl=cluster_type(),
                    decomposed=False
                )
                X_4d.cluster(
                    mdl=cluster_type(),
                    decomposed=False
                )

                X_3d.cluster(
                    mdl=cluster_type(),
                    decomposed=True,
                    pca_comps=2
                )
                X_4d.cluster(
                    mdl=cluster_type(),
                    decomposed=True,
                    pca_comps=2
                )
Beispiel #7
0
    def test_decompose(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)

        for decomp_type in DECOMPOSE_TYPES:
            ims_3d, spcs3d = X_3d.decompose(mdl=decomp_type(n_components=2))
            ims_4d, spcs4d = X_4d.decompose(mdl=decomp_type(n_components=2))

            assert ims_3d.shape == (8, 8, 2)
            assert spcs3d.shape == (32, 2)
            assert ims_4d.shape == (8, 8, 2, 2)
            assert spcs4d.shape == (32, 2)
Beispiel #8
0
    def test_data_access(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)

        arr3d = X_3d[:2, :2, :]
        arr4d = X_4d[:2, :2, :1, :]

        assert arr3d.shape == (2, 2, 32)
        assert arr4d.shape == (2, 2, 1, 32)

        X_3d[0, 0, :] = np.random.rand(32)
        X_4d[0, 0, 0, :] = np.random.rand(32)
Beispiel #9
0
    def test_abundance(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)

        lbls_3d = X_3d.abundance(spectra=np.random.rand(32, 5),
                                 plot=False,
                                 return_arrs=True)

        lbls_4d = X_4d.abundance(spectra=np.random.rand(32, 5),
                                 plot=False,
                                 return_arrs=True)

        assert lbls_3d.shape == (8, 8, 5)
        assert lbls_4d.shape == (8, 8, 2, 5)
Beispiel #10
0
    def test_smoothing(self):
        X_3d = hp.Dataset(self.data_3d)
        X_3d.smoothing = 'savitzky_golay'
        X_3d.smoothen(window_length=5, polyorder=3)

        X_3d = hp.Dataset(self.data_3d)
        X_3d.smoothing = 'gaussian_filter'
        X_3d.smoothen(sigma=0.5)

        X_4d = hp.Dataset(self.data_4d)
        X_4d.smoothing = 'savitzky_golay'
        X_4d.smoothen(window_length=5, polyorder=3)

        X_4d = hp.Dataset(self.data_4d)
        X_4d.smoothing = 'gaussian_filter'
        X_4d.smoothen(sigma=0.5)
Beispiel #11
0
    def test_mixture(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)

        for mixture_type in MIXTURE_TYPES:
            lbls_3d, spcs_3d = X_3d.mixture(mdl=mixture_type(n_components=2),
                                            plot=False,
                                            return_arrs=True)

            lbls_4d, spcs_4d = X_4d.mixture(mdl=mixture_type(n_components=2),
                                            plot=False,
                                            return_arrs=True)

            assert lbls_3d.shape == (8, 8)
            assert lbls_4d.shape == (8, 8, 2)
            assert spcs_3d.shape == (32, 2)
            assert spcs_4d.shape == (32, 2)
Beispiel #12
0
    def test_vca(self):
        X_3d = hp.Dataset(self.data_3d)
        X_4d = hp.Dataset(self.data_4d)

        spectra_3d, coords_3d = X_3d.vca(
            n_components=2,
            plot=False,
            return_arrs=True
        )

        spectra_4d, coords_4d = X_4d.vca(
            n_components=2,
            plot=False,
            return_arrs=True
        )

        assert spectra_3d.shape == (32, 2)
        assert spectra_4d.shape == (32, 2)
Beispiel #13
0
 def test_preprocess_methods(self):
     X_3d = hp.Dataset(self.data_3d)
     X_3d.scale()
     X_3d = hp.Dataset(self.data_3d)
     X_3d.robust_scale()
     X_3d = hp.Dataset(self.data_3d)
     X_3d.normalize()
     X_4d = hp.Dataset(self.data_4d)
     X_4d.scale()
     X_4d = hp.Dataset(self.data_4d)
     X_4d.robust_scale()
     X_4d = hp.Dataset(self.data_4d)
     X_4d.normalize()
 def test_for_fail(self):
     X_3d = hp.Dataset(self.data_3d)
     with pytest.raises(TypeError):
         X_3d.preprocess(mdl=np.zeros(2))
Beispiel #15
0
 def test_print_dataset(self):
     X_3d = hp.Dataset(self.data_3d)
     X_4d = hp.Dataset(self.data_4d)
     print(X_3d)
     print(X_4d)