Skip to content

Commit 71f9448

Browse files
authored
Merge pull request #35 from osorensen/prefs-issue-34
fixed bug in sampling of preferences
2 parents 3791cd0 + ab7bfe7 commit 71f9448

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/sample_latent_rankings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ LatentRankingProposal sample_latent_rankings(
129129

130130
for(auto ndit = new_data.begin(); ndit != new_data.end(); ++ndit) {
131131
umat sort_matrix = new_sort_matrices[ndit->first];
132-
int random_index = Rcpp::sample(sort_matrix.n_rows, 1, false)[0] - 1;
132+
int random_index = Rcpp::sample(sort_matrix.n_cols, 1, false)[0] - 1;
133133

134134
proposal.proposal.col(proposal_index++) = sort_matrix.col(random_index);
135135
proposal.log_probability = join_vert(

tests/testthat/test-compute_sequentially_preferences.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test_that("compute_sequentially works with preference data", {
2-
dat <- subset(pairwise_preferences, user <= 20)
2+
dat <- subset(pairwise_preferences, user <= 24)
33
topological_sorts <- split(dat, f =~ timepoint) |>
44
lapply(split, f =~ user) |>
55
lapply(function(x) {
@@ -23,8 +23,8 @@ test_that("compute_sequentially works with preference data", {
2323
topological_sorts = topological_sorts
2424
)
2525

26-
expect_gt(mean(mod$alpha), 1.03)
27-
expect_lt(mean(mod$alpha), 1.06)
26+
expect_gt(mean(mod$alpha), 1)
27+
expect_lt(mean(mod$alpha), 1.02)
2828
})
2929

3030
test_that("compute_sequentially works with preference data and tracing", {
@@ -55,8 +55,8 @@ test_that("compute_sequentially works with preference data and tracing", {
5555

5656
expect_equal(length(mod$alpha_traces), 3)
5757
expect_equal(length(mod$alpha_traces[[2]]), 100)
58-
expect_gt(mod$alpha_traces[[2]][[3]], .7)
59-
expect_lt(mod$alpha_traces[[2]][[3]], .8)
58+
expect_gt(mod$alpha_traces[[2]][[3]], .24)
59+
expect_lt(mod$alpha_traces[[2]][[3]], .25)
6060

6161
set.seed(3)
6262
mod <- compute_sequentially(
@@ -72,13 +72,13 @@ test_that("compute_sequentially works with preference data and tracing", {
7272

7373
expect_equal(length(mod$alpha_traces), 3)
7474
expect_equal(length(mod$alpha_traces[[2]]), 100)
75-
expect_gt(mod$alpha_traces[[2]][[3]], .7)
76-
expect_lt(mod$alpha_traces[[2]][[3]], .8)
75+
expect_gt(mod$alpha_traces[[2]][[3]], .04)
76+
expect_lt(mod$alpha_traces[[2]][[3]], .05)
7777

7878
expect_equal(length(mod$latent_rankings_traces), 3)
7979
expect_equal(length(mod$latent_rankings_traces[[2]]), 100)
8080
expect_equal(
8181
mod$latent_rankings_traces[[2]][[3]],
82-
c(1, 2, 5, 3, 4, 2, 1, 4, 5, 3)
82+
c(1, 3, 5, 4, 2, 2, 1, 4, 3, 5)
8383
)
8484
})

0 commit comments

Comments
 (0)