评估指标
评估指标模块。
提供影响力最大化算法的多种评估指标函数。
模块包含: - ranking_metrics: 排名稳定性评估指标 - influence_metrics: 影响力传播评估指标 - seed_quality_metrics: 种子节点质量评估指标 - network_metrics: 网络结构评估指标
- pynetim.evaluation.average_shortest_distance(graph, seeds, use_weight=False)[source]
计算种子节点之间的平均最短距离。
- Parameters:
- Returns:
平均最短距离。如果种子节点之间不可达,返回 -1。
- Return type:
Example
>>> from pynetim.evaluation import average_shortest_distance >>> # 基于跳数 >>> avg_dist = average_shortest_distance(graph, seeds) >>> # 基于权重 >>> avg_dist = average_shortest_distance(graph, seeds, use_weight=True)
- pynetim.evaluation.clustering_coefficient(graph, seeds)[source]
计算种子节点的平均聚类系数。
聚类系数衡量节点邻居之间的连接密度。
- Parameters:
- Returns:
平均聚类系数,范围 [0, 1]。
- Return type:
Example
>>> from pynetim.evaluation import clustering_coefficient >>> cc = clustering_coefficient(graph, seeds) >>> print(f"Clustering coefficient: {cc:.4f}")
- pynetim.evaluation.degree_distribution(graph, seeds)[source]
计算种子节点的度分布。
- Parameters:
- Returns:
度值到节点数量的映射。
- Return type:
Example
>>> from pynetim.evaluation import degree_distribution >>> dist = degree_distribution(graph, seeds) >>> print(f"Degree 5: {dist.get(5, 0)} nodes")
- pynetim.evaluation.degree_statistics(graph, seeds)[source]
计算种子节点的度统计信息。
- Parameters:
- Returns:
- 包含以下统计量:
mean_degree: 平均度
max_degree: 最大度
min_degree: 最小度
std_degree: 度标准差
- Return type:
Example
>>> from pynetim.evaluation import degree_statistics >>> stats = degree_statistics(graph, seeds) >>> print(f"Mean degree: {stats['mean_degree']:.2f}")
- pynetim.evaluation.distribution_entropy(graph, seeds)[source]
计算种子节点在度分布上的熵。
熵值越高表示种子节点分布越均匀。
- Parameters:
- Returns:
- 分布熵,范围 [0, 1]。
1.0 表示分布完全均匀
0.0 表示分布完全集中
- Return type:
Example
>>> from pynetim.evaluation import distribution_entropy >>> entropy = distribution_entropy(graph, seeds) >>> print(f"Distribution entropy: {entropy:.4f}")
- pynetim.evaluation.kendall_tau(ranking1, ranking2, variant='b')[source]
计算两个排名之间的肯德尔系数。
Kendall’s Tau 用于衡量两个排名序列的相关性, 适用于评估不同算法得到的种子节点排名的一致性。
- Parameters:
- Returns:
- (tau系数, p值)
tau系数范围 [-1, 1],1表示完全一致,-1表示完全相反
p值表示统计显著性
- Return type:
- Raises:
ImportError – 如果 scipy 未安装。
ValueError – 如果输入长度不一致。
References
Kendall, M. G. (1938). A new measure of rank correlation. Biometrika, 30(1/2), 81-93.
Example
>>> from pynetim.evaluation import kendall_tau >>> seeds_algo1 = [0, 1, 2, 3, 4] >>> seeds_algo2 = [0, 2, 1, 3, 4] >>> tau, p = kendall_tau(seeds_algo1, seeds_algo2) >>> print(f"Kendall's Tau: {tau:.4f}, p-value: {p:.4f}")
- pynetim.evaluation.local_clustering(graph, seeds)[source]
计算种子节点的局部聚类系数。
评估种子节点周围网络的紧密程度。
- Parameters:
- Returns:
平均局部聚类系数,范围 [0, 1]。
- Return type:
Example
>>> from pynetim.evaluation import local_clustering >>> clustering = local_clustering(graph, seeds) >>> print(f"Local clustering: {clustering:.4f}")
- pynetim.evaluation.mean_centrality(graph, seeds, centrality_type='degree')[source]
计算种子节点的平均中心性。
- Parameters:
- Returns:
平均中心性值。
- Return type:
Example
>>> from pynetim.evaluation import mean_centrality >>> centrality = mean_centrality(graph, seeds, centrality_type='degree')
- pynetim.evaluation.monotonicity_score(values)[source]
计算节点重要性排序的单调性得分。
单调性指标衡量排序算法能否有效区分不同节点的重要性。 如果算法能给每个节点赋予唯一的重要性值,单调性接近1; 如果很多节点有相同的重要性值,单调性会降低。
- 计算公式:
M = (N_unique - 1) / (N_total - 1)
- 其中:
N_unique: 不同重要性值的数量
N_total: 总节点数
M 的取值范围为 [0, 1]
M → 1 表示排序算法具有良好的区分度
M → 0 表示所有节点的重要性值都相同
- Parameters:
- Returns:
- 单调性得分,范围 [0, 1]。
1.0 表示所有节点的重要性值都唯一(完美区分)
0.0 表示所有节点的重要性值都相同(无区分度)
- Return type:
References
A novel voting measure for identifying influential nodes in complex networks based on local structure. Scientific Reports, 2025.
复杂网络节点重要性排序算法的单调性评估。
Example
>>> from pynetim.evaluation import monotonicity_score >>> # 所有值都不同,单调性高 >>> values1 = [1.0, 2.0, 3.0, 4.0, 5.0] >>> score1 = monotonicity_score(values1) >>> print(f"Monotonicity: {score1:.4f}") # 1.0
>>> # 有重复值,单调性降低 >>> values2 = [1.0, 2.0, 2.0, 4.0, 5.0] >>> score2 = monotonicity_score(values2) >>> print(f"Monotonicity: {score2:.4f}") # 0.75
>>> # 所有值相同,单调性为0 >>> values3 = [3.0, 3.0, 3.0, 3.0, 3.0] >>> score3 = monotonicity_score(values3) >>> print(f"Monotonicity: {score3:.4f}") # 0.0
- pynetim.evaluation.neighbor_coverage(graph, seeds)[source]
计算种子节点的邻居覆盖率。
邻居覆盖率 = 种子节点的唯一邻居数 / 网络总节点数
- Parameters:
- Returns:
邻居覆盖率,范围 [0, 1]。
- Return type:
Example
>>> from pynetim.evaluation import neighbor_coverage >>> coverage = neighbor_coverage(graph, seeds) >>> print(f"Neighbor coverage: {coverage:.2%}")
- pynetim.evaluation.ranking_distance(ranking1, ranking2, metric='kendall')[source]
计算两个排名之间的距离。
- Parameters:
- Returns:
排名距离,越小表示排名越相似。
- Return type:
- Raises:
ValueError – 如果 metric 不支持。
Example
>>> from pynetim.evaluation import ranking_distance >>> ranking1 = [0, 1, 2, 3, 4] >>> ranking2 = [0, 2, 1, 3, 4] >>> distance = ranking_distance(ranking1, ranking2, metric='kendall')
- pynetim.evaluation.ranking_stability(rankings, method='kendall')[source]
计算多个排名之间的平均稳定性。
评估算法多次运行得到的排名的一致性。
- Parameters:
- Returns:
平均稳定性得分,范围 [0, 1]。
- Return type:
Example
>>> from pynetim.evaluation import ranking_stability >>> rankings = [ ... [0, 1, 2, 3, 4], ... [0, 2, 1, 3, 4], ... [0, 1, 2, 4, 3] ... ] >>> stability = ranking_stability(rankings)
- pynetim.evaluation.reachability(graph, seeds)[source]
计算种子节点的可达性。
可达性 = 从种子节点可达的节点数 / 网络总节点数
- Parameters:
- Returns:
可达性,范围 [0, 1]。
- Return type:
Example
>>> from pynetim.evaluation import reachability >>> reach = reachability(graph, seeds) >>> print(f"Reachability: {reach:.2%}")
- pynetim.evaluation.seed_diversity(graph, seeds)[source]
计算种子节点的多样性。
基于种子节点之间的平均距离评估多样性。
- Parameters:
- Returns:
- 多样性得分,范围 [0, 1]。
1.0 表示种子节点分布非常分散
0.0 表示种子节点非常集中
- Return type:
Example
>>> from pynetim.evaluation import seed_diversity >>> diversity = seed_diversity(graph, seeds)
- pynetim.evaluation.seed_overlap(seeds1, seeds2)[source]
计算两组种子节点的重叠率。
Jaccard相似度 = |S1 ∩ S2| / |S1 ∪ S2|
- Parameters:
- Returns:
重叠率,范围 [0, 1]。
- Return type:
Example
>>> from pynetim.evaluation import seed_overlap >>> overlap = seed_overlap(seeds1, seeds2) >>> print(f"Overlap: {overlap:.2%}")
- pynetim.evaluation.spearman_correlation(ranking1, ranking2)[source]
计算两个排名之间的斯皮尔曼相关系数。
Spearman相关系数评估两个排名的单调关系, 适用于评估种子节点排名的相关性。
- Parameters:
- Returns:
- (相关系数, p值)
相关系数范围 [-1, 1]
p值表示统计显著性
- Return type:
- Raises:
ImportError – 如果 scipy 未安装。
ValueError – 如果输入长度不一致。
Example
>>> from pynetim.evaluation import spearman_correlation >>> ranking1 = [1, 2, 3, 4, 5] >>> ranking2 = [1, 3, 2, 4, 5] >>> rho, p = spearman_correlation(ranking1, ranking2)
- pynetim.evaluation.top_k_accuracy(predicted_seeds, ground_truth_seeds, k=None)[source]
计算 Top-K 准确率。
评估预测的种子节点与真实种子节点的重叠程度。
- Parameters:
- Returns:
- Top-K 准确率,范围 [0, 1]。
1.0 表示完全重叠
0.0 表示完全不重叠
- Return type:
Example
>>> from pynetim.evaluation import top_k_accuracy >>> predicted = [0, 1, 2, 3, 4] >>> ground_truth = [0, 2, 1, 5, 6] >>> acc = top_k_accuracy(predicted, ground_truth, k=3) >>> print(f"Top-3 accuracy: {acc:.2%}")
- pynetim.evaluation.top_k_overlap(ranking1, ranking2, k)[source]
计算两个排名在 Top-K 位置的重叠率。
评估不同算法选择的种子节点集合的重叠程度。
- Parameters:
- Returns:
- 重叠率,范围 [0, 1]。
1.0 表示完全重叠
0.0 表示完全不重叠
- Return type:
Example
>>> from pynetim.evaluation import top_k_overlap >>> ranking1 = [0, 1, 2, 3, 4, 5] >>> ranking2 = [0, 2, 1, 4, 3, 5] >>> overlap = top_k_overlap(ranking1, ranking2, k=3) >>> print(f"Top-3 overlap: {overlap:.4f}")
- pynetim.evaluation.weight_statistics(graph, seeds)[source]
计算种子节点相关边的权重统计信息。
- Parameters:
- Returns:
- 包含以下统计量:
mean_weight: 平均权重
max_weight: 最大权重
min_weight: 最小权重
total_weight: 总权重
- Return type:
Example
>>> from pynetim.evaluation import weight_statistics >>> stats = weight_statistics(graph, seeds) >>> print(f"Mean weight: {stats['mean_weight']:.4f}")