-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function for sequential learning (#391)
* incremented dev version * got rid of unused variable * turned new_data into a list * main part ready and passing tests * styling and fixing docs issue * Updating docs * small steps * adding user ids * added the consistency vector to the particles * updating examples * updating more * updating examples * passing rcmdchck * added deprecation notice for old burnin setting * skipping the deprecation notice * removed unnecessary brackets * updated particle handling * removed unused code * refactoring complete * ready for sequential updating * we have a loop * small fix * added learning examples * added test * added tests * styling and updating docs * updated expected test output * have to get rid of a test for now due to platform dependence
- Loading branch information
Showing
50 changed files
with
701 additions
and
299 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
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,71 @@ | ||
#' @title Estimate the Bayesian Mallows Model Sequentially | ||
#' | ||
#' @description Compute the posterior distributions of the parameters of the | ||
#' Bayesian Mallows model using sequential Monte Carlo. This is based on the | ||
#' algorithms developed in | ||
#' \insertCite{steinSequentialInferenceMallows2023;textual}{BayesMallows}. | ||
#' This function differs from [update_mallows()] in that it takes all the data | ||
#' at once, and uses SMC to fit the model step-by-step. Used in this way, SMC | ||
#' is an alternative to Metropolis-Hastings, which may work better in some | ||
#' settings. In addition, it allows visualization of the learning process. | ||
#' | ||
#' @param data A list of objects of class "BayesMallowsData" returned from | ||
#' [setup_rank_data()]. Each list element is interpreted as the data belonging | ||
#' to a given timepoint. | ||
#' @param initial_values An object of class "BayesMallowsPriorSamples" returned | ||
#' from [sample_prior()]. | ||
#' @param model_options An object of class "BayesMallowsModelOptions" returned | ||
#' from [set_model_options()]. | ||
#' @param smc_options An object of class "SMCOptions" returned from | ||
#' [set_smc_options()]. | ||
#' @param compute_options An object of class "BayesMallowsComputeOptions" | ||
#' returned from [set_compute_options()]. | ||
#' @param priors An object of class "BayesMallowsPriors" returned from | ||
#' [set_priors()]. | ||
#' | ||
#' @param pfun_estimate Object returned from [estimate_partition_function()]. | ||
#' Defaults to \code{NULL}, and will only be used for footrule, Spearman, or | ||
#' Ulam distances when the cardinalities are not available, cf. | ||
#' [get_cardinalities()]. | ||
#' | ||
#' @return An object of class BayesMallowsSequential. | ||
#' | ||
#' @details This function is very new, and plotting functions and other tools | ||
#' for visualizing the posterior distribution do not yet work. See the examples | ||
#' for some workarounds. | ||
#' | ||
#' | ||
#' @references \insertAllCited{} | ||
#' @export | ||
#' | ||
#' @family modeling | ||
#' | ||
#' @example /inst/examples/compute_mallows_sequentially_example.R | ||
#' | ||
compute_mallows_sequentially <- function( | ||
data, | ||
initial_values, | ||
model_options = set_model_options(), | ||
smc_options = set_smc_options(), | ||
compute_options = set_compute_options(), | ||
priors = set_priors(), | ||
pfun_estimate = NULL) { | ||
pfun_values <- extract_pfun_values(model_options$metric, data[[1]]$n_items, pfun_estimate) | ||
validate_class(initial_values, "BayesMallowsPriorSamples") | ||
alpha_init <- sample(initial_values$alpha, smc_options$n_particles, replace = TRUE) | ||
rho_init <- initial_values$rho[, sample(ncol(initial_values$rho), smc_options$n_particles, replace = TRUE)] | ||
|
||
ret <- run_smc( | ||
data = flush(data[[1]]), | ||
new_data = data, | ||
model_options = model_options, | ||
smc_options = smc_options, | ||
compute_options = compute_options, | ||
priors = priors, | ||
initial_values = list(alpha_init = alpha_init, rho_init = rho_init, aug_init = NULL), | ||
pfun_values = pfun_values, | ||
pfun_estimate = pfun_estimate | ||
) | ||
class(ret) <- "SMCMallows" | ||
ret | ||
} |
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
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
Oops, something went wrong.