Beispiel #1
0
    def test_inference_data_attrs(self, posterior, prior, save_warmup, warmup_iterations: int):
        arviz_inference_data_from_pyjags_samples_dict = from_pyjags(
            posterior=posterior,
            prior=prior,
            log_likelihood={"y": "log_like"},
            save_warmup=save_warmup,
            warmup_iterations=warmup_iterations,
        )
        posterior_warmup_prefix = (
            "" if save_warmup and warmup_iterations > 0 and posterior is not None else "~"
        )
        prior_warmup_prefix = (
            "" if save_warmup and warmup_iterations > 0 and prior is not None else "~"
        )
        print(f'posterior_warmup_prefix="{posterior_warmup_prefix}"')
        test_dict = {
            f'{"~" if posterior is None else ""}posterior': ["b", "int"],
            f'{"~" if prior is None else ""}prior': ["b", "int"],
            f'{"~" if posterior is None else ""}log_likelihood': ["y"],
            f"{posterior_warmup_prefix}warmup_posterior": ["b", "int"],
            f"{prior_warmup_prefix}warmup_prior": ["b", "int"],
            f"{posterior_warmup_prefix}warmup_log_likelihood": ["y"],
        }

        fails = check_multiple_attrs(test_dict, arviz_inference_data_from_pyjags_samples_dict)
        assert not fails
Beispiel #2
0
    def test_roundtrip_from_pyjags_via_arviz_to_pyjags(self):
        arviz_inference_data_from_pyjags_samples_dict = from_pyjags(
            PYJAGS_POSTERIOR_DICT)
        arviz_dict_from_idata_from_pyjags_dict = _extract_arviz_dict_from_inference_data(
            arviz_inference_data_from_pyjags_samples_dict)

        pyjags_dict_from_arviz_idata = _convert_arviz_dict_to_pyjags_dict(
            arviz_dict_from_idata_from_pyjags_dict)

        assert verify_equality_of_numpy_values_dictionaries(
            PYJAGS_POSTERIOR_DICT, pyjags_dict_from_arviz_idata)
Beispiel #3
0
    def __call__(self, samples: tp.Dict[str, np.ndarray],
                 verbose: bool) -> bool:
        idata = az.from_pyjags(samples)
        ess = az.ess(idata, var_names=self.variable_names)

        minimum_ess = min(value['data']
                          for key, value in ess.to_dict()['data_vars'].items())

        if verbose:
            print(f'minimum ess = {minimum_ess}')

        return minimum_ess >= self.minimum_ess
Beispiel #4
0
    def __call__(self, samples: tp.Dict[str, np.ndarray],
                 verbose: bool) -> bool:
        idata = az.from_pyjags(samples)
        rhat = az.rhat(idata, var_names=self.variable_names)

        maximum_rhat_deviation = max(
            abs(value['data'] - 1.0)
            for key, value in rhat.to_dict()['data_vars'].items())

        if verbose:
            print(f'maximum rhat deviation = {maximum_rhat_deviation}')

        return maximum_rhat_deviation <= self.maximum_rhat_deviation
Beispiel #5
0
    def test_extract_samples_dictionary_from_arviz_inference_data(self):
        arviz_samples_dict_from_pyjags_samples_dict = _convert_pyjags_dict_to_arviz_dict(
            PYJAGS_POSTERIOR_DICT)

        arviz_inference_data_from_pyjags_samples_dict = from_pyjags(
            PYJAGS_POSTERIOR_DICT)
        arviz_dict_from_idata_from_pyjags_dict = _extract_arviz_dict_from_inference_data(
            arviz_inference_data_from_pyjags_samples_dict)

        assert verify_equality_of_numpy_values_dictionaries(
            arviz_samples_dict_from_pyjags_samples_dict,
            arviz_dict_from_idata_from_pyjags_dict,
        )