cdlib.ensemble.pool_grid_filter¶
- cdlib.ensemble.pool_grid_filter(graph: ~networkx.classes.graph.Graph, methods: ~typing.Callable[[~networkx.classes.graph.Graph, dict], object], configurations: list, quality_score: ~typing.Callable[[~networkx.classes.graph.Graph, object], object], aggregate: ~typing.Callable[[list], object] = <built-in function max>) tuple ¶
Execute a pool of community discovery internal on the input graph. Returns the optimal partition for each algorithm given the specified quality function.
- Parameters:
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
- Returns:
at each call the generator yields a tuple composed by: the actual method, its optimal configuration; the obtained communities; the fitness score.
- Raises:
ValueError – if the number of methods is different from the number of configurations specified
- Example:
>>> 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)