Пример #1
0
    def test_initialize_communities(self):
        pgn_file = []

        game_1 = {
            'black_id': '1',
            'black': 'player_one',
            'black_elo': '101',
            'black_title': 'GM',
            'white_id': '2',
            'white': 'player_two',
            'white_elo': '202',
            'white_title': 'GM'
        }
        game_2 = {
            'black_id': '3',
            'black': 'player_three',
            'black_elo': '303',
            'black_title': 'GM',
            'white_id': '4',
            'white': 'player_four',
            'white_elo': '404',
            'white_title': 'GM'
        }
        game_3 = {
            'black_id': '1',
            'black': 'player_one',
            'black_elo': '101',
            'black_title': 'GM',
            'white_id': '4',
            'white': 'player_four',
            'white_elo': '404',
            'white_title': 'GM'
        }
        pgn_file.extend([game_1, game_2, game_3])

        graph = ChessGraph(pgn_file)
        self.assertEqual(len(pgn_file), graph.number_of_edges)
        self.assertEqual(4, graph.number_of_nodes)

        self.assertEqual(0, graph.number_of_communities)

        community_labels = [1, 2, 2, 3]
        expected_number_of_communities = len(np.unique(community_labels))

        graph.communities = community_labels
        self.assertEqual(expected_number_of_communities,
                         graph.number_of_communities)
        self.assertEqual(community_labels, graph.communities)

        bad_community_labels = [1, 2, 2, 3, 4]
        with self.assertRaises(GraphError) as _:
            graph.communities = bad_community_labels

        bad_community_labels = [1, 2, 3]
        with self.assertRaises(GraphError) as _:
            graph.communities = bad_community_labels
Пример #2
0
    def test_initialize_communities(self):
        pgn_file = []

        game_1 = {'black_id': '1',
                  'black': 'player_one',
                  'black_elo': '101',
                  'black_title': 'GM',
                  'white_id': '2',
                  'white': 'player_two',
                  'white_elo': '202',
                  'white_title': 'GM'}
        game_2 = {'black_id': '3',
                  'black': 'player_three',
                  'black_elo': '303',
                  'black_title': 'GM',
                  'white_id': '4',
                  'white': 'player_four',
                  'white_elo': '404',
                  'white_title': 'GM'}
        game_3 = {'black_id': '1',
                  'black': 'player_one',
                  'black_elo': '101',
                  'black_title': 'GM',
                  'white_id': '4',
                  'white': 'player_four',
                  'white_elo': '404',
                  'white_title': 'GM'}
        pgn_file.extend([game_1, game_2, game_3])

        graph = ChessGraph(pgn_file)
        self.assertEqual(len(pgn_file), graph.number_of_edges)
        self.assertEqual(4, graph.number_of_nodes)

        self.assertEqual(0, graph.number_of_communities)

        community_labels = [1, 2, 2, 3]
        expected_number_of_communities = len(np.unique(community_labels))

        graph.communities = community_labels
        self.assertEqual(expected_number_of_communities, graph.number_of_communities)
        self.assertEqual(community_labels, graph.communities)

        bad_community_labels = [1, 2, 2, 3, 4]
        with self.assertRaises(GraphError) as _:
            graph.communities = bad_community_labels

        bad_community_labels = [1, 2, 3]
        with self.assertRaises(GraphError) as _:
            graph.communities = bad_community_labels
def main(data_file_name, iterations, output_dir, min_elo, p_in, p_out, burnin):

    with PgnFile(data_file_name) as pgnfile:
        graph = ChessGraph(pgnfile, min_elo=min_elo)

    detector = CommunityDetector(p_in=p_in, p_out=p_out)

    labels = detector.run(graph, iterations=iterations)

    assert len(labels) == iterations + 1

    chosen_index, communities = CommunityDetector.estimate_partitions(labels, burnin=burnin)
    graph.communities = communities
    graph.render_community_graph(show_single_nodes=False)

    return 0
def main(data_file_name, iterations, output_dir, min_elo, p_in, p_out, burnin):

    with PgnFile(data_file_name) as pgnfile:
        graph = ChessGraph(pgnfile, min_elo=min_elo)

    detector = CommunityDetector(p_in=p_in, p_out=p_out)

    labels = detector.run(graph, iterations=iterations)

    assert len(labels) == iterations + 1

    chosen_index, communities = CommunityDetector.estimate_partitions(
        labels, burnin=burnin)
    graph.communities = communities
    graph.render_community_graph(show_single_nodes=False)

    return 0