<commit_before>"""Functions for calculating errors by combining different datasets."""

import math

def combine(files, rivet_path, error_calc):
    """Combine files[1]/rivet_path, files[2]/rivet_path, ...
    using an error_calc function from the heppyplotlib.error_calc
    module and return a YODA data object.

    files[0] is supposed to be the CV data set.
    """
    import yoda
    from . import yodaplot
    y_coord_list = []
    for file_name in files:
        data_object = yodaplot.resolve_data_object(file_name, rivet_path)
        y_coord_list.append(yodaplot.get_y_coords(data_object))
    errs = error_calc(y_coord_list)
    # make sure we are dealing with a scatter object to have the correct notion of errors
    scatter = yoda.mkScatter(yodaplot.resolve_data_object(files[0], rivet_path))
    for point, point_errs in zip(scatter.points, zip(*errs)):
        point.yErrs = point_errs
    return scatter

def asymmetric_hessian_error(value_lists):
    """Calculate the asymmetric hessian error from a list of datasets,
    where the first dataset stems from a PDF CV run."""
    negative_errs = []
    positive_errs = []
    transposed_value_lists = zip(*value_lists)
    for values in transposed_value_lists:
        central_value = values[0]
        evs = values[1:]
        error = [0.0, 0.0]
        for i in range(0, len(evs), 2):
            (ev_p, ev_m) = evs[i:i+2]
            error[0] += max(central_value - ev_p, central_value - ev_m, 0)**2
            error[1] += max(ev_p - central_value, ev_m - central_value, 0)**2
        negative_errs.append(math.sqrt(error[0]))
        positive_errs.append(math.sqrt(error[1]))
    return (negative_errs, positive_errs)<commit_msg>Add envelope as an error calc method<commit_after>"""Functions for calculating errors by combining different datasets."""

import math

def combine(files, rivet_path, error_calc):
    """Combine files[1]/rivet_path, files[2]/rivet_path, ...
    using an error_calc function from the heppyplotlib.error_calc
    module and return a YODA data object.

    files[0] is supposed to be the CV data set.
    """
    import yoda
    from . import yodaplot
    y_coord_list = []
    for file_name in files:
        data_object = yodaplot.resolve_data_object(file_name, rivet_path)
        y_coord_list.append(yodaplot.get_y_coords(data_object))
    errs = error_calc(y_coord_list)
    # make sure we are dealing with a scatter object to have the correct notion of errors
    scatter = yoda.mkScatter(yodaplot.resolve_data_object(files[0], rivet_path))
    for point, point_errs in zip(scatter.points, zip(*errs)):
        point.yErrs = point_errs
    return scatter

def asymmetric_hessian_error(value_lists):
    """Calculate the asymmetric hessian error from a list of datasets,
    where the first dataset stems from a PDF CV run."""
    negative_errs = []
    positive_errs = []
    transposed_value_lists = zip(*value_lists)
    for values in transposed_value_lists:
        central_value = values[0]
        evs = values[1:]
        error = [0.0, 0.0]
        for i in range(0, len(evs), 2):
            (ev_p, ev_m) = evs[i:i+2]
            error[0] += max(central_value - ev_p, central_value - ev_m, 0)**2
            error[1] += max(ev_p - central_value, ev_m - central_value, 0)**2
        negative_errs.append(math.sqrt(error[0]))
        positive_errs.append(math.sqrt(error[1]))
    return (negative_errs, positive_errs)

def envelope_error(value_lists):
    """Calculate the envelope of a list of datasets.
    The returned "errors" are relative to the first dataset."""
    negative_errs = []
    positive_errs = []
    transposed_value_lists = zip(*value_lists)
    for values in transposed_value_lists:
        negative_errs.append(values[0] - min(values))
        positive_errs.append(max(values) - values[0])
    return (negative_errs, positive_errs)
{'fraction_non_alphanumeric': 0.0996634739839503, 'fraction_numerical': 0.011390111312451462, 'mean_word_length': 3.3367003367003365, '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': '3679093', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1241, 'n_words': 335}