def partition_from_sample(sample_partition: BlockState, graph: Graph, mapping: Dict) -> BlockState: """Creates a BlockState for the full graph from sample results. Parameters ---------- sample_partition : BlockState the partitioning results on the sample subgraph graph : Graph the full graph mapping : Dict[int, int] the mapping of sample vertices to full graph vertices Returns ------- partition : BlockState the extended partition on the full graph """ assignment_property_map = graph.new_vertex_property("int", val=-1) assignment = assignment_property_map.get_array() sample_assignment = sample_partition.get_blocks().get_array() for key, value in mapping.items(): assignment[key] = sample_assignment[value] next_block = sample_partition.get_B() for i in range(graph.num_vertices()): if assignment[i] >= 0: continue assignment[i] = next_block next_block += 1 for i in range(graph.num_vertices()): if assignment[i] < sample_partition.get_B(): continue # TODO: make a helper function that finds the most connected block # TODO: make this an iterative process, so vertices with all neighbors unknown wait until at least one neighbor # is known block_counts = dict() # type: Dict[int, int] neighbors = graph.get_all_neighbors(i) for neighbor in neighbors: neighbor_block = assignment[neighbor] if neighbor_block < sample_partition.get_B(): if neighbor_block in block_counts: block_counts[neighbor_block] += 1 else: block_counts[neighbor_block] = 1 if len(block_counts) > 0: assignment[i] = max(block_counts) else: assignment[i] = np.random.randint(0, sample_partition.get_B()) assignment_property_map.a = assignment partition = BlockState(graph, assignment_property_map, sample_partition.get_B()) return partition
def simplicial_vertices(g: gt.Graph): ''' returns the (unweighted, undirected) simplicial vertices of g ''' simplicial_vertices = [] for v in g.vertices(): #try to find a clique around v #TODO: Replace with numpy style for x, y in itertools.combinations(g.get_all_neighbors(v), 2): if g.edge(x, y) is None: break else: simplicial_vertices.append(int(v)) #print(len(g.get_all_neighbors(v))) return simplicial_vertices