MCPcopy Create free account
hub / github.com/ChartGalaxy/ChartGalaxy / pair_leafs

Function pair_leafs

code_generation_benchmark/utils/utils_eval.py:212–231  ·  view source on GitHub ↗
(gt_leafs, pr_leafs, gt_matched_prs, pr_matched_gts, gt_match_costs, gt_match_sims)

Source from the content-addressed store, hash-verified

210
211
212def pair_leafs(gt_leafs, pr_leafs, gt_matched_prs, pr_matched_gts, gt_match_costs, gt_match_sims):
213 m = len(gt_leafs)
214 n = len(pr_leafs)
215 cost_matrix = np.zeros((m, n))
216 sims_record = [[[] for _ in range(n)] for _ in range(m)]
217 for i, gleaf in enumerate(gt_leafs):
218 for j, pleaf in enumerate(pr_leafs):
219 cost_matrix[i, j], sims_record[i][j] = leaf_cost(gleaf, pleaf)
220
221 # hungarian algorithm
222 row_ind, col_ind = linear_sum_assignment(cost_matrix)
223 for i, j in zip(row_ind, col_ind):
224 if cost_matrix[i, j] > 1:
225 continue
226 if gt_matched_prs[i] != -1 or pr_matched_gts[j] != -1:
227 continue
228 gt_matched_prs[i] = int(j)
229 pr_matched_gts[j] = int(i)
230 gt_match_costs[i] = cost_matrix[i, j]
231 gt_match_sims[i] = sims_record[i][j]
232
233def convert_tree_json(logger, tree_file, file_type):
234 assert file_type in ['gt', 'pr'], 'file_type should be gt or pr'

Callers 1

compute_element_pairsFunction · 0.85

Calls 1

leaf_costFunction · 0.85

Tested by

no test coverage detected