def test_zero_clusters(self): io_graph = DenGraphIO(base_graph=DistanceGraph( nodes=[1, 2, 3, 4], distance=DeltaDistance(), symmetric=True), cluster_distance=1, core_neighbours=5) with self.assertRaises(ValueError): davies_bouldin_score(io_graph.clusters, io_graph.graph)
def test_two_cluster(self): io_graph = DenGraphIO(base_graph=DistanceGraph( nodes=[1, 2, 3, 4, 5, 6, 13, 14, 15, 16, 17, 18], distance=DeltaDistance(), symmetric=True), cluster_distance=5, core_neighbours=5) self.assertEqual( .25, davies_bouldin_score(io_graph.clusters, io_graph.graph))
def test_one_cluster(self): io_graph = DenGraphIO( base_graph=DistanceGraph( nodes=[1, 2, 3, 4, 5, 6], distance=DeltaDistance(), symmetric=True), cluster_distance=5, core_neighbours=5 ) self.assertEqual(-1, silhouette_score(io_graph.clusters, io_graph.graph))
def test_two_cluster(self): io_graph = DenGraphIO( base_graph=DistanceGraph( nodes=[1, 2, 3, 4, 5, 6, 13, 14, 15, 16, 17, 18], distance=DeltaDistance(), symmetric=True), cluster_distance=5, core_neighbours=5 ) self.assertAlmostEqual(123.4, calinski_harabasz_score(io_graph.clusters, io_graph.graph), 1)
def test_one_cluster(self): io_graph = DenGraphIO( base_graph=DistanceGraph( nodes=[1, 2, 3, 4, 5, 6], distance=DeltaDistance(), symmetric=True), cluster_distance=5, core_neighbours=5 ) with self.assertRaises(ValueError): calinski_harabasz_score(io_graph.clusters, io_graph.graph)
def test_get(self): cluster = DenGraphCluster(graph=DistanceGraph( nodes=[1, 2, 3, 4], distance=DeltaDistance(), symmetric=True)) with self.assertRaises(dengraph.graph.NoSuchEdge): cluster[1:2] cluster.categorize_node(1, cluster.CORE_NODE) with self.assertRaises(dengraph.graph.NoSuchEdge): cluster[1:2] cluster.categorize_node(2, cluster.BORDER_NODE) self.assertEqual(1, cluster[1:2]) with self.assertRaises(dengraph.graph.NoSuchEdge): cluster[3:2]
def setUp(self): self.io_graph = DenGraphIO(base_graph=DistanceGraph( nodes=[1, 2, 3, 4], distance=DeltaDistance(), symmetric=True), cluster_distance=1, core_neighbours=5) self.one_cluster_graph = DenGraphIO(base_graph=DistanceGraph( nodes=[(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6)], distance=ListDistance(), symmetric=True), cluster_distance=.1, core_neighbours=5)
def test_simple(self): io_graph = DenGraphVIO( base_graph=DistanceGraph(nodes=[1, 2, 3, 4, 5, 6], distance=DeltaDistance(), symmetric=True), cluster_distance=5, core_neighbours=5) cluster, distance = next(io_graph.probe(1)) self.assertEqual(2.5, distance) io_graph[7] = {} cluster, distance = next(io_graph.probe(1)) # expecting that algorithm uses cached mean self.assertEqual(2.5, distance)
def test_creation(self): io_graph = DenGraphVIO( base_graph=DistanceGraph(nodes=[1, 2, 3, 4, 5, 6], distance=DeltaDistance(), symmetric=True), cluster_distance=5, core_neighbours=5) self.assertIsNotNone(io_graph) literal = textwrap.dedent(""" 1,2,3,4,5,6 0,1,1,1,1,1 1,0,1,1,1,1 1,1,0,1,1,1 1,1,1,0,1,1 1,1,1,1,0,1 1,1,1,1,1,0 """.strip()) with self.assertRaises(dengraph.distance.NoDistanceSupport): io_graph = DenGraphVIO( base_graph=dengraph.graphs.graph_io.csv_graph_reader( literal.splitlines(), symmetric=True), cluster_distance=5, core_neighbours=5)
def test_mean_iterator(self): distance = DeltaDistance() self.assertEqual(4.5, distance.mean(range(10)))
def test_median_exception_with_default(self): distance = DeltaDistance() self.assertIsNone(distance.median(default=None))
def test_median_exception(self): distance = DeltaDistance() with self.assertRaises(ValueError): distance.median()
def test_median_args(self): distance = DeltaDistance() self.assertEqual(6, distance.median(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)) self.assertEqual(6, distance.median(10, 9, 8, 7, 6, 5, 4, 3, 2))
def test_median_iterator(self): distance = DeltaDistance() self.assertEqual(6, distance.median(range(10, 0, -1))) self.assertEqual(6, distance.median(range(10, 1, -1)))
def test_mean_args(self): distance = DeltaDistance() self.assertEqual(4.5, distance.mean(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))