def evaluate_partition(graph: Graph, true_b: np.ndarray, alg_partition: BlockState, evaluation: Evaluation): """Evaluate the output partition against the truth partition and report the correctness metrics. Compare the partitions using only the nodes that have known truth block assignment. Parameters ---------- graph : Graph the graph which was partitioned. true_b : ndarray (int) array of truth block assignment for each node. If the truth block is not known for a node, -1 is used to indicate unknown blocks. alg_partition : BlockState the partition result returned by stochastic block partitioning. evaluation : Evaluation stores evaluation results Returns ------ evaluation : Evaluation the evaluation results, filled in with goodness of partitioning measures """ alg_b = alg_partition.get_blocks().get_array() evaluation.full_graph_description_length = alg_partition.entropy() evaluation.max_full_graph_description_length = BlockState( graph, graph.new_vertex_property("int", np.arange(graph.num_vertices()))).entropy() evaluation.full_graph_modularity = modularity(graph, alg_partition.get_blocks()) if np.unique(true_b).size != 1: contingency_table, N = create_contingency_table( true_b, alg_b, evaluation) evaluation.contingency_table = contingency_table joint_prob = evaluate_accuracy(contingency_table, evaluation) evaluate_pairwise_metrics(contingency_table, N, evaluation) evaluate_entropy_metrics(joint_prob, evaluation) else: evaluation.num_blocks_algorithm = max(alg_b) + 1 evaluation.save()