Skip to content
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

How to calculate the mean of the specified chains and draws #2284

Open
LevCarlo opened this issue Oct 17, 2023 · 4 comments
Open

How to calculate the mean of the specified chains and draws #2284

LevCarlo opened this issue Oct 17, 2023 · 4 comments

Comments

@LevCarlo
Copy link

trace = az.from_netcdf(trace_filepath)
selected_posterior = trace.posterior.sel(chain=selected_chains, draw=selected_draws)
selected_posterior[list(trace.posterior.data_vars)[0]].mean(("chain", "draw"))
why does the code get stuck when applying mean method to selected_posterior?

@ahartikainen
Copy link
Contributor

What do you mean by stuck?

What do you get with .mean(["chain", "draw"])?

@LevCarlo
Copy link
Author

What do you mean by stuck?

What do you get with .mean(["chain", "draw"])?

No output after ~20 minutes running. trace.posterior.mean(("chain", "draw")) works well, but not for selected_posterior.

@ahartikainen
Copy link
Contributor

Before calling the mean make sure selected posterior looks the way you expect it to look.

Then take the first data_var and check again. Then call mean.

Also make sure you want to use .sel and not .isel.

Are you certain that selected draw and selected chain are good?

@ahartikainen
Copy link
Contributor

ahartikainen commented Nov 12, 2023

Can you run this example normally?

import arviz as az
data = az.load_arviz_data("centered_eight")
selected_posterior = data.posterior.sel(chain=[1,2], draw=list(range(422)))
print("selected_posterior:", selected_posterior[list(data.posterior.data_vars)[0]])
print("\nmean:", selected_posterior[list(data.posterior.data_vars)[0]].mean(("chain", "draw")))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants