graph_assortativity.cc 2.11 KB
Newer Older
Tiago Peixoto's avatar
Tiago Peixoto committed
1
2
// graph-tool -- a general graph modification and manipulation thingy
//
Tiago Peixoto's avatar
Tiago Peixoto committed
3
// Copyright (C) 2006-2015 Tiago de Paula Peixoto <tiago@skewed.de>
Tiago Peixoto's avatar
Tiago Peixoto committed
4
5
6
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
Tiago Peixoto's avatar
Tiago Peixoto committed
7
// as published by the Free Software Foundation; either version 3
Tiago Peixoto's avatar
Tiago Peixoto committed
8
9
10
11
12
13
14
15
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
16
17
// along with this program. If not, see <http://www.gnu.org/licenses/>.

Tiago Peixoto's avatar
Tiago Peixoto committed
18
19
20
#include "graph_filtering.hh"
#include "graph_selectors.hh"
#include "graph_properties.hh"
21
22
23
#include "graph.hh"

#include "graph_assortativity.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
24
25
26
27

using namespace std;
using namespace graph_tool;

28
pair<double,double>
29
assortativity_coefficient(GraphInterface& gi,
30
                          GraphInterface::deg_t deg)
Tiago Peixoto's avatar
Tiago Peixoto committed
31
{
32
    double a, a_err;
Tiago Peixoto's avatar
Tiago Peixoto committed
33
    run_action<>()(gi,std::bind(get_assortativity_coefficient(),
34
                                std::placeholders::_1, std::placeholders::_2,
Tiago Peixoto's avatar
Tiago Peixoto committed
35
36
                                std::ref(a), std::ref(a_err)),
                   scalar_selectors())
37
        (degree_selector(deg));
38
39
40
41
    return make_pair(a, a_err);
}

pair<double,double>
42
scalar_assortativity_coefficient(GraphInterface& gi,
43
                                 GraphInterface::deg_t deg)
44
45
{
    double a, a_err;
Tiago Peixoto's avatar
Tiago Peixoto committed
46
    run_action<>()(gi, std::bind(get_scalar_assortativity_coefficient(),
47
                                 std::placeholders::_1, std::placeholders::_2,
Tiago Peixoto's avatar
Tiago Peixoto committed
48
                                 std::ref(a), std::ref(a_err)),
49
                   scalar_selectors())
50
        (degree_selector(deg));
51
    return make_pair(a, a_err);
Tiago Peixoto's avatar
Tiago Peixoto committed
52
}
53
54
55
56
57
58
59
60
61
62

#include <boost/python.hpp>

using namespace boost::python;

void export_assortativity()
{
    def("assortativity_coefficient", &assortativity_coefficient);
    def("scalar_assortativity_coefficient", &scalar_assortativity_coefficient);
}