cdlib.ensemble.random_search¶
-
random_search
(graph: <Mock id='140410181329248'>, method: Callable[[<Mock id='140410181329440'>, dict], object], parameters: list, quality_score: Callable[[<Mock id='140410181329536'>, object], object], instances: int = 10, aggregate: 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 over a randomized sample of the input parameters.
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)
- instances – number of randomly selected parameters configurations
- 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.random_search(graph=g, method=algorithms.louvain, >>> parameters=[resolution, randomize], >>> quality_score=evaluation.erdos_renyi_modularity, >>> instances=5, aggregate=max) >>> print(communities, scoring)