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¶
在输入图上执行社区发现内部池。 根据指定的质量函数,返回每个算法的最佳分区。
- Parameters:
methods – 列出社区发现方法(来自nclib.community)
graph – networkx/igraph 对象
配置 – 由Parameter和BoolParameter对象组成的列表的列表(每个方法一个)
quality_score – 用于评估所获得分区的适应度函数(来自 nclib.evaluation)
aggregate – 用于选择最佳适应值的函数。可能的值:min/max
- Returns:
每次调用时,生成器都会生成一个由以下内容组成的元组:实际方法、其最佳配置;获得的社区;适应度分数。
- Raises:
ValueError – 如果方法的数量与指定的配置数量不同
- 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)