Feature/crispino nontransitive - #83
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for a Bernoulli error model for pairwise-preference data (to handle non-transitive comparisons), introduces a Beta prior for the error probability epsilon, and returns/traces epsilon from the SMC run.
Changes:
- Add
error_modeloption ("none"/"bernoulli") and thread it through the C++ SMC pipeline. - Introduce
epsilonas a static parameter with Beta prior hyperparameterskappa_1/kappa_2, and surfaceepsilon+epsilon_tracesin the results. - Add a test for non-transitive pairwise preferences under the Bernoulli error model, plus NEWS/docs/version bumps.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/testthat/test-compute_sequentially_bernoulli.R | Adds a test for Bernoulli error model on non-transitive pairwise preferences. |
| src/sample_latent_rankings.h | Extends latent ranking proposal API with error_model. |
| src/sample_latent_rankings.cpp | Implements Bernoulli-path latent ranking proposals for pairwise data. |
| src/run_smc.cpp | Returns epsilon and epsilon_traces in the model output. |
| src/rejuvenate.cpp | Updates rejuvenation to carry epsilon and includes a Gibbs-style epsilon update. |
| src/prior.h | Adds kappa_1/kappa_2 to the prior struct. |
| src/prior.cpp | Reads kappa_1/kappa_2 from the R prior list. |
| src/particle.h | Adds epsilon to StaticParameters and updates constructors. |
| src/particle.cpp | Initializes epsilon, passes error_model to proposals, and adds Bernoulli likelihood contribution for pairwise data. |
| src/parameter_tracer.h | Adds epsilon_traces. |
| src/parameter_tracer.cpp | Records epsilon over time when tracing is enabled. |
| src/options.h | Adds error_model option field. |
| src/options.cpp | Reads error_model from R options list. |
| R/set_smc_options.R | Adds error_model argument and docs. |
| R/set_hyperparameters.R | Adds kappa_1/kappa_2 hyperparameters and docs. |
| NEWS.md | Documents the new Bernoulli error model and epsilon tracking. |
| man/set_smc_options.Rd | Updates Rd for new error_model option. |
| man/set_hyperparameters.Rd | Updates Rd for kappa_1/kappa_2. |
| DESCRIPTION | Bumps package version to development version 0.3.0.9000. |
| CRAN-SUBMISSION | Adds CRAN submission metadata file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| kappa_1 { input_prior["kappa_1"] }, | ||
| kappa_2 { input_prior["kappa_2"] } {} |
| epsilon = Rcpp::rbeta(1, prior.kappa_1, prior.kappa_2)[0]; | ||
| if (epsilon >= 0.5) { | ||
| epsilon = 0.4999; // Simple way to handle the truncation for the initial value | ||
| } |
| double epsilon_prime = 1.0; | ||
| while (epsilon_prime >= 0.5) { | ||
| epsilon_prime = Rcpp::rbeta(1, prior.kappa_1 + total_a, prior.kappa_2 + total_b)[0]; | ||
| } |
| pairwise_tp new_data = pp->timeseries[t]; | ||
| for (auto ndit = new_data.begin(); ndit != new_data.end(); ++ndit) { | ||
| total_p += ndit->second.size(); | ||
| for (auto pair : ndit->second) { |
| umat sort_matrix = new_sort_matrices[ndit->first]; | ||
| int random_index = Rcpp::sample(sort_matrix.n_cols, 1, false)[0] - 1; | ||
|
|
||
| proposal.proposal.col(proposal_index++) = sort_matrix.col(random_index); | ||
| proposal.log_probability = join_vert( | ||
| proposal.log_probability, vec{-log(new_sort_counts[ndit->first])} | ||
| ); | ||
| proposal.proposal.col(proposal_index++) = sort_matrix.col(random_index); | ||
| proposal.log_probability = join_vert( | ||
| proposal.log_probability, vec{-log(new_sort_counts[ndit->first])} | ||
| ); |
| # Run compute_sequentially | ||
| mod <- compute_sequentially( | ||
| df, | ||
| topological_sorts = top_sorts, | ||
| smc_options = set_smc_options( | ||
| n_particles = 100, | ||
| n_particle_filters = 5, | ||
| error_model = "bernoulli", | ||
| use_backward_simulation = TRUE | ||
| ), | ||
| hyperparameters = set_hyperparameters(n_items = 3) | ||
| ) | ||
|
|
||
| # Assertions | ||
| expect_true(!is.null(mod$epsilon)) | ||
| expect_true(mean(mod$epsilon) > 0) | ||
| expect_true(mean(mod$epsilon) < 0.5) |
| @@ -0,0 +1,3 @@ | |||
| Version: 0.3.0 | |||
…, fixed ranking conversion bug, and test fixes
|
@copilot can you tell me if the updated commit passes your review? |
2aa3074 addresses the specific review comments I raised earlier, but I wouldn’t mark it as fully passing yet because the current R-CMD-check run is failing on ubuntu-latest (release) and ubuntu-latest (oldrel-1). Both failures are in |
No description provided.