<commit_before>"""
This module contains the RandomSearch class, which is class
that just samples randomly the next input to evaluate, without
using a surrogate.
"""
from .base import Optimizer
from .base import OptimizerWithHistory
from .utils import check_random_state
from .utils import check_sampler

__all__ = [
    "RandomSearch"
]

class RandomSearch(OptimizerWithHistory):
    """
    a random search optimizer.
    This optimizer is completely random, it does not use
    any surrogate model. It uses a `sampler`, which have to be
    a callable (e.g function) that takes a random state (integer)
    as input and returns a random sample. The `suggest` method
    just calls `sampler` each time.

    Parameters
    ----------
    sampler : callable
        a callable used to sample an input for further evaluation.
        it takes one argument, a random number generator following the API
        of numpy.random and returns a dict, a list or a scalar.
    random_state : int or None, optional
        controls the random seed used by `sampler`.

    Attributes
    ----------
        input_history_ : list of inputs evaluated
        output_history_: outputs corresponding to the evaluated inputs
    """

    def __init__(self, sampler, random_state=None):
        super().__init__()
        self.sampler = check_sampler(sampler)
        self.rng = check_random_state(random_state)

    def suggest(self):
        return self.sampler(self.rng)<commit_msg>make super compatible with py2<commit_after>"""
This module contains the RandomSearch class, which is class
that just samples randomly the next input to evaluate, without
using a surrogate.
"""
from .base import Optimizer
from .base import OptimizerWithHistory
from .utils import check_random_state
from .utils import check_sampler

__all__ = [
    "RandomSearch"
]

class RandomSearch(OptimizerWithHistory):
    """
    a random search optimizer.
    This optimizer is completely random, it does not use
    any surrogate model. It uses a `sampler`, which have to be
    a callable (e.g function) that takes a random state (integer)
    as input and returns a random sample. The `suggest` method
    just calls `sampler` each time.

    Parameters
    ----------
    sampler : callable
        a callable used to sample an input for further evaluation.
        it takes one argument, a random number generator following the API
        of numpy.random and returns a dict, a list or a scalar.
    random_state : int or None, optional
        controls the random seed used by `sampler`.

    Attributes
    ----------
        input_history_ : list of inputs evaluated
        output_history_: outputs corresponding to the evaluated inputs
    """

    def __init__(self, sampler, random_state=None):
        super(self, RandomSearch).__init__()
        self.sampler = check_sampler(sampler)
        self.rng = check_random_state(random_state)

    def suggest(self):
        return self.sampler(self.rng)
{'fraction_non_alphanumeric': 0.07169303264893975, 'fraction_numerical': 0.0003365870077415012, 'mean_word_length': 2.9839142091152815, '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': '1026635', 'n_tokens_mistral': 789, 'n_tokens_neox': 765, 'n_words': 334}