<commit_before>'''
Created on Jun 8, 2015

@author: <NAME>
'''

import emcee
import numpy as np

from robo.acquisition.LogEI import LogEI
from robo.acquisition.EntropyMC import EntropyMC

from scipy import stats


class EnvEntropySearch(EntropyMC):
    '''
    classdocs
    '''

    def __init__(self, model, cost_model, X_lower, X_upper, compute_incumbent, is_env_variable, n_representer=10, n_hals_vals=100, n_func_samples=100, **kwargs):

        self.cost_model = cost_model
        self.n_dims = X_lower.shape[0]

        self.is_env_variable = is_env_variable

        super(EnvEntropySearch, self).__init__(model, X_lower, X_upper, compute_incumbent, Nb=n_representer, Nf=n_func_samples, Np=n_hals_vals)

    def update(self, model, cost_model):
        self.cost_model = cost_model
        super(EnvEntropySearch, self).update(model)

    def compute(self, X, derivative=False):

        # Predict the costs for this configuration
        cost = self.cost_model.predict(X)

        # Compute fantasized pmin
        new_pmin = self.change_pmin_by_innovation(X, self.f)

        # Compute acquisition value
        H_old = np.sum(np.multiply(self.pmin, (self.logP + self.lmb)))
        H_new = np.sum(np.multiply(new_pmin, (np.log(new_pmin) + self.lmb)))

        loss = np.array([[-H_new + H_old]])
        acquisition_value = loss / cost

        return acquisition_value

    def update_representer_points(self):

        #TODO: We might want to start the sampling of the representer points from the incumbent here? Or maybe from a sobel grid?
        super(EnvEntropySearch, self).update_representer_points()

        # Project representer points to subspace
        self.zb[:, self.is_env_variable == 1] = self.X_upper[self.is_env_variable == 1]
<commit_msg>return only mean predictions for cost and omit variance<commit_after>'''
Created on Jun 8, 2015

@author: <NAME>
'''

import emcee
import numpy as np

from robo.acquisition.LogEI import LogEI
from robo.acquisition.EntropyMC import EntropyMC

from scipy import stats


class EnvEntropySearch(EntropyMC):
    '''
    classdocs
    '''

    def __init__(self, model, cost_model, X_lower, X_upper, compute_incumbent, is_env_variable, n_representer=10, n_hals_vals=100, n_func_samples=100, **kwargs):

        self.cost_model = cost_model
        self.n_dims = X_lower.shape[0]

        self.is_env_variable = is_env_variable

        super(EnvEntropySearch, self).__init__(model, X_lower, X_upper, compute_incumbent, Nb=n_representer, Nf=n_func_samples, Np=n_hals_vals)

    def update(self, model, cost_model):
        self.cost_model = cost_model
        super(EnvEntropySearch, self).update(model)

    def __call__(self, X, derivative=False):

        # Predict the costs for this configuration
        cost = self.cost_model.predict(X)[0]

        # Compute fantasized pmin
        new_pmin = self.change_pmin_by_innovation(X, self.f)

        # Compute acquisition value
        H_old = np.sum(np.multiply(self.pmin, (self.logP + self.lmb)))
        H_new = np.sum(np.multiply(new_pmin, (np.log(new_pmin) + self.lmb)))

        loss = np.array([[-H_new + H_old]])

        acquisition_value = loss / cost

        return acquisition_value

    def update_representer_points(self):

        #TODO: We might want to start the sampling of the representer points from the incumbent here? Or maybe from a sobel grid?
        super(EnvEntropySearch, self).update_representer_points()

        # Project representer points to subspace
        self.zb[:, self.is_env_variable == 1] = self.X_upper[self.is_env_variable == 1]
{'fraction_non_alphanumeric': 0.09643255295429208, 'fraction_numerical': 0.00919732441471572, 'mean_word_length': 3.4363411619283064, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7232057', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1164, 'n_words': 280}