-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
R: use rvars from posterior as output format (#9)
* R: use rvars from posterior as output format * Install posterior in CI
- Loading branch information
Showing
9 changed files
with
85 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
# copied from cmdstanr, definitely doesn't handle tuples, but then neither does | ||
# posterior | ||
repair_variable_names <- function(names) { | ||
names <- sub("\\.", "[", names) | ||
names <- gsub("\\.", ",", names) | ||
names[grep("\\[", names)] <- paste0(names[grep("\\[", names)], "]") | ||
names | ||
} | ||
|
||
|
||
output_as_rvars <- function(names, num_draws, num_chains, draws) { | ||
names <- repair_variable_names(names) | ||
num_params <- length(names) | ||
dims <- c(num_params, num_draws, num_chains) | ||
|
||
# all our outputs are row-major | ||
draws <- array(draws, dim = dims, dimnames = list(names, NULL, NULL)) | ||
# so we need to rearrange. posterior likes draws x chains x params | ||
draws <- aperm(draws, c(2, 3, 1)) | ||
|
||
posterior::as_draws_rvars(draws) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters