<commit_before>"""
This module contains a base class of optimizers.
This module purpose is to describe the API that optimizers
should follow.
"""
from .utils import check_types_coherence
from .utils import check_if_list_of_scalars

class Optimizer:
    """
    Optimizer base class
    """

    def update(self, x, y):
        """
        Update the surrogate used by the optimizer using a single evaluation.

        Parameters
        ----------
        x: dict, or list or scalar
        outputs: scalar
        """
        self.update_many([x], [y])

    def update_many(self, xlist, ylist):
        """
        Update the surrogate used by the optimizer using a list of evaluations.

        Parameters
        ----------
        xlist : list of dicts, or lists or scalars
        outputs: list of scalars
        """
        raise NotImplementedError()

    def suggest(self):
        """
        Use the surrogate to suggest a next input to evaluate

        Returns
        -------
        a dict, a list or a scalar
        """
        raise NotImplementedError()

class OptimizerWithHistory(Optimizer):

    def __init__(self):
        self.input_history_ = []
        self.output_history_ = []

    def update(self, x, y):
        self.update_many([x], [y])

    def update_many(self, xlist, ylist):
        assert len(xlist) == len(ylist), "xlist and ylist should have the same length"
        check_types_coherence(self.input_history_[-1:] + xlist)
        check_if_list_of_scalars(ylist)
        self.input_history_.extend(xlist)
        self.output_history_.extend(ylist)
<commit_msg>small change in a comment<commit_after>"""
This module contains a base class of optimizers.
This module purpose is to describe the API that optimizers
should follow.
"""
from .utils import check_types_coherence
from .utils import check_if_list_of_scalars

class Optimizer:
    """
    Optimizer base class
    """

    def update(self, x, y):
        """
        Update the surrogate used by the optimizer using a single evaluation.

        Parameters
        ----------
        x: dict, or list or scalar
        outputs: scalar
        """
        self.update_many([x], [y])

    def update_many(self, xlist, ylist):
        """
        Update the surrogate used by the optimizer using a list of evaluations.

        Parameters
        ----------
        xlist : list of dicts, or list of lists or list of scalars
        outputs: list of scalars
        """
        raise NotImplementedError()

    def suggest(self):
        """
        Use the surrogate to suggest a next input to evaluate

        Returns
        -------
        a dict, a list or a scalar
        """
        raise NotImplementedError()

class OptimizerWithHistory(Optimizer):

    def __init__(self):
        self.input_history_ = []
        self.output_history_ = []

    def update(self, x, y):
        self.update_many([x], [y])

    def update_many(self, xlist, ylist):
        assert len(xlist) == len(ylist), "xlist and ylist should have the same length"
        check_types_coherence(self.input_history_[-1:] + xlist)
        check_if_list_of_scalars(ylist)
        self.input_history_.extend(xlist)
        self.output_history_.extend(ylist)

{'fraction_non_alphanumeric': 0.09795412275263485, 'fraction_numerical': 0.0006199628022318661, 'mean_word_length': 2.1855873642645607, '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': '869753', 'n_tokens_mistral': 929, 'n_tokens_neox': 892, 'n_words': 298}