-
-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure dimension order can be anything #1693
Comments
+1. TFP mcmc currently output variables as |
There are two things to take into account for this to work, luckily with xarray the second is already taken care of. The first thing is conversion from ppl data to inferencedata. ppls use a given ordering but so far none uses named dimensions, so we need to know the ordering for things to work. Currently all converters end up calling I think it would also be great to allow something like
And have it work, which will need some work in the base converters but should be possible. Once this is done, we can also look into updating all the converters that currently use swapdims, as it may (or may not) be easier to handle things this way. The second thing is that once data is already as inferencedata, ArviZ needs to always used named dims, so it doesn't actually care about the order of the dimensions anymore, only about their names (like xarray does). I am 90% sure that all ArviZ code does that already but we need to check. Here are some examples showing how this already works: import arviz as az
idata = az.load_arviz_data("rugby")
ds = idata.posterior[["atts", "defs"]]
ds = ds.transpose("draw", "team", "chain")
az.summary(ds)
az.plot_forest(ds) |
Expanding on the first case, how about supporting an API like: az.from_dict(
{"a": np.random.normal(size=(100, 8, 4)),
"b": np.random.normal(size=(100, 4)),
},
draw_axis=0,
chain_axis=-1,
)
az.from_dict(
{"a": np.random.normal(size=(100, 4, 8)),
"b": np.random.normal(size=(100, 4)),
},
draw_axis=0,
chain_axis=1,
) which default being |
Oh it also makes supporting single chain and MAP easier: # Single chain
az.from_dict(
{"a": np.random.normal(size=(100, 8)),
"b": np.random.normal(size=(100)),
},
draw_axis=0,
chain_axis=None,
)
# MAP
az.from_dict(
{"a": np.random.normal(size=(8)),
"b": np.random.normal(size=()),
},
draw_axis=None,
chain_axis=None,
)
# multiple run of MAP (e.g., MAP sovled from different starting position)
az.from_dict(
{"a": np.random.normal(size=(4, 8)),
"b": np.random.normal(size=(4)),
},
draw_axis=None,
chain_axis=0,
) |
Currently all examples I have seen order the dimensions for samples as
(chain, draw, shape...)
, whereshape
is the shape of a single draw of the variable. This particular ordering shouldn't be necessary, and allowing alternative orderings might enable samples from PPLs to be used without copying. e.g. Turing stores variables as(draw, shape..., chain)
.This might already be supported. If so, it should be tested.
The text was updated successfully, but these errors were encountered: