pool_grid_filter(graph, methods, configurations, quality_score, aggregate=<built-in function max>)¶
Execute a pool of community discovery internal on the input graph. Returns the optimal partition for each algorithm given the specified quality function.
- methods – list community discovery methods (from nclib.community)
- graph – networkx/igraph object
- configurations – list of lists (one for each method) of Parameter and BoolParameter objects
- quality_score – a fitness function to evaluate the obtained partition (from nclib.evaluation)
- aggregate – function to select the best fitness value. Possible values: min/max
at each call the generator yields a tuple composed by: the actual method, its optimal configuration; the obtained communities; the fitness score.
ValueError – if the number of methods is different from the number of configurations specified
>>> import networkx as nx >>> from cdlib import algorithms, ensemble >>> g = nx.karate_club_graph() >>> # Louvain >>> resolution = ensemble.Parameter(name="resolution", start=0.1, end=1, step=0.1) >>> randomize = ensemble.BoolParameter(name="randomize") >>> louvain_conf = [resolution, randomize] >>> >>> # Angel >>> threshold = ensemble.Parameter(name="threshold", start=0.1, end=1, step=0.1) >>> angel_conf = [threshold] >>> >>> methods = [algorithms.louvain, algorithms.angel] >>> >>> for communities, scoring in ensemble.pool_grid_filter(g, methods, [louvain_conf, angel_conf], quality_score=evaluation.erdos_renyi_modularity, aggregate=max): >>> print(communities, scoring)