Describe the bug
When using from_cmdstanpy(CmdStanMCMC, log_likelihood = {'output_name': 'log_lik_parameter_name'}), the log_likelihood group isn't returned in the az.InferenceData object.
However, if I use from_cmdstanpy(CmdStanMCMC, log_likelihood = ['log_lik_parameter_name']), the log_likelihood group is created correctly.
In both cases the log_likelihood is correctly filtered out from the posterior draws, per these lines. However, the log_likelihood_to_xarray method does not address the scenario where the user provides the log_likelihood as a dict (per these lines).
To Reproduce
I updated a gist here to create a CmdStan fit for the same eight_schools model in the documentation.
The gist creates az.InferenceData objects in two ways:
idata_from_cmdstanpy = az.from_cmdstanpy(fit_from_cmdstanpy, dims=dims, coords=coords, log_likelihood = ['log_lik'])
idata2_from_cmdstanpy = az.from_cmdstanpy(fit_from_cmdstanpy, dims=dims, coords=coords, log_likelihood = {'y': 'log_lik'})
Output:
In [2]: idata_from_cmdstanpy
Out[2]:
Inference data with groups:
> posterior
> log_likelihood
> sample_stats
In [3]: idata2_from_cmdstanpy
Out[3]:
Inference data with groups:
> posterior
> sample_stats
Expected behavior
Both methods of describing log_likelihood output should be supported
Additional context
In [4]: az.__version__
Out[4]: '0.10.0'
log_likelihood accepts str or a list of str. (See docstring)
What would be the purpose of that dict?
Ah, interesting. I was looking at this pystan schema example in the User Guide:
idata_stan = az.from_pystan(
posterior=posterior,
prior=prior,
posterior_predictive=["slack_comments_hat","github_commits_hat"],
prior_predictive=["slack_comments_hat","github_commits_hat"],
observed_data=["slack_comments","github_commits"],
constant_data=["time_since_joined"],
log_likelihood={
"slack_comments": "log_likelihood_slack_comments",
"github_commits": "log_likelihood_github_commits"
},
predictions=["slack_comments_pred", "github_commits_pred"],
predictions_constant_data=["time_since_joined_pred"],
coords={"developer": names, "candidate developer" : candidate_devs},
dims={
"slack_comments": ["developer"],
"github_commits" : ["developer"],
"slack_comments_hat": ["developer"],
"github_commits_hat": ["developer"],
"time_since_joined": ["developer"],
"slack_comments_pred" : ["candidate developer"],
"github_commits_pred" : ["candidate developer"],
"time_since_joined_pred" : ["candidate developer"],
}
)
Which includes a dict for the scenario where there are multiple observed values, each with a different log_likelihood.
Ok, yeah. There could an option to rename values.
Most helpful comment
Ok, yeah. There could an option to rename values.