示例#1
0
    def _samplehyper(self, mean_ln_yminob_minus_eta, var_ln_yminob_minus_eta):

        Nsamples = self.burnin + self.mc_samples
        L_d = np.ones(self.X_dim)
        # define initial guess for hyperparameters
        init = np.hstack((np.log(0.3*L_d), np.log(10.0), np.log(1e-2), mean_ln_yminob_minus_eta))

        prior_mu = np.zeros(self.X_dim+3)
        prior_cov = np.diag(1.0 * np.ones(self.X_dim+3))
        prior_cov_chol = sp.linalg.cholesky(prior_cov, lower=True)

        params_array = init
        log_params = np.zeros((Nsamples, len(params_array)))
        sampler_options = {"cur_log_like": None, "angle_range": 0}
        extra_para = (mean_ln_yminob_minus_eta, var_ln_yminob_minus_eta)
        for i in range(Nsamples):
            params_array, current_ll = elliptical_slice(
                params_array,
                self._log_posterior,
                prior_cov_chol,
                prior_mu,
                * extra_para,
                **sampler_options)
            log_params[i,:] = params_array.ravel()
            current_ll = current_ll  # for diagnostics QUESTION: what is this for?
        self.params = np.exp(log_params[self.burnin:, :])
示例#2
0
    def _samplehyper(self, mean_ln_yminob_minus_eta, var_ln_yminob_minus_eta):
        # Takes any samples and finds maximum
        Nsamples = self.burnin + self.mc_samples + 200
        L_d = np.ones(self.X_dim)
        # define initial guess for hyperparameters
        init = np.hstack((np.log(0.3 * L_d), np.log(10.0), np.log(1e-2),
                          mean_ln_yminob_minus_eta))

        prior_mu = np.zeros(self.X_dim + 3)
        prior_cov = np.diag(1.0 * np.ones(self.X_dim + 3))
        prior_cov_chol = sp.linalg.cholesky(prior_cov, lower=True)

        params_array = init
        log_params = np.zeros((Nsamples, len(params_array)))
        ll_record = np.zeros((Nsamples, 1))
        sampler_options = {"cur_log_like": None, "angle_range": 0}
        extra_para = (mean_ln_yminob_minus_eta, var_ln_yminob_minus_eta)
        for i in range(Nsamples):
            params_array, current_ll = elliptical_slice(
                params_array, self._log_posterior, prior_cov_chol, prior_mu,
                *extra_para, **sampler_options)
            log_params[i, :] = params_array.ravel()
            ll_record[i] = current_ll

        self.params = np.exp(log_params[self.burnin:, :])

        max_ll_index = np.argmax(ll_record) - self.burnin
        self.params = np.atleast_2d(self.params[max_ll_index])