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()
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)
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)
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)