Changeset 0075ec


Ignore:
Timestamp:
07/02/07 20:33:37 (6 years ago)
Author:
Tiago de Paula Peixoto <tiago@…>
Branches:
master, python3
Children:
393242
Parents:
ba2aee
git-author:
Tiago de Paula Peixoto <tiago@…> (07/02/07 20:33:37)
git-committer:
Tiago de Paula Peixoto <tiago@…> (07/02/07 20:33:37)
Message:
* normalize betweenness centrality
* include central point dominance


git-svn-id: https://svn.forked.de/graph-tool/trunk@103 d4600afd-f417-0410-95de-beed9576f240
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/graph-tool

    rba2aee r0075ec  
    114114statistics.add_option("--minimum-spanning-tree", action="callback", callback=push_option, type="string", metavar="[WEIGHT|]PROPERTY", help="mark the minimum spanning tree edges in PROPERTY") 
    115115statistics.add_option("--line-graph", action="callback", callback=push_option, type="string", metavar="FILE[|FORMAT]", help="save the corresponding line graph to FILE") 
    116 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") 
     116statistics.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") 
     117statistics.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") 
     118 
    117119 
    118120correlations =  parser.add_option_group("Correlations") 
     
    125127 
    126128clustering =  parser.add_option_group("Clustering") 
    127 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") 
     129clustering.add_option("--local-clustering-coefficient", action="callback", callback=push_option, type="string", metavar="PROPERTY", help="set the local clustering coefficient to vertex property") 
    128130clustering.add_option("--global-clustering-coefficient", action="callback", callback=push_option, type="string", metavar="FILE", help="get the global clustering coefficient") 
    129 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") 
     131clustering.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") 
    130132 
    131133layout =  parser.add_option_group("Layout") 
     
    523525            weight = "" 
    524526        graph.GetBetweenness(weight, vertex_centrality, edge_centrality) 
     527    elif opt.name == "central-point-dominance": 
     528        values = parse_values(opt.value) 
     529        if len(values) != 2: 
     530            raise OptionError(opt.name, "invalid value '%s'" % opt.value) 
     531        if just_file: 
     532            return None 
     533        return (graph.GetCentralPointDominance(values[0]), values[1]) 
    525534    elif opt.name == "vertex-correlation-histogram": 
    526535        values = parse_values(opt.value) 
     
    601610        ret = "%f\t%f" % (avg, dev) 
    602611        return (ret, opt.value) 
    603     elif opt.name == "set-local-clustering-to-property": 
     612    elif opt.name == "local-clustering-coefficient": 
    604613        if just_file: 
    605614            return None 
    606615        graph.SetLocalClusteringToProperty(opt.value) 
    607     elif opt.name == "set-extended-clustering-to-property": 
     616    elif opt.name == "extended-clustering-coefficient": 
    608617        if just_file: 
    609618            return None 
  • src/graph/graph.hh

    rba2aee r0075ec  
    9999    void   GetLineGraph(std::string out_file, std::string format); 
    100100    void   GetBetweenness(std::string weight, std::string edge_betweenness, std::string vertex_betweenness); 
    101  
     101    double GetCentralPointDominance(std::string vertex_betweenness); 
     102     
    102103    // community structure 
    103104    enum comm_corr_t 
  • src/graph/graph_betweenness.cc

    rba2aee r0075ec  
    3636using namespace graph_tool; 
    3737 
     38template <class Graph, class VertexBetweenness, class EdgeBetweenness> 
     39void normalize_betweenness(const Graph& g, VertexBetweenness vertex_betweenness, EdgeBetweenness edge_betweenness) 
     40{ 
     41    size_t n = HardNumVertices()(g); 
     42    double factor = 2.0/(n*n - 3*n + 2); 
     43 
     44    typename graph_traits<Graph>::vertex_iterator v, v_end; 
     45    for (tie(v, v_end) = vertices(g); v != v_end; ++v)  
     46    { 
     47        put(vertex_betweenness, *v, factor * get(vertex_betweenness, *v)); 
     48    } 
     49 
     50    typename graph_traits<Graph>::edge_iterator e, e_end; 
     51    for (tie(e, e_end) = edges(g); e != e_end; ++e)  
     52    { 
     53        put(edge_betweenness, *e, factor * get(edge_betweenness, *e)); 
     54    } 
     55} 
     56 
    3857struct get_betweenness 
    3958{     
     
    4261    {         
    4362        brandes_betweenness_centrality(g, vertex_index_map(index_map).edge_centrality_map(edge_betweenness).centrality_map(vertex_betweenness)); 
     63        normalize_betweenness(g, vertex_betweenness, edge_betweenness); 
    4464    } 
    4565}; 
     
    6181            weight_map = get_static_property_map<weight_map_t>(find_property_map(_dp, _weight, typeid(graph_traits<typename GraphInterface::multigraph_t>::edge_descriptor))); 
    6282            brandes_betweenness_centrality(_g, vertex_index_map(_vertex_index).weight_map(weight_map).edge_centrality_map(_edge_betweenness).centrality_map(_vertex_betweenness)); 
     83            normalize_betweenness(_g, _vertex_betweenness, _edge_betweenness); 
    6384            _found = true; 
    6485        } 
     
    165186 
    166187} 
     188 
     189struct get_central_point_dominance 
     190{     
     191    template <class Graph, class VertexBetweenness> 
     192    void operator()(Graph& g, VertexBetweenness vertex_betweenness, double& c) const 
     193    {         
     194        c = central_point_dominance(g, vertex_betweenness); 
     195    } 
     196}; 
     197 
     198 
     199double GraphInterface::GetCentralPointDominance(string vertex_betweenness) 
     200{ 
     201    try 
     202    { 
     203        typedef DynamicPropertyMapWrap<double, graph_traits<multigraph_t>::vertex_descriptor> betweenness_map_t; 
     204        betweenness_map_t betweenness(find_property_map(_properties, vertex_betweenness, typeid(graph_traits<multigraph_t>::vertex_descriptor))); 
     205        double c = 0.0; 
     206         
     207        bool reversed = this->GetReversed(); 
     208        bool directed = this->GetDirected(); 
     209        check_filter(*this, bind<void>(get_central_point_dominance(), _1, var(betweenness), var(c)), never_reversed(), always_directed()); 
     210        this->SetReversed(reversed); 
     211        this->SetDirected(directed); 
     212        return c; 
     213    } 
     214    catch (property_not_found)  
     215    { 
     216        throw GraphException("vertex property " + vertex_betweenness + " not found"); 
     217    } 
     218} 
  • src/graph/graph_bind.cc

    rba2aee r0075ec  
    241241        .def("GetLineGraph", &GraphInterfaceWrap::GetLineGraph) 
    242242        .def("GetBetweenness", &GraphInterfaceWrap::GetBetweenness) 
     243        .def("GetCentralPointDominance", &GraphInterfaceWrap::GetCentralPointDominance) 
    243244        .def("GetCommunityStructure", &GraphInterfaceWrap::GetCommunityStructure) 
    244245        .def("GetCommunityNetwork", &GraphInterfaceWrap::GetCommunityNetwork) 
Note: See TracChangeset for help on using the changeset viewer.