Skip to content

Commit

Permalink
Merge pull request #76 from stan-dev/issue-75
Browse files Browse the repository at this point in the history
try to fix issue #75
  • Loading branch information
paul-buerkner authored Jun 11, 2020
2 parents 3af0890 + 8df28a4 commit d2eac48
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
2 changes: 1 addition & 1 deletion R/as_draws_array.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ draws_array <- function(..., .nchains = 1) {
variables <- names(out)
out <- unlist(out)
out <- array(out, dim = c(niterations, .nchains, length(variables)))
dimnames(out)[[3]] <- variables
dimnames(out) <- list(NULL, NULL, variables)
as_draws_array(out)
}

Expand Down
34 changes: 13 additions & 21 deletions R/weight_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@
#' x <- example_draws()
#'
#' # sample some random weights for illustration
#' weights <- rexp(ndraws(x))
#' wts <- rexp(ndraws(x))
#' head(wts)
#'
#' # add weights
#' x <- weight_draws(x, weights = weights)
#' x <- weight_draws(x, weights = wts)
#'
#' # extract weights
#' head(weights(x))
#' head(weights(x)) # defaults to normalized weights
#' head(weights(x, normalize=FALSE)) # recover original weights
#' head(weights(x, log=TRUE)) # get normalized log-weights
#'
#' # add weights which are already on the log scale
#' log_weights <- log(weights)
#' log_wts <- log(wts)
#' head(log_wts)
#'
#' x <- weight_draws(x, weights = log_wts, log = TRUE)
#' # extract weights
#' x <- weight_draws(x, weights = weights, log = TRUE)
#' head(weights(x))
#' head(weights(x, log=TRUE, normalize = FALSE)) # recover original log_wts
#'
#' @export
weight_draws <- function(x, weights, ...) {
Expand Down Expand Up @@ -112,22 +119,7 @@ weight_draws.draws_list <- function(x, weights, log = FALSE, ...) {
#'
#' @seealso [`weight_draws`], [`resample_draws`]
#'
#' @examples
#' x <- example_draws()
#'
#' # sample some random weights for illustration
#' weights <- rexp(ndraws(x))
#'
#' # add weights
#' x <- weight_draws(x, weights = weights)
#'
#' # return normalized weights
#' weights <- weights(x)
#' head(weights)
#'
#' # return normalized log weights
#' log_weights <- weights(x, log = TRUE)
#' head(log_weights)
#' @inherit weight_draws examples
#'
#' @export
weights.draws <- function(object, log = FALSE, normalize = TRUE, ...) {
Expand Down
17 changes: 12 additions & 5 deletions man/weight_draws.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions man/weights.draws.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d2eac48

Please sign in to comment.