diff --git a/DESCRIPTION b/DESCRIPTION index eb0e53fc..b7294afc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: BayesMallows Type: Package Title: Bayesian Preference Learning with the Mallows Rank Model -Version: 2.2.2 +Version: 2.2.2.9000 Authors@R: c(person("Oystein", "Sorensen", email = "oystein.sorensen.1985@gmail.com", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 6731a2bb..6f473f61 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# BayesMallows (development versions) + +* A bug in the pseudolikelihood proposal for latent rankings has been corrected. + # BayesMallows 2.2.2 * An error in compute_mallows_loglik when the number of clusters is more than diff --git a/src/rank_proposal.cpp b/src/rank_proposal.cpp index 78906af8..7d80ded8 100644 --- a/src/rank_proposal.cpp +++ b/src/rank_proposal.cpp @@ -224,9 +224,11 @@ std::pair PartialPseudoProposal::propose_pseudo( vec sample_probs = normalise(exp(log_numerator), 1); if(forward) { - ivec ans(sample_probs.size()); - R::rmultinom(1, sample_probs.begin(), sample_probs.size(), ans.begin()); - proposal(span(item_to_rank)) = available_rankings(find(ans == 1)); + Rcpp::IntegerVector rank_index = Rcpp::sample( + sample_probs.size(), 1, true, + Rcpp::as(Rcpp::wrap(sample_probs)), + false); + proposal(span(item_to_rank)) = available_rankings(rank_index(0)); } int ranking_chosen = as_scalar(find(proposal(item_to_rank) == available_rankings)); diff --git a/tests/testthat/test-smc_update_correctness.R b/tests/testthat/test-smc_update_correctness.R index 68474958..ecf58829 100644 --- a/tests/testthat/test-smc_update_correctness.R +++ b/tests/testthat/test-smc_update_correctness.R @@ -137,7 +137,8 @@ test_that("update_mallows is correct for new partial rankings", { expect_equal( mean(mod_smc_next$alpha$value), - ifelse(aug == "uniform", 10.9348917143992, 10.9279783083453) + ifelse(aug == "uniform", 10.9348917143992, 10.910), + tolerance = .01 ) expect_equal(