Beispiel #1
0
    def setUp(self):
        rng = np.random.RandomState(42)
        Cluster.global_rng = rng
        Genotype.global_rng = rng

        setattr(Cluster, "num_dims", 2)

        clust1 = Cluster(50)
        clust1.mean = np.array([0, 0])
        clust1.cov = np.array([[1, 0], [0, 1]])
        clust2 = Cluster(30)
        clust2.mean = np.array([5, 5])
        clust2.cov = np.array([[5, 0], [0, 10]])
        self.indiv1 = Genotype([clust1, clust2])
        self.indiv1.create_views()
        self.indiv1.resample_values()

        clust3 = Cluster(50)
        clust3.mean = np.array([2, 2])
        clust3.cov = np.array([[2, 0], [0, 2]])
        clust4 = Cluster(30)
        clust4.mean = np.array([10, 10])
        clust4.cov = np.array([[4, 0], [0, 2]])
        self.indiv2 = Genotype([clust3, clust4])
        self.indiv2.create_views()
        self.indiv2.resample_values()
Beispiel #2
0
 def setUp(self):
     # Whatever setup is needed
     rng = np.random.RandomState(42)
     Genotype.global_rng = rng
     Cluster.global_rng = rng
     sizes = [190, 20, 30, 110]
     self.indiv = Genotype([Cluster(size) for size in sizes])
     self.indiv.create_views()
     self.indiv.resample_values()
     hawks.objectives.Silhouette.setup_indiv(self.indiv)
Beispiel #3
0
    def test_eigenratio_eccentric(self):
        clust1 = Cluster(50)
        clust1.mean = np.array([0, 0])
        clust1.cov = np.array([[10, 0], [0, 1]])

        clust2 = Cluster(80)
        clust2.mean = np.array([0, 0])
        clust2.cov = np.array([[9.9, 0], [0, 1]])

        indiv = Genotype([clust1, clust2])
        eigen_ratio = hawks.constraints.eigenval_ratio(indiv)

        self.assertEqual(eigen_ratio, 10)
Beispiel #4
0
 def setUp(self):
     # Whatever setup is needed
     rng = np.random.RandomState(42)
     Genotype.global_rng = rng
     Cluster.global_rng = rng
     sizes = [190, 20, 30, 110]
     setattr(Cluster, "num_dims", 2)
     setattr(Cluster, "initial_mean_upper", 1.0)
     setattr(Cluster, "initial_cov_upper", 0.5)
     self.indiv = Genotype([Cluster(size) for size in sizes])
     self.indiv.create_views()
     self.indiv.resample_values()
     hawks.objectives.Silhouette.setup_indiv(self.indiv)
Beispiel #5
0
    def test_overlap_same(self):
        clust1 = Cluster(4000)
        clust1.mean = np.array([0, 0])
        clust1.cov = np.array([[1, 0], [0, 1]])

        clust2 = Cluster(4000)
        clust2.mean = np.array([0, 0])
        clust2.cov = np.array([[1, 0], [0, 1]])

        indiv = Genotype([clust1, clust2])
        indiv.create_views()
        indiv.resample_values()

        overlap = hawks.constraints.overlap(indiv)

        self.assertAlmostEqual(overlap, 0.5, places=1)
Beispiel #6
0
    def test_overlap_separated(self):
        clust1 = Cluster(50)
        clust1.mean = np.array([0, 0])
        clust1.cov = np.array([[1, 0], [0, 1]])

        clust2 = Cluster(80)
        clust2.mean = np.array([10, 10])
        clust2.cov = np.array([[1, 0], [0, 1]])

        indiv = Genotype([clust1, clust2])
        indiv.create_views()
        indiv.resample_values()

        overlap = hawks.constraints.overlap(indiv)

        self.assertEqual(overlap, 0)
Beispiel #7
0
    def test_silhouette_singleton_cluster(self):
        rng = np.random.RandomState(42)
        Genotype.global_rng = rng
        Cluster.global_rng = rng
        sizes = [1, 20, 30, 110]
        self.indiv = Genotype([Cluster(size) for size in sizes])
        self.indiv.create_views()
        self.indiv.resample_values()
        hawks.objectives.Silhouette.setup_indiv(self.indiv)

        hawks.objectives.Silhouette.eval_objective(self.indiv)

        close_to_sk = np.isclose(
            silhouette_score(self.indiv.all_values,
                             self.indiv.labels,
                             metric="sqeuclidean"), self.indiv.silhouette)

        self.assertTrue(close_to_sk)