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

Function to cast InferenceData into tidy_draws format #18

Open
damonbayer opened this issue Oct 11, 2024 · 1 comment · May be fixed by #36
Open

Function to cast InferenceData into tidy_draws format #18

damonbayer opened this issue Oct 11, 2024 · 1 comment · May be fixed by #36
Assignees
Labels
feature A new tool or utility being added the package or code-base. Medium Priority

Comments

@damonbayer
Copy link
Contributor

tidy_draws details.

You can approach this however you like, but I have previously done some relevant work:

I have written similar functionality in R, which expects as input the output of arviz.InferenceData.to_dataframe.
It splits the InferenceData into several tidy_draws formatted tables, one for each group.

arviz_split <- function(x) {
x %>%
    select(-distribution) %>%
    split(f = as.factor(x$distribution))
}

pyrenew_samples <-
read_csv(inference_data_path) %>%
rename_with(\(varname) str_remove_all(varname, "\\(|\\)|\\'|(, \\d+)")) |>
rename(
    .chain = chain,
    .iteration = draw
) |>
mutate(across(c(.chain, .iteration), \(x) as.integer(x + 1))) |>
mutate(
    .draw = tidybayes:::draw_from_chain_and_iteration_(.chain, .iteration),
    .after = .iteration
) |>
pivot_longer(-starts_with("."),
    names_sep = ", ",
    names_to = c("distribution", "name")
) |>
arviz_split() |>
map(\(x) pivot_wider(x, names_from = name) |> tidy_draws())
@AFg6K7h4fhy2
Copy link
Collaborator

AFg6K7h4fhy2 commented Nov 4, 2024

A comment is due on why this issue was modified from High Priority to Medium Priority during the week of [Oct. 28, Nov. 1]. Given DB's workflow (see partially here), which loads in R the contents of an az.InferenceData object, in pyrenew-hew (see here), careful treatment of time intervals in az.InferenceData was needed more (see here) by DB, who with the rest of STF represents the primary user of forecasttools-py, for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new tool or utility being added the package or code-base. Medium Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants