def get_posterior_samples()

in orbit/forecaster/forecaster.py [0:0]


    def get_posterior_samples(self, relabel: bool = False, permute: bool = True):
        """
        Parameters
        ----------
        relabel : bool
            whether returns posteriors after relabeling some parameters such as regressors etc.
        permute : bool
            default as true where chain information will be masked and the chain dimension will be collapsed; when
        it is set to false, additional chain dimension will be introduced at front before batch / sample dimension
        this is useful for arviz plotting. This argument is only effective for stan-mcmc estimator.

        Returns
        -------
        OrderedDict
            dictionary where each item represents the posterior samples of a specific parameter.
        """
        posterior_samples = deepcopy(self._posterior_samples)
        if relabel:
            regressors = self.get_regressors()
            if len(regressors) > 0:
                if len(regressors) == 1:
                    posterior_samples[regressors[0]] = posterior_samples["beta"]
                else:
                    for i, regressor in enumerate(regressors):
                        posterior_samples[regressor] = posterior_samples["beta"][:, i]
                del posterior_samples["beta"]

        if not permute:
            if self.estimator_type == StanEstimatorMCMC:
                for key, val in posterior_samples.items():
                    posterior_samples[key] = val.reshape(
                        (
                            self.estimator.chains,
                            self.estimator._num_sample_per_chain,
                            *val.shape[1:],
                        )
                    )
        return posterior_samples