@@ -0,0 +1,2117 @@
+'''%0ACreated on Jun 8, 2015%0A%0A@author: Aaron Klein%0A'''%0A%0Aimport emcee%0Aimport numpy as np%0A%0Afrom Entropy import Entropy%0A%0A%0Aclass EnvEntropySearch(Entropy):%0A    '''%0A    classdocs%0A    '''%0A%0A    def __init__(self, model, cost_model, n_representer, n_hals_vals, n_func_samples, **kwargs):%0A        '''%0A        Constructor%0A        '''%0A        self.model = model%0A        self.cost_model = cost_model%0A%0A        # Sample representer points%0A%0A        # Compute kl divergence between current pmin and the uniform distribution%0A%0A%0A    def update(self, model):%0A        %22%22%22%0A        %22%22%22%0A        self.model = model%0A%0A    def __call__(self, X, derivative=False):%0A        %22%22%22%0A        %22%22%22%0A        # Compute kl divergence between the updated pmin and the uniform distribution%0A%0A        # Predict the costs for this configuration%0A%0A        # Compute acquisition value%0A%0A        raise NotImplementedError()%0A%0A    def _sample_representers(self, proposal_measure, n_representers, n_dim, burnin_steps=100, mcmc_steps=100):%0A%0A        p0 = %5Bnp.random.rand(n_dim) for i in range(n_representers)%5D%0A%0A        sampler = emcee.EnsembleSampler(n_representers, n_dim, proposal_measure)%0A%0A        pos, prob, state = sampler.run_mcmc(p0, burnin_steps)%0A        sampler.reset()%0A        sampler.run_mcmc(pos, mcmc_steps)%0A        representers = sampler.chain%5B:, -1, :%5D%0A        return representers%0A%0A    def _compute_pmin(self, model, representers, num_func_samples=1000):%0A        K_star = model.kernel.K(representers)%0A        mean, _ = model.predict(representers, full_cov=False)%0A        func_samples = np.random.multivariate_normal(mean, K_star, num_func_samples)%0A        minimums = np.zeros(func_samples.shape)%0A        idx = np.argmin(func_samples, axis=1)%0A        minimums%5Bnp.arange(0, func_samples.shape%5B0%5D, 1), idx%5D = 1%0A        pmin = np.sum(minimums, axis=0) / float(representers.shape%5B0%5D)%0A%0A        return pmin%0A%0A    def _compute_kl_divergence(self, pmin, log_proposal_vals):%0A        entropy_pmin = -np.dot(pmin, np.log(pmin + 1e-50))%0A        log_proposal = np.dot(log_proposal_vals, pmin)%0A        kl_divergence = (entropy_pmin - log_proposal)%0A        return kl_divergence%0A

add env_entrop_search