arviz-devs / arviz

Exploratory analysis of Bayesian models with Python
https://python.arviz.org
Apache License 2.0
1.6k stars 398 forks source link

InferenceData from a numpy matrix #1270

Closed GWeindel closed 4 years ago

GWeindel commented 4 years ago

Hi all,

I have posterior traces that I would like to use with the arviz package, the back-end is pymc (1 I think) but generated from another package (HDDM, http://ski.clps.brown.edu/hddm_docs/index.html).

When I try the az.from_pymc3() module I get an error message AttributeError: 'DataFrame' object has no attribute '_straces' I am assuming either that the top level package did change the pymc structure too much to be converted by Arviz or that the pymc used is too old.

One useful feature for such case would probably be to create an InferenceData directly from the traces, is that technically possible ? As an example my traces are currently in a matrix iteration X parameter (chains are merged and burn-in already excluded).

OriolAbril commented 4 years ago

Hi,

I am not sure if HDDM uses pymc 2 or 3, it looks like it should be compatible with both. From the error message, it looks like the returned object is a DataFrame, not a pymc3.MultiTrace (not totally unexpected given the pymc2 compatibility). You should therefore not expect from_pymc3 to work as it only works with pymc3.MultiTrace objects.

I have never used the HDDM package and therefore don't know how is this dataframe structured nor how are sample stats or pointwise log likelihood handled. Thus, as a first approximation, I'd recommend converting the result dataframe to a dictionary and then use from_dict. Keep in mind that ArviZ has a convention for array shapes:

GWeindel commented 4 years ago

Hi thanks for your answer. From your response I see that there is already a solution so I will close the issue and I will try it with my data.