Exemple #1
0
    def test_iris(self):

        # Generate full set of constraints for comparison with reference implementation
        mask = (self.iris_labels[None] == self.iris_labels[:, None])
        a, b = np.nonzero(np.triu(mask, k=1))
        c, d = np.nonzero(np.triu(~mask, k=1))

        # Full metric
        mmc = MMC(convergence_threshold=0.01)
        mmc.fit(self.iris_points, [a, b, c, d])
        expected = [[+0.00046504, +0.00083371, -0.00111959, -0.00165265],
                    [+0.00083371, +0.00149466, -0.00200719, -0.00296284],
                    [-0.00111959, -0.00200719, +0.00269546, +0.00397881],
                    [-0.00165265, -0.00296284, +0.00397881, +0.00587320]]
        assert_array_almost_equal(expected, mmc.metric(), decimal=6)

        # Diagonal metric
        mmc = MMC(diagonal=True)
        mmc.fit(self.iris_points, [a, b, c, d])
        expected = [0, 0, 1.21045968, 1.22552608]
        assert_array_almost_equal(np.diag(expected), mmc.metric(), decimal=6)

        # Supervised Full
        mmc = MMC_Supervised()
        mmc.fit(self.iris_points, self.iris_labels)
        csep = class_separation(mmc.transform(), self.iris_labels)
        self.assertLess(csep, 0.15)

        # Supervised Diagonal
        mmc = MMC_Supervised(diagonal=True)
        mmc.fit(self.iris_points, self.iris_labels)
        csep = class_separation(mmc.transform(), self.iris_labels)
        self.assertLess(csep, 0.2)
Exemple #2
0
    def test_iris(self):

        # Generate full set of constraints for comparison with reference implementation
        n = self.iris_points.shape[0]
        mask = (self.iris_labels[None] == self.iris_labels[:, None])
        a, b = np.nonzero(np.triu(mask, k=1))
        c, d = np.nonzero(np.triu(~mask, k=1))

        # Full metric
        mmc = MMC(convergence_threshold=0.01)
        mmc.fit(self.iris_points, [a, b, c, d])
        expected = [[0.000514, 0.000868, -0.001195, -0.001703],
                    [0.000868, 0.001468, -0.002021, -0.002879],
                    [-0.001195, -0.002021, 0.002782, 0.003964],
                    [-0.001703, -0.002879, 0.003964, 0.005648]]
        assert_array_almost_equal(expected, mmc.metric(), decimal=6)

        # Diagonal metric
        mmc = MMC(diagonal=True)
        mmc.fit(self.iris_points, [a, b, c, d])
        expected = [0, 0, 1.210220, 1.228596]

        assert_array_almost_equal(np.diag(expected), mmc.metric(), decimal=6)

        # Supervised Full
        mmc = MMC_Supervised()
        mmc.fit(self.iris_points, self.iris_labels)
        csep = class_separation(mmc.transform(), self.iris_labels)
        self.assertLess(csep, 0.15)

        # Supervised Diagonal
        mmc = MMC_Supervised(diagonal=True)
        mmc.fit(self.iris_points, self.iris_labels)
        csep = class_separation(mmc.transform(), self.iris_labels)
        self.assertLess(csep, 0.2)
  def test_iris(self):

    # Generate full set of constraints for comparison with reference implementation
    mask = (self.iris_labels[None] == self.iris_labels[:, None])
    a, b = np.nonzero(np.triu(mask, k=1))
    c, d = np.nonzero(np.triu(~mask, k=1))

    # Full metric
    mmc = MMC(convergence_threshold=0.01)
    mmc.fit(self.iris_points, [a, b, c, d])
    expected = [[+0.00046504, +0.00083371, -0.00111959, -0.00165265],
                [+0.00083371, +0.00149466, -0.00200719, -0.00296284],
                [-0.00111959, -0.00200719, +0.00269546, +0.00397881],
                [-0.00165265, -0.00296284, +0.00397881, +0.00587320]]
    assert_array_almost_equal(expected, mmc.metric(), decimal=6)

    # Diagonal metric
    mmc = MMC(diagonal=True)
    mmc.fit(self.iris_points, [a, b, c, d])
    expected = [0, 0, 1.21045968, 1.22552608]
    assert_array_almost_equal(np.diag(expected), mmc.metric(), decimal=6)

    # Supervised Full
    mmc = MMC_Supervised()
    mmc.fit(self.iris_points, self.iris_labels)
    csep = class_separation(mmc.transform(), self.iris_labels)
    self.assertLess(csep, 0.15)

    # Supervised Diagonal
    mmc = MMC_Supervised(diagonal=True)
    mmc.fit(self.iris_points, self.iris_labels)
    csep = class_separation(mmc.transform(), self.iris_labels)
    self.assertLess(csep, 0.2)