Example #1
0
    def _get_prior_parameters_observations(self):
        """
        Lotka-Volterra simulator is expensive, so load prior simulations from disk.
        :return: np.array, np.array
        """
        self._has_been_used = True

        file = (
            "prior-parameters.npy"
            if not self._gaussian_prior
            else "prior-parameters-gaussian.npy"
        )
        parameters = np.load(
            os.path.join(utils.get_data_root(), "lotka-volterra", file)
        )

        file = (
            "prior-observations.npy"
            if not self._gaussian_prior
            else "prior-observations-gaussian.npy"
        )
        observations = np.load(
            os.path.join(utils.get_data_root(), "lotka-volterra", file)
        )

        ix = np.random.permutation(range(parameters.shape[0]))

        return parameters[ix], observations[ix]
Example #2
0
    def get_ground_truth_posterior_samples(self, num_samples=None):
        """
        We have pre-generated posterior samples using MCMC on the product of the analytic
        likelihood and a uniform prior on [-3, 3]^5.
        Thus they are ground truth as long as MCMC has behaved well.
        We load these once if samples have not been loaded before, store them for future use,
        and return as many as are requested.

        :param num_samples: int
            Number of sample to return.
        :return: torch.Tensor [num_samples, parameter_dim]
            Batch of posterior samples.
        """
        if self._posterior_samples is None:
            self._posterior_samples = torch.Tensor(
                np.load(
                    os.path.join(
                        utils.get_data_root(),
                        "nonlinear-gaussian",
                        "true-posterior-samples.npy",
                    )))
        if num_samples is not None:
            return self._posterior_samples[:num_samples]
        else:
            return self._posterior_samples
Example #3
0
    def __init__(self):

        path = os.path.join(
            utils.get_data_root(), "lotka-volterra", "pilot_run_results.pkl"
        )
        with open(path, "rb") as file:
            self.means, self.stds = pickle.load(file, encoding="bytes")
Example #4
0
    def __init__(self):

        n_percentiles = 5
        self.perc = np.linspace(0.0, 100.0, n_percentiles)

        path = os.path.join(utils.get_data_root(), "mg1",
                            "pilot_run_results.pkl")
        with open(path, "rb") as file:
            self.whiten_params = pickle.load(file, encoding="bytes")
Example #5
0
 def get_ground_truth_observation(self):
     path = os.path.join(utils.get_data_root(), "mg1", "observed_data.pkl")
     with open(path, "rb") as file:
         _, true_observation = pickle.load(file, encoding="bytes")
     return torch.Tensor(true_observation)
Example #6
0
def get_ground_truth_observation():
    path = os.path.join(utils.get_data_root(), "lotka-volterra", "obs_stats.pkl")
    with open(path, "rb") as file:
        true_observation = pickle.load(file, encoding="bytes")
    return np.array(true_observation)