def calc_entropy(p_marginal_truth: np.ndarray, p_marginal_alg: np.ndarray, idx_truth: np.ndarray, idx_alg: np.ndarray, evaluation: Evaluation, is_subgraph: bool = False) -> Evaluation: """Calculates the entropy of the truth and algorithm partitions. Parameters --------- p_marginal_truth : np.ndarray (float) the marginal probabilities of the truth partition p_marginal_alg : np.ndarray (float) the marginal probabilities of the algorithm partition idx_truth : np.ndarray (int) the indexes of the non-zero marginal probabilities of the truth partition idx_alg : np.ndarray (int) the indexes of the non-zero marginal probabilities of the algorithm partition is_subgraph : bool True if evaluation is for a subgraph. Default = False Returns ------ evaluation : Evaluation the evaluation object, updated with the entropy metrics """ # compute entropy of the non-partition2 and the partition2 version entropy_truth = -np.sum(p_marginal_truth[idx_truth] * np.log(p_marginal_truth[idx_truth])) print('Entropy of truth partition: {}'.format(abs(entropy_truth))) entropy_alg = -np.sum(p_marginal_alg[idx_alg] * np.log(p_marginal_alg[idx_alg])) print('Entropy of alg. partition: {}'.format(abs(entropy_alg))) if is_subgraph: evaluation.subgraph_entropy_truth = entropy_truth evaluation.subgraph_entropy_algorithm = entropy_alg else: evaluation.entropy_truth = entropy_truth evaluation.entropy_algorithm = entropy_alg return evaluation