Skip to content

Commit

Permalink
Updated unit tests to use C++ version (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Jul 26, 2022
1 parent b3756b7 commit ef3ac41
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions tests/testthat/test-smc_updated_new_item_rank.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ smc_test_new_user_unif <- smc_mallows_new_users(
# run smc updated rankings with alpha unknown
Time2 <- dim(test_dataset)[3]
set.seed(994)
smc_test_updated_partial_unif1 <- smc_mallows_new_item_rank_updated_alpha_fixed(
smc_test_updated_partial_unif1 <- smc_mallows_new_item_rank_updated_cpp(
alpha = 2, n_items = n_items,
R_obs = test_dataset, metric = metric, leap_size = leap_size,
N = N, Time = Time2, logz_estimate = logz_estimate,
mcmc_kernel_app = mcmc_kernel_app, aug_method = "random",
rho_samples_init = smc_test_new_user_unif$rho_samples[, , Time + 1],
aug_rankings_init = smc_test_new_user_unif$augmented_rankings
aug_rankings_init = smc_test_new_user_unif$augmented_rankings,
alpha_fixed = TRUE
)
test_that("Updated item rank output is OK", {
expect_is(smc_test_updated_partial_unif1, "list")
Expand All @@ -106,22 +107,10 @@ test_that("Updated item rank output is OK", {
expect_equal(dim(smc_test_updated_partial_unif1$augmented_rankings), c(n_users, n_items, N))
})

# TODO: get the CPP version to work like the R version
smc_test_updated_partial_unif1_cpp <- smc_mallows_new_item_rank_updated_cpp(
alpha = 2, n_items = n_items,
R_obs = test_dataset, metric = metric, leap_size = leap_size,
N = N, Time = Time2, logz_estimate = logz_estimate,
mcmc_kernel_app = mcmc_kernel_app, aug_method = "random",
rho_samples_init = smc_test_new_user_unif$rho_samples[, , Time + 1],
aug_rankings_init = smc_test_new_user_unif$augmented_rankings,
alpha_fixed = TRUE
)
print(identical(smc_test_updated_partial_unif1_cpp, smc_test_updated_partial_unif1))

# run smc updated rankings with alpha unknown
Time2 <- dim(test_dataset)[3]
set.seed(994)
smc_test_updated_partial_unif2 <- smc_mallows_new_item_rank_updated(
smc_test_updated_partial_unif2 <- smc_mallows_new_item_rank_updated_cpp(
n_items = n_items,
R_obs = test_dataset, metric = metric, leap_size = leap_size,
N = N, Time = Time2, logz_estimate = logz_estimate,
Expand Down Expand Up @@ -159,13 +148,14 @@ smc_test_new_user_pseudo <- smc_mallows_new_users(
)

set.seed(994)
smc_test_updated_partial_pseudo1 <- smc_mallows_new_item_rank_updated_alpha_fixed(
smc_test_updated_partial_pseudo1 <- smc_mallows_new_item_rank_updated_cpp(
alpha = 2, n_items = n_items,
R_obs = test_dataset, metric = metric, leap_size = leap_size,
N = N, Time = Time2, logz_estimate = logz_estimate,
mcmc_kernel_app = mcmc_kernel_app, aug_method = "pseudolikelihood",
rho_samples_init = smc_test_new_user_pseudo$rho_samples[, , Time + 1],
aug_rankings_init = smc_test_new_user_pseudo$augmented_rankings
aug_rankings_init = smc_test_new_user_pseudo$augmented_rankings,
alpha_fixed = TRUE
)
test_that("Updated item rank output is OK", {
expect_is(smc_test_updated_partial_pseudo1, "list")
Expand All @@ -176,7 +166,7 @@ test_that("Updated item rank output is OK", {
})

set.seed(994)
smc_test_updated_partial_pseudo2 <- smc_mallows_new_item_rank_updated(
smc_test_updated_partial_pseudo2 <- smc_mallows_new_item_rank_updated_cpp(
n_items = n_items,
R_obs = test_dataset, metric = metric, leap_size = leap_size,
N = N, Time = Time2, logz_estimate = logz_estimate,
Expand All @@ -186,7 +176,6 @@ smc_test_updated_partial_pseudo2 <- smc_mallows_new_item_rank_updated(
rho_samples_init = smc_test_new_user_unif$rho_samples[, , Time + 1],
aug_rankings_init = smc_test_new_user_unif$augmented_rankings
)

test_that("Updated item rank output (variable alpha) is OK", {
expect_is(smc_test_updated_partial_pseudo2, "list")
expect_length(smc_test_updated_partial_pseudo2, 4)
Expand Down

0 comments on commit ef3ac41

Please sign in to comment.