47668

Counting how many vertices in a neighbourhood have a given attribute with edge weights in igraph for

This is related to this question. I have a very large graph, on the order of 100,000 vertices in igraph. Each vertex has an attribute att which is a logical value. Edges are weighted with positive integer weights. For each vertex v, I would like to sum the edge weights of edges that connect v to a vertex where att=T.

We can use the following as an example

set.seed(42) g <- erdos.renyi.game(169081, 178058, type="gnm") V(g)$att <- as.logical(rbinom(vcount(g), 1, 0.5))

Answer1:

Here's one way to get, for each vertex v, the sum of edge weights of neighboring vertices with att=T. Gabor might have a more elegant way that is much faster.

library(igraph) set.seed(42) g <- erdos.renyi.game(169081, 178058, type="gnm") V(g)$att <- as.logical(rbinom(vcount(g), 1, 0.5)) E(g)$weight <- sample(10, ecount(g), replace=TRUE) #integer weights sumEdgeWeightsOfEdgesFromVertexV<- function(v){ totwt <- 0 #get all neighbors of vertex v all_neighbors_of_v <- V(g)[nei(v)] #subset to those with att to be TRUE att_nei <- as.vector(all_neighbors_of_v[all_neighbors_of_v$att==TRUE]) #sum all the weights, edge by edge for( ver in att_nei) { totwt <- totwt + E(g, c(v,ver))$weight } totwt } # sapply(V(g), sumEdgeWeightsOfEdgesFromVertexV)

Recommend

  • COALESCE Extrage results on dates and strings
  • Replace multiple data codes in a dataframe with names
  • Choosing Entity framework as default implementation ORM against Nhibernate, cons and pros?
  • Different outcomes when using tf.Variable() and tf.get_variable()
  • Use WPF object to 'punch' hole in another?
  • How do you download a image/png data URI in Edge?
  • Controlling tab space in a using CSS?
  • All shortest paths for weighted graphs with networkx?
  • Remove border around the color in an input[type=color] in Firefox?
  • Overriding window.location on Webbrowser Control
  • Different builds of turn-based Game Center game can’t see each other’s matches
  • Thrust filter by key value
  • opengl window freezing during move/resize
  • SQL - Select lowest values with group by and order by?
  • Calculating ratio of reciprocated ties for each node in igraph
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • Dynamically switching connect in Modelica
  • Approximate Order-Preserving Huffman Code
  • calculate gradient output for Theta update rule
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • Redux Form - Not able to type anything in input
  • Z3: Convert between FP and BitVector?
  • Grails calculated field in SQL
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • Get history of file changes from TFS to implement custom “blame”-behaviour of exceptions
  • Counter field in MS Access, how to generate?
  • JavaScriptCore crash on iOS9
  • Is possible to count alias result on mysql
  • Convert array of 8 bytes to signed long in C++
  • Importing jscolor library in angular 2
  • QuartzCore.framework for Mono Develop
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Arrays break string types in Julia
  • How to format a variable of double type
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • retrieve vertices with no linked edge in arangodb
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Binding checkboxes to object values in AngularJs