def test_lanczos_optimal_cut_2(self): g = Graph(5, [ (0, 0, 0.), (1, 1, 0.), (2, 2, 0.), (3, 3, 0.), (4, 4, 0.), (1, 0, 15.1), (2, 0, 14,3), (3, 0, 21.3), (4, 0, 11.1), (2, 1, 17.), (3, 1, 10.2), (4, 1, 4.9), (3, 2, 19.99), (4, 2, 17.1), (4, 3, 11.1)]) real1, real2 = g.lanczos_optimal_cut() min_cut_real = g.calculate_normalized_cut(real1, real2) expected1, expected2 = set([0, 1, 3]), set([2, 4]) min_cut_expected = 1.151324986 #self.assertAlmostEqual(min_cut_expected, min_cut_real, places=3) all_real = set([str(real1), str(real2)]) all_expected = set([str(expected1), str(expected2)]) self.assertSetEqual(all_expected, all_real)
def test_lanczos_optimal_cut_3(self): g = Graph(7, [(0, 0, 0.), (1, 1, 0.), (2, 2, 0.), (3, 3, 0.), (4, 4, 0.), (5, 5, 0.), (6, 6, 0.), (3, 0, 10.), (4, 0, 7.), (4, 3, 6.), (2, 1, 5.), (5, 1, 8.), (6, 1, 6.), (5, 2, 6.7), (6, 2, 7.1), (6, 5, 9.), (1, 0, 1.2), (2, 0, 0.9), (5, 0, 1.1), (6, 0, 2.1), (3, 1, 1.3), (3, 2, 2.), (5, 3, 0.6), (6, 3, 1.2), (4, 1, 1.1), (4, 2, 2.), (5, 4, 1.1), (6, 4, 0.9)]) real1, real2 = g.lanczos_optimal_cut() min_cut_real = g.calculate_normalized_cut(real1, real2) expected1 = set([0, 4, 3]) expected2 = set([1, 2, 5, 6]) min_cut_expected = 0.408440189346 self.assertAlmostEqual(min_cut_expected, min_cut_real, places=3) all_real = set([str(real1), str(real2)]) all_expected = set([str(expected1), str(expected2)]) self.assertSetEqual(all_expected, all_real)
def test_lanczos_optimal_cut_1(self): g = Graph(4, [(0, 0, 0.), (1, 1, 0.), (2, 2, 0.), (3, 3, 0.), (1, 0, 0.6), (2, 0, 0.7), (3, 0, 0.55), (2, 1, 0.55), (3, 1, 0.6), (3, 2, 10.)]) real1, real2 = g.lanczos_optimal_cut() min_cut_real = g.calculate_normalized_cut(real1, real2) expected1 = set([0, 1]) expected2 = set([2, 3]) min_cut_expected = 0.77376042124387123 self.assertAlmostEqual(min_cut_expected, min_cut_real, places=3) all_real = set([str(real1), str(real2)]) all_expected = set([str(expected1), str(expected2)]) self.assertSetEqual(all_expected, all_real)