<commit_before>from numpy import bool, uint8


def pixel_wise_boundary_precision_recall(aseg, gt):
    gt = (1-gt.astype(bool)).astype(uint8)
    aseg = (1-aseg.astype(bool)).astype(uint8)
    tp = float((gt * aseg).sum())
    fp = (aseg * (1-gt)).sum()
    fn = (gt * (1-aseg)).sum()
    return tp/(tp+fp), tp/(tp+fn)

def body_rand(aseg, gt):<commit_msg>New edit distance measure. Requires original watershed map<commit_after>from numpy import bool, uint8


def pixel_wise_boundary_precision_recall(aseg, gt):
    gt = (1-gt.astype(bool)).astype(uint8)
    aseg = (1-aseg.astype(bool)).astype(uint8)
    tp = float((gt * aseg).sum())
    fp = (aseg * (1-gt)).sum()
    fn = (gt * (1-aseg)).sum()
    return tp/(tp+fp), tp/(tp+fn)

def edit_distance(aseg, gt, ws):
    return edit_distance_to_bps(aseg, agglo.best_possible_segmentation(ws, gt))

def edit_distance_to_bps(aseg, bps):
    r = agglo.Rug(aseg, bps)
    r.overlaps = r.overlaps.astype(bool)
    false_splits = (r.overlaps.sum(axis=0)-1).sum()
    false_merges = (r.overlaps.sum(axis=1)-1).sum()
    return (false_merges, false_splits)

def body_rand(aseg, gt):
{'fraction_non_alphanumeric': 0.1736420302760463, 'fraction_numerical': 0.016028495102404273, 'mean_word_length': 4.040358744394619, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4644086', 'n_tokens_mistral': 478, 'n_tokens_neox': 469, 'n_words': 83}