Commit 0075ec76 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

* normalize betweenness centrality

* include central point dominance


git-svn-id: https://svn.forked.de/graph-tool/trunk@103 d4600afd-f417-0410-95de-beed9576f240
parent ba2aee8a
......@@ -113,7 +113,9 @@ statistics.add_option("--average-edge-property", action="callback", callback=pus
statistics.add_option("--reciprocity", action="callback", callback=push_option, type="string", metavar="FILE", help="get the edge reciprocity")
statistics.add_option("--minimum-spanning-tree", action="callback", callback=push_option, type="string", metavar="[WEIGHT|]PROPERTY", help="mark the minimum spanning tree edges in PROPERTY")
statistics.add_option("--line-graph", action="callback", callback=push_option, type="string", metavar="FILE[|FORMAT]", help="save the corresponding line graph to FILE")
statistics.add_option("--betweenness-centrality", action="callback", callback=push_option, type="string", metavar="VERTEX_BETWEENESS[EDGE_BETWEENESS]", help="calculate and store the vertex and/or edge betweenness centrality")
statistics.add_option("--betweenness-centrality", action="callback", callback=push_option, type="string", metavar="VERTEX_BETWEENESS[|EDGE_BETWEENESS[|WEIGHT]]", help="calculate and store the vertex and/or edge betweenness centrality")
statistics.add_option("--central-point-dominance", action="callback", callback=push_option, type="string", metavar="VERTEX_BETWEENESS|FILE", help="calculate central point dominance, given the VERTEX_BETWEENESS vertex property")
correlations = parser.add_option_group("Correlations")
correlations.add_option("--average-combined-vertex-correlation", action="callback", callback=push_option, type="string", metavar="DEGREE1|DEGREE2|FILE", help="get the average of DEGREE2 in function of DEGREE1. Scalar properties are also accepted as DEGREE1 or DEGREE2")
......@@ -124,9 +126,9 @@ correlations.add_option("--assortativity-coefficient", action="callback", callba
correlations.add_option("--scalar-assortativity-coefficient", action="callback", callback=push_option, type="string", metavar="DEGREE|FILE", help="get the scalar assortativity coefficient. Scalar properties are also accepted in place of DEGREE")
clustering = parser.add_option_group("Clustering")
clustering.add_option("--set-local-clustering-to-property", action="callback", callback=push_option, type="string", metavar="PROPERTY", help="set the local clustering coefficient to vertex property")
clustering.add_option("--local-clustering-coefficient", action="callback", callback=push_option, type="string", metavar="PROPERTY", help="set the local clustering coefficient to vertex property")
clustering.add_option("--global-clustering-coefficient", action="callback", callback=push_option, type="string", metavar="FILE", help="get the global clustering coefficient")
clustering.add_option("--set-extended-clustering-to-property", action="callback", callback=push_option, type="string", metavar="PREFIX|MAX", help="set the extended clustering coefficients c1 to cMAX to vertex properties PREFIX1 to PREFIXMAX")
clustering.add_option("--extended-clustering-coefficient", action="callback", callback=push_option, type="string", metavar="PREFIX|MAX", help="set the extended clustering coefficients c1 to cMAX to vertex properties PREFIX1 to PREFIXMAX")
layout = parser.add_option_group("Layout")
layout.add_option("--compute-spring-block-layout", action="callback", callback=push_option, type="string", metavar="ITERATIONS[|SEED]", help="compute the spring block layout")
......@@ -522,6 +524,13 @@ def parse_option(opt, just_file=False):
else:
weight = ""
graph.GetBetweenness(weight, vertex_centrality, edge_centrality)
elif opt.name == "central-point-dominance":
values = parse_values(opt.value)
if len(values) != 2:
raise OptionError(opt.name, "invalid value '%s'" % opt.value)
if just_file:
return None
return (graph.GetCentralPointDominance(values[0]), values[1])
elif opt.name == "vertex-correlation-histogram":
values = parse_values(opt.value)
if len(values) < 3 or len(values) > 4:
......@@ -600,11 +609,11 @@ def parse_option(opt, just_file=False):
(avg, dev) = graph.GetGlobalClustering()
ret = "%f\t%f" % (avg, dev)
return (ret, opt.value)
elif opt.name == "set-local-clustering-to-property":
elif opt.name == "local-clustering-coefficient":
if just_file:
return None
graph.SetLocalClusteringToProperty(opt.value)
elif opt.name == "set-extended-clustering-to-property":
elif opt.name == "extended-clustering-coefficient":
if just_file:
return None
values = parse_values(opt.value)
......
......@@ -98,7 +98,8 @@ public:
void GetMinimumSpanningTree(std::string weight, std::string property);
void GetLineGraph(std::string out_file, std::string format);
void GetBetweenness(std::string weight, std::string edge_betweenness, std::string vertex_betweenness);
double GetCentralPointDominance(std::string vertex_betweenness);
// community structure
enum comm_corr_t
{
......
......@@ -35,12 +35,32 @@ using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
template <class Graph, class VertexBetweenness, class EdgeBetweenness>
void normalize_betweenness(const Graph& g, VertexBetweenness vertex_betweenness, EdgeBetweenness edge_betweenness)
{
size_t n = HardNumVertices()(g);
double factor = 2.0/(n*n - 3*n + 2);
typename graph_traits<Graph>::vertex_iterator v, v_end;
for (tie(v, v_end) = vertices(g); v != v_end; ++v)
{
put(vertex_betweenness, *v, factor * get(vertex_betweenness, *v));
}
typename graph_traits<Graph>::edge_iterator e, e_end;
for (tie(e, e_end) = edges(g); e != e_end; ++e)
{
put(edge_betweenness, *e, factor * get(edge_betweenness, *e));
}
}
struct get_betweenness
{
template <class Graph, class VertexIndexMap, class EdgeBetweenness, class VertexBetweenness>
void operator()(Graph& g, VertexIndexMap index_map, EdgeBetweenness edge_betweenness, VertexBetweenness vertex_betweenness) const
{
brandes_betweenness_centrality(g, vertex_index_map(index_map).edge_centrality_map(edge_betweenness).centrality_map(vertex_betweenness));
normalize_betweenness(g, vertex_betweenness, edge_betweenness);
}
};
......@@ -60,6 +80,7 @@ struct get_weighted_betweenness
weight_map_t weight_map(_edge_index);
weight_map = get_static_property_map<weight_map_t>(find_property_map(_dp, _weight, typeid(graph_traits<typename GraphInterface::multigraph_t>::edge_descriptor)));
brandes_betweenness_centrality(_g, vertex_index_map(_vertex_index).weight_map(weight_map).edge_centrality_map(_edge_betweenness).centrality_map(_vertex_betweenness));
normalize_betweenness(_g, _vertex_betweenness, _edge_betweenness);
_found = true;
}
catch (property_not_found) {}
......@@ -164,3 +185,34 @@ void GraphInterface::GetBetweenness(string weight, string edge_betweenness, stri
}
}
struct get_central_point_dominance
{
template <class Graph, class VertexBetweenness>
void operator()(Graph& g, VertexBetweenness vertex_betweenness, double& c) const
{
c = central_point_dominance(g, vertex_betweenness);
}
};
double GraphInterface::GetCentralPointDominance(string vertex_betweenness)
{
try
{
typedef DynamicPropertyMapWrap<double, graph_traits<multigraph_t>::vertex_descriptor> betweenness_map_t;
betweenness_map_t betweenness(find_property_map(_properties, vertex_betweenness, typeid(graph_traits<multigraph_t>::vertex_descriptor)));
double c = 0.0;
bool reversed = this->GetReversed();
bool directed = this->GetDirected();
check_filter(*this, bind<void>(get_central_point_dominance(), _1, var(betweenness), var(c)), never_reversed(), always_directed());
this->SetReversed(reversed);
this->SetDirected(directed);
return c;
}
catch (property_not_found)
{
throw GraphException("vertex property " + vertex_betweenness + " not found");
}
}
......@@ -240,6 +240,7 @@ BOOST_PYTHON_MODULE(libgraph_tool)
.def("GetMinimumSpanningTree", &GraphInterfaceWrap::GetMinimumSpanningTree)
.def("GetLineGraph", &GraphInterfaceWrap::GetLineGraph)
.def("GetBetweenness", &GraphInterfaceWrap::GetBetweenness)
.def("GetCentralPointDominance", &GraphInterfaceWrap::GetCentralPointDominance)
.def("GetCommunityStructure", &GraphInterfaceWrap::GetCommunityStructure)
.def("GetCommunityNetwork", &GraphInterfaceWrap::GetCommunityNetwork)
.def("GetModularity", &GraphInterfaceWrap::GetModularity)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment