Skip to content

Commit

Permalink
Replaced smc_mallows_new_item_rank() (#198)
Browse files Browse the repository at this point in the history
Subfunction  was also moved away from  _back_ into , since it's not being used anywhere else
  • Loading branch information
wleoncio committed Sep 5, 2022
1 parent 3c5f283 commit 0dd8b99
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 486 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export(rank_freq_distr)
export(sample_mallows)
export(smc_mallows_new_item_rank)
export(smc_mallows_new_item_rank_alpha_fixed)
export(smc_mallows_new_item_rank_updated)
export(smc_mallows_new_users)
export(smc_mallows_new_users_complete)
export(smc_mallows_new_users_partial)
Expand Down
34 changes: 3 additions & 31 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -386,39 +386,11 @@ leap_and_shift_probs <- function(rho, leap_size, n_items) {
#' @param verbose Logical specifying whether to print out the progress of the
#' SMC-Mallows algorithm. Defaults to \code{FALSE}.
#' @param alpha_fixed Logical indicating whether to sample \code{alpha} or not.
#' @return a set of particles each containing the values of rho and alpha and the effective sample size (ESS) at each iteration of the SMC
#' algorithm as well as the set of augmented rankings at the final iteration.
#' @export
smc_mallows_new_item_rank <- function(n_items, R_obs, metric, leap_size, N, Time, logz_estimate, mcmc_kernel_app, alpha = 0, alpha_prop_sd = 1, lambda = 1, alpha_max = 1, aug_method = "random", verbose = FALSE, alpha_fixed = FALSE) {
.Call(`_BayesMallows_smc_mallows_new_item_rank`, n_items, R_obs, metric, leap_size, N, Time, logz_estimate, mcmc_kernel_app, alpha, alpha_prop_sd, lambda, alpha_max, aug_method, verbose, alpha_fixed)
}

#' @title SMC-Mallows new item rank updated
#' @description Function to perform resample-move SMC algorithm where we receive a new item ranks from an existing user at each time step given an initial particle set obtained from MCMC or SMC. Each correction and augmentation is done by filling in the missing item ranks using pseudolikelihood augmentation.
#' @param n_items Integer is the number of items in a ranking.
#' @param R_obs 3D matrix of size n_assessors by n_items by Time containing a set of observed rankings of Time steps.
#' @param metric A character string specifying the distance metric to use in the Bayesian Mallows Model. Available options are \code{"footrule"},
#' \code{"spearman"}, \code{"cayley"}, \code{"hamming"}, \code{"kendall"}, and \code{"ulam"}.
#' @param leap_size leap_size Integer specifying the step size of the leap-and-shift proposal distribution.
#' @param N Integer specifying the number of particles.
#' @param Time Integer specifying the number of time steps in the SMC algorithm.
#' @param logz_estimate Estimate of the partition function, computed with \code{\link{estimate_partition_function}} in the BayesMallow R package {estimate_partition_function}.
#' @param mcmc_kernel_app Integer value for the number of applications we apply the MCMC move kernel.
#' @param alpha_prop_sd Numeric value of the standard deviation of the prior distribution for alpha.
#' @param lambda Strictly positive numeric value specifying the rate parameter of the truncated exponential prior distribution of alpha.
#' @param alpha_max Maximum value of alpha in the truncated exponential prior distribution.
#' @param aug_method A character string specifying the approach for filling in the missing data, options are "pseudolikelihood" or "random".
#' @param alpha_samples_init A vector of size N by containing the initial particle set values of alpha.
#' @param rho_samples_init 2D matrix of size N by n_items containing the initial particle set values of rho.
#' @param aug_rankings_init 3D matrix of size n_assessors by n_items by N containing the initial particle set values of augmented rankings for R_obs.
#' @return a 3d matrix containing: the samples of: rho, alpha and the augmented rankings, and the effective sample size at each iteration of the SMC algorithm.
#' @param verbose Logical specifying whether to print out the progress of the
#' SMC-Mallows algorithm. Defaults to \code{FALSE}.
#' @param alpha_fixed Logical indicating whether to sample \code{alpha} or not.
#' @param alpha numeric value of the scale parameter.
#' @return a 3d matrix containing: the samples of: rho, alpha and the augmented rankings, and the effective sample size at each iteration of the SMC algorithm.
#' @export
smc_mallows_new_item_rank_updated <- function(n_items, R_obs, metric, leap_size, N, Time, logz_estimate, mcmc_kernel_app, rho_samples_init, aug_rankings_init, alpha_samples_init = 0L, alpha = 0, alpha_prop_sd = 1, lambda = 1, alpha_max = 1, aug_method = "random", verbose = FALSE, alpha_fixed = FALSE) {
.Call(`_BayesMallows_smc_mallows_new_item_rank_updated`, n_items, R_obs, metric, leap_size, N, Time, logz_estimate, mcmc_kernel_app, rho_samples_init, aug_rankings_init, alpha_samples_init, alpha, alpha_prop_sd, lambda, alpha_max, aug_method, verbose, alpha_fixed)
smc_mallows_new_item_rank <- function(n_items, R_obs, metric, leap_size, N, Time, logz_estimate, mcmc_kernel_app, rho_samples_init, aug_rankings_init, alpha_samples_init = 0L, alpha = 0, alpha_prop_sd = 1, lambda = 1, alpha_max = 1, aug_method = "random", verbose = FALSE, alpha_fixed = FALSE) {
.Call(`_BayesMallows_smc_mallows_new_item_rank`, n_items, R_obs, metric, leap_size, N, Time, logz_estimate, mcmc_kernel_app, rho_samples_init, aug_rankings_init, alpha_samples_init, alpha, alpha_prop_sd, lambda, alpha_max, aug_method, verbose, alpha_fixed)
}

#' @title SMC-Mallows New Users
Expand Down
8 changes: 6 additions & 2 deletions man/smc_mallows_new_item_rank.Rd

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

72 changes: 0 additions & 72 deletions man/smc_mallows_new_item_rank_updated.Rd

This file was deleted.

34 changes: 4 additions & 30 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,33 +274,8 @@ BEGIN_RCPP
END_RCPP
}
// smc_mallows_new_item_rank
Rcpp::List smc_mallows_new_item_rank(const unsigned int& n_items, arma::cube& R_obs, const std::string& metric, const int& leap_size, const unsigned int& N, const unsigned int Time, const Rcpp::Nullable<arma::vec> logz_estimate, const int& mcmc_kernel_app, const double alpha, const double alpha_prop_sd, const double lambda, const double alpha_max, const std::string& aug_method, const bool verbose, const bool alpha_fixed);
RcppExport SEXP _BayesMallows_smc_mallows_new_item_rank(SEXP n_itemsSEXP, SEXP R_obsSEXP, SEXP metricSEXP, SEXP leap_sizeSEXP, SEXP NSEXP, SEXP TimeSEXP, SEXP logz_estimateSEXP, SEXP mcmc_kernel_appSEXP, SEXP alphaSEXP, SEXP alpha_prop_sdSEXP, SEXP lambdaSEXP, SEXP alpha_maxSEXP, SEXP aug_methodSEXP, SEXP verboseSEXP, SEXP alpha_fixedSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const unsigned int& >::type n_items(n_itemsSEXP);
Rcpp::traits::input_parameter< arma::cube& >::type R_obs(R_obsSEXP);
Rcpp::traits::input_parameter< const std::string& >::type metric(metricSEXP);
Rcpp::traits::input_parameter< const int& >::type leap_size(leap_sizeSEXP);
Rcpp::traits::input_parameter< const unsigned int& >::type N(NSEXP);
Rcpp::traits::input_parameter< const unsigned int >::type Time(TimeSEXP);
Rcpp::traits::input_parameter< const Rcpp::Nullable<arma::vec> >::type logz_estimate(logz_estimateSEXP);
Rcpp::traits::input_parameter< const int& >::type mcmc_kernel_app(mcmc_kernel_appSEXP);
Rcpp::traits::input_parameter< const double >::type alpha(alphaSEXP);
Rcpp::traits::input_parameter< const double >::type alpha_prop_sd(alpha_prop_sdSEXP);
Rcpp::traits::input_parameter< const double >::type lambda(lambdaSEXP);
Rcpp::traits::input_parameter< const double >::type alpha_max(alpha_maxSEXP);
Rcpp::traits::input_parameter< const std::string& >::type aug_method(aug_methodSEXP);
Rcpp::traits::input_parameter< const bool >::type verbose(verboseSEXP);
Rcpp::traits::input_parameter< const bool >::type alpha_fixed(alpha_fixedSEXP);
rcpp_result_gen = Rcpp::wrap(smc_mallows_new_item_rank(n_items, R_obs, metric, leap_size, N, Time, logz_estimate, mcmc_kernel_app, alpha, alpha_prop_sd, lambda, alpha_max, aug_method, verbose, alpha_fixed));
return rcpp_result_gen;
END_RCPP
}
// smc_mallows_new_item_rank_updated
Rcpp::List smc_mallows_new_item_rank_updated(const unsigned int& n_items, arma::cube& R_obs, const std::string& metric, const int& leap_size, const unsigned int& N, const unsigned int Time, const Rcpp::Nullable<arma::vec> logz_estimate, const int& mcmc_kernel_app, arma::mat rho_samples_init, arma::cube aug_rankings_init, arma::vec alpha_samples_init, const double alpha, const double alpha_prop_sd, const double lambda, const double alpha_max, const std::string& aug_method, const bool verbose, const bool alpha_fixed);
RcppExport SEXP _BayesMallows_smc_mallows_new_item_rank_updated(SEXP n_itemsSEXP, SEXP R_obsSEXP, SEXP metricSEXP, SEXP leap_sizeSEXP, SEXP NSEXP, SEXP TimeSEXP, SEXP logz_estimateSEXP, SEXP mcmc_kernel_appSEXP, SEXP rho_samples_initSEXP, SEXP aug_rankings_initSEXP, SEXP alpha_samples_initSEXP, SEXP alphaSEXP, SEXP alpha_prop_sdSEXP, SEXP lambdaSEXP, SEXP alpha_maxSEXP, SEXP aug_methodSEXP, SEXP verboseSEXP, SEXP alpha_fixedSEXP) {
Rcpp::List smc_mallows_new_item_rank(const unsigned int& n_items, arma::cube& R_obs, const std::string& metric, const int& leap_size, const unsigned int& N, const unsigned int Time, const Rcpp::Nullable<arma::vec> logz_estimate, const int& mcmc_kernel_app, arma::mat rho_samples_init, arma::cube aug_rankings_init, arma::vec alpha_samples_init, const double alpha, const double alpha_prop_sd, const double lambda, const double alpha_max, const std::string& aug_method, const bool verbose, const bool alpha_fixed);
RcppExport SEXP _BayesMallows_smc_mallows_new_item_rank(SEXP n_itemsSEXP, SEXP R_obsSEXP, SEXP metricSEXP, SEXP leap_sizeSEXP, SEXP NSEXP, SEXP TimeSEXP, SEXP logz_estimateSEXP, SEXP mcmc_kernel_appSEXP, SEXP rho_samples_initSEXP, SEXP aug_rankings_initSEXP, SEXP alpha_samples_initSEXP, SEXP alphaSEXP, SEXP alpha_prop_sdSEXP, SEXP lambdaSEXP, SEXP alpha_maxSEXP, SEXP aug_methodSEXP, SEXP verboseSEXP, SEXP alpha_fixedSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -322,7 +297,7 @@ BEGIN_RCPP
Rcpp::traits::input_parameter< const std::string& >::type aug_method(aug_methodSEXP);
Rcpp::traits::input_parameter< const bool >::type verbose(verboseSEXP);
Rcpp::traits::input_parameter< const bool >::type alpha_fixed(alpha_fixedSEXP);
rcpp_result_gen = Rcpp::wrap(smc_mallows_new_item_rank_updated(n_items, R_obs, metric, leap_size, N, Time, logz_estimate, mcmc_kernel_app, rho_samples_init, aug_rankings_init, alpha_samples_init, alpha, alpha_prop_sd, lambda, alpha_max, aug_method, verbose, alpha_fixed));
rcpp_result_gen = Rcpp::wrap(smc_mallows_new_item_rank(n_items, R_obs, metric, leap_size, N, Time, logz_estimate, mcmc_kernel_app, rho_samples_init, aug_rankings_init, alpha_samples_init, alpha, alpha_prop_sd, lambda, alpha_max, aug_method, verbose, alpha_fixed));
return rcpp_result_gen;
END_RCPP
}
Expand Down Expand Up @@ -424,8 +399,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_BayesMallows_get_exponent_sum", (DL_FUNC) &_BayesMallows_get_exponent_sum, 5},
{"_BayesMallows_get_sample_probabilities", (DL_FUNC) &_BayesMallows_get_sample_probabilities, 5},
{"_BayesMallows_leap_and_shift_probs", (DL_FUNC) &_BayesMallows_leap_and_shift_probs, 3},
{"_BayesMallows_smc_mallows_new_item_rank", (DL_FUNC) &_BayesMallows_smc_mallows_new_item_rank, 15},
{"_BayesMallows_smc_mallows_new_item_rank_updated", (DL_FUNC) &_BayesMallows_smc_mallows_new_item_rank_updated, 18},
{"_BayesMallows_smc_mallows_new_item_rank", (DL_FUNC) &_BayesMallows_smc_mallows_new_item_rank, 18},
{"_BayesMallows_smc_mallows_new_users", (DL_FUNC) &_BayesMallows_smc_mallows_new_users, 16},
{"_BayesMallows_metropolis_hastings_alpha", (DL_FUNC) &_BayesMallows_metropolis_hastings_alpha, 9},
{"_BayesMallows_metropolis_hastings_aug_ranking", (DL_FUNC) &_BayesMallows_metropolis_hastings_aug_ranking, 7},
Expand Down
1 change: 0 additions & 1 deletion src/smc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ double calculate_backward_probability(arma::uvec, arma::vec, arma::vec, arma::ve
Rcpp::List correction_kernel(arma::vec, arma::vec, int);
Rcpp::List correction_kernel_pseudo(arma::vec, arma::vec, arma::vec, double, int, std::string);
arma::vec metropolis_hastings_aug_ranking(const double&, const arma::vec&, const int&, const arma::vec&, const arma::vec&, const std::string&, const bool&);
void new_items_move_step(arma::cube&, arma::mat&, arma::cube&, const arma::cube&, const std::string&, const std::string&, const Rcpp::Nullable<arma::vec>&, const double&, const double&, const double&, const double&, const arma::uword&, const int&, const bool&);
#endif
Loading

0 comments on commit 0dd8b99

Please sign in to comment.