<commit_before>'''
Created on 12.07.2015

@author: <NAME>
'''

import numpy as np


class BaseTask(object):
    '''
    classdocs
    '''

    def __init__(self, X_lower, X_upper, opt=None, fopt=None, do_scaling=True):
        '''
        Constructor
        '''
        self.X_lower = X_lower
        self.X_upper = X_upper
        self.n_dims = self.X_lower.shape[0]
        assert self.n_dims == self.X_upper.shape[0]
        self.opt = opt
        self.fopt = fopt
        self.do_scaling = do_scaling

        if do_scaling:
            self.original_X_lower = self.X_lower
            self.original_X_upper = self.X_upper
            self.original_opt = opt
            self.original_fopt = fopt

            self.X_lower = np.zeros(self.original_X_lower.shape)
            self.X_upper = np.ones(self.original_X_upper.shape)
            if self.opt is not None:
                self.opt = np.true_divide(
                    (self.original_opt - self.original_X_lower),
                    (self.original_X_upper - self.original_X_lower))

    def objective_function(self, x):
        pass

    def objective_function_test(self, x):
        pass

    def evaluate(self, x):
        assert len(x.shape) == 2
        assert x.shape[1] == self.n_dims
        assert np.all(x >= self.X_lower)
        assert np.all(x <= self.X_upper)

        if self.do_scaling:
            x = self.original_X_lower + (self.original_X_upper - self.original_X_lower) * x
        return self.objective_function(x)

    def evaluate_test(self, x):
        assert len(x.shape) == 2
        assert x.shape[1] == self.n_dims<commit_msg>minor<commit_after>'''
Created on 12.07.2015

@author: <NAME>
'''

import numpy as np


class BaseTask(object):
    '''
    classdocs
    '''

    def __init__(self, X_lower, X_upper, opt=None, fopt=None, do_scaling=True):
        '''
        Constructor
        '''
        self.X_lower = X_lower
        self.X_upper = X_upper
        self.n_dims = self.X_lower.shape[0]
        assert self.n_dims == self.X_upper.shape[0]
        self.opt = opt
        self.fopt = fopt
        self.do_scaling = do_scaling

        if do_scaling:
            self.original_X_lower = self.X_lower
            self.original_X_upper = self.X_upper
            self.original_opt = opt
            self.original_fopt = fopt

            self.X_lower = np.zeros(self.original_X_lower.shape)
            self.X_upper = np.ones(self.original_X_upper.shape)
            if self.opt is not None:
                self.opt = self.transform(self.opt)

    def objective_function(self, x):
        pass

    def objective_function_test(self, x):
        pass

    def transform(self, x):
        """
        Transforms from  original space to the space [0, 1]
        Parameters
        ----------
        X: np.ndarray (1, D)
            Data point in original space

        Returns
        ----------
        np.ndarray (1, D)
            Input point in [0, 1] input space
        """
        return np.true_divide((x - self.original_X_lower),
                    (self.original_X_upper - self.original_X_lower))

    def retransform(self, x):
        """
        Scales from [0, 1] back to original space
        Parameters
        ----------
        X: np.ndarray (1, D)
            Data point in [0, 1] space

        Returns
        ----------
        np.ndarray (1, D)
            Input point in original input space
        """
        return self.original_X_lower + (self.original_X_upper -
                                        self.original_X_lower) * x

    def evaluate(self, x):
        assert len(x.shape) == 2
        assert x.shape[1] == self.n_dims
        assert np.all(x >= self.X_lower)
        assert np.all(x <= self.X_upper)

        if self.do_scaling:
            x = self.scaling(x)
        return self.objective_function(x)

    def evaluate_test(self, x):
        assert len(x.shape) == 2
        assert x.shape[1] == self.n_dims
{'fraction_non_alphanumeric': 0.11082995951417005, 'fraction_numerical': 0.010121457489878543, 'mean_word_length': 1.7075342465753425, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1965565', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1238, 'n_words': 271}