Hello,
I have been trying to filter vertices iteratively but am seeing very strange behaviour. Summary of what my code is doing: I loop through groups of vertices. I set the vertex property map to False for all vertices. I then set it to True for all vertices in the current group. I then loop through all vertices in the graph setting the vertex property for the current vertex also to True, creating a graph_view object using that property map, resetting the value for that vertex to zero and then moving on to the next vertex repeating the procedure. For some reason the number of vertices in the resulting graph_view object bears no resemblance to the number of vertices in my current group. Can anybody help me with what is going on here? I am using '2.27dev (commit 31421e3c, Sun Jun 17 19:18:54 2018 +0200)'. If the code looks like it should work I can upload a copy of the state and network if that would be useful. Here is the code: g = gt.load_graph('graph_no_multi.gt') with open('state.pkl','rb') as state_pkl: state=pickle.load(state_pkl) groups = collections.defaultdict(list) l0 = state.levels[0] for v in g.vertices(): groups[l0.b[v]].append(int(v)) v_filter = g.new_vertex_property('bool') P_part = collections.defaultdict(int) for target_vertices in groups: target_vertices = groups[target_vertices] v_filter.set_value(False) for v_index in target_vertices: vertex = g.vertex(v_index) v_filter[vertex] = True for v in g.vertices(): v_filter[v] = True f_g = gt.GraphView(g,v_filter) if int(v) in target_vertices: if f_g.num_vertices() != len(target_vertices): print 'f_g.num_vertices()=', f_g.num_vertices(), 'expected: ', len(target_vertices) elif f_g.num_vertices() != len(target_vertices)+1: 'f_g.num_vertices()=', f_g.num_vertices(), 'expected: ', len(target_vertices)+1 v_filter[v] = False Best wishes, Philipp  Sent from: http://maindiscussionlistforthegraphtoolproject.982480.n3.nabble.com/ _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool 
Administrator

Am 10.07.2018 um 12:05 schrieb PM:
> Hello, > > I have been trying to filter vertices iteratively but am seeing very strange > behaviour. > > Summary of what my code is doing: > I loop through groups of vertices. I set the vertex property map to False > for all vertices. I then set it to True for all vertices in the current > group. I then loop through all vertices in the graph setting the vertex > property for the current vertex also to True, creating a graph_view object > using that property map, resetting the value for that vertex to zero and > then moving on to the next vertex repeating the procedure. For some reason > the number of vertices in the resulting graph_view object bears no > resemblance to the number of vertices in my current group. Can anybody help > me with what is going on here? > > I am using '2.27dev (commit 31421e3c, Sun Jun 17 19:18:54 2018 +0200)'. If > the code looks like it should work I can upload a copy of the state and > network if that would be useful. > > Here is the code: > > g = gt.load_graph('graph_no_multi.gt') > with open('state.pkl','rb') as state_pkl: > state=pickle.load(state_pkl) > > > groups = collections.defaultdict(list) > l0 = state.levels[0] > for v in g.vertices(): > groups[l0.b[v]].append(int(v)) > > v_filter = g.new_vertex_property('bool') > > P_part = collections.defaultdict(int) > for target_vertices in groups: > target_vertices = groups[target_vertices] > v_filter.set_value(False) > for v_index in target_vertices: > vertex = g.vertex(v_index) > v_filter[vertex] = True > for v in g.vertices(): > v_filter[v] = True > f_g = gt.GraphView(g,v_filter) > if int(v) in target_vertices: > if f_g.num_vertices() != len(target_vertices): > print 'f_g.num_vertices()=', f_g.num_vertices(), 'expected: > ', len(target_vertices) > elif f_g.num_vertices() != len(target_vertices)+1: > 'f_g.num_vertices()=', f_g.num_vertices(), 'expected: ', > len(target_vertices)+1 > v_filter[v] = False I couldn't run your code since it depends on some data you haven't provided  it is _always_ a bad idea to give code that can't be run. Please provide *selfcontained* examples. Otherwise we have to guess what the intended behavior is, instead of looking at it ourselves. But looking briefly, it seems you are resetting the filter even for vertices that do belong to the current group, thus destroying it. Best, Tiago  Tiago de Paula Peixoto <[hidden email]> _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool

Tiago de Paula Peixoto <tiago@skewed.de> 
You are perfectly right, I am indeed! I will rerun it and get back in touch
if the problem persists. Thank you for spotting this though! Best, Philipp  Sent from: http://maindiscussionlistforthegraphtoolproject.982480.n3.nabble.com/ _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool 
Free forum by Nabble  Edit this page 