cdlib.ensemble.grid_search¶
- cdlib.ensemble.grid_search(graph: ~networkx.classes.graph.Graph, method: ~typing.Callable[[~networkx.classes.graph.Graph, dict], object], parameters: list, quality_score: ~typing.Callable[[~networkx.classes.graph.Graph, object], object], aggregate: ~typing.Callable[[list], object] = <built-in function max>) tuple ¶
Returns the optimal partition of the specified graph w.r.t. the selected algorithm and quality score.
- Parameters:
method – community discovery method (from nclib.community)
graph – networkx/igraph object
parameters – list 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 optimal configuration for the given algorithm, input paramters and fitness function; the obtained communities; the fitness score
- Example:
>>> import networkx as nx >>> from cdlib import algorithms, ensemble >>> g = nx.karate_club_graph() >>> resolution = ensemble.Parameter(name="resolution", start=0.1, end=1, step=0.1) >>> randomize = ensemble.BoolParameter(name="randomize") >>> communities, scoring = ensemble.grid_search(graph=g, method=algorithms.louvain, >>> parameters=[resolution, randomize], >>> quality_score=evaluation.erdos_renyi_modularity, >>> aggregate=max) >>> print(communities, scoring)