<commit_before>import numpy as np
from scipy.interpolate import PchipInterpolator


class UcPoly(object):
    def __init__(self, coef):
        self.p = np.poly1d(coef)

    def machine_to_physics(self, machine_value):
        return self.p(machine_value)

    def physics_to_machine(self, physics_value):
        roots = (self.p - physics_value).roots
        positive_roots = [root for root in roots if root > 0]
        if len(positive_roots) > 0:
            return positive_roots[0]
        else:
            raise ValueError("No corresponding positive machine value:", roots)


class UcPchip(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.pp = PchipInterpolator(x, y)

    def machine_to_physics(self, machine_value):
        return self.pp(machine_value)

    def physics_to_machine(self, physics_value):
        y = [val - physics_value for val in self.y]
        new_pp = PchipInterpolator(self.x, y)
        return new_pp.roots()[0]<commit_msg>Raise error when creating PChip object with not monotonely increasing y list<commit_after>import numpy as np
from scipy.interpolate import PchipInterpolator


class UcPoly(object):
    def __init__(self, coef):
        self.p = np.poly1d(coef)

    def machine_to_physics(self, machine_value):
        return self.p(machine_value)

    def physics_to_machine(self, physics_value):
        roots = (self.p - physics_value).roots
        positive_roots = [root for root in roots if root > 0]
        if len(positive_roots) > 0:
            return positive_roots[0]
        else:
            raise ValueError("No corresponding positive machine value:", roots)


class UcPchip(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.pp = PchipInterpolator(x, y)

        diff = np.diff(y)
        if not (np.all(diff > 0)):
            raise ValueError('''Given coefficients must be
                                monotonely increasing.''')

    def machine_to_physics(self, machine_value):
        return self.pp(machine_value)

    def physics_to_machine(self, physics_value):
        y = [val - physics_value for val in self.y]
        new_pp = PchipInterpolator(self.x, y)
        return new_pp.roots()[0]
{'fraction_non_alphanumeric': 0.09208761734465802, 'fraction_numerical': 0.0049172999552972736, 'mean_word_length': 2.5808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '4064461', 'n_tokens_mistral': 717, 'n_tokens_neox': 684, 'n_words': 185}