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

fix process_init_approx #984

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/args.R
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,8 @@ process_init_approx <- function(init, num_procs, model_variables = NULL,
model_variables = list(parameters = colnames(draws_df)[3:(length(colnames(draws_df)) - 3)])
}
draws_df$lw = draws_df$lp__ - draws_df$lp_approx__
# Replace NaN and Inf with -Inf
draws_df$lw[!is.finite(draws_df$lw)] <- -Inf
andrjohns marked this conversation as resolved.
Show resolved Hide resolved
# Calculate unique draws based on 'lw' using base R functions
unique_draws = length(unique(draws_df$lw))
if (num_procs > unique_draws) {
Expand All @@ -1315,7 +1317,7 @@ process_init_approx <- function(init, num_procs, model_variables = NULL,
draws_df$weight = exp(draws_df$lw - max(draws_df$lw))
} else {
draws_df$weight = posterior::pareto_smooth(
exp(draws_df$lw - max(draws_df$lw)), tail = "right", return_k=FALSE)
exp(draws_df$lw - max(draws_df$lw)), tail = "right", r_eff=1, return_k=FALSE)
}
init_draws_df = posterior::resample_draws(draws_df, ndraws = num_procs,
weights = draws_df$weight, method = "simple_no_replace")
Expand Down
Loading