Skip to content

Commit 634f73a

Browse files
authored
Merge pull request #42 from osorensen/aider-test
Aider test
2 parents 86dd95b + 962fdc6 commit 634f73a

File tree

10 files changed

+49
-8
lines changed

10 files changed

+49
-8
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
^data-raw$
55
^dev$
66
^\.github$
7+
^cran-comments\.md$

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
.Rhistory
33
.RData
44
.Ruserdata
5-
parameter_trace
5+
.aider*

DESCRIPTION

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ Authors@R: c(person("Oystein", "Sorensen",
77
role = c("aut", "cre"),
88
comment = c(ORCID = "0000-0003-0724-3542")))
99
Maintainer: Oystein Sorensen <oystein.sorensen.1985@gmail.com>
10-
Description: Nested sequential Monte Carlo algorithms for the Bayesian Mallows
11-
model.
10+
Description: Provides nested sequential Monte Carlo (SMC^2) algorithms for
11+
performing Bayesian inference in the Mallows model for ranking data.
12+
The package implements efficient algorithms for sequential learning
13+
with both complete and partial rankings, supporting multiple distance
14+
metrics including Kendall, Spearman, Cayley, Hamming, and footrule distances.
1215
License: GPL-3
1316
Encoding: UTF-8
1417
LazyData: true
1518
Roxygen: list(markdown = TRUE)
16-
RoxygenNote: 7.3.2
19+
RoxygenNote: 7.3.3
1720
LinkingTo:
1821
Rcpp,
1922
RcppArmadillo

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# BayesMallowsSMC2 0.1.1
2+
3+
* Initial CRAN submission
4+
* Implements nested sequential Monte Carlo (SMC^2) algorithms for Bayesian Mallows model
5+
* Supports multiple distance metrics: Kendall, Spearman, Cayley, Hamming, and footrule
6+
* Handles both complete and partial rankings
7+
* Includes functions for hyperparameter setting and SMC options configuration

R/RcppExports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' The function generates all possible topological sorts for the provided preference matrix
1818
#' and saves approximately `save_frac` of the sorts in a matrix which is returned.
1919
#'
20-
#' @return This function returns the number of topological sorts.
20+
#' @return A list containing the number of topological sorts and optionally a matrix of sorts.
2121
#'
2222
#' @export
2323
#' @examples

cran-comments.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Test environments
2+
* local R installation, R 4.3.2
3+
* ubuntu 20.04 (on GitHub Actions), R 4.1.0, 4.2.0, 4.3.0
4+
* win-builder (devel and release)
5+
* macOS (on GitHub Actions), R 4.3.0
6+
7+
## R CMD check results
8+
9+
0 errors | 0 warnings | 0 notes
10+
11+
## Downstream dependencies
12+
13+
There are currently no downstream dependencies for this package.
14+
15+
## Comments
16+
17+
This is a new submission of BayesMallowsSMC2, providing nested sequential Monte Carlo algorithms for the Bayesian Mallows model.

man/precompute_topological_sorts.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/all_topological_sorts.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <list>
88
#include <string>
99
#include <sstream>
10-
#include <filesystem>
10+
#include <R_ext/Utils.h>
1111
using namespace std;
1212

1313
class Graph {
@@ -37,6 +37,11 @@ void Graph::alltopologicalSortUtil(
3737
std::vector<arma::ivec>& sorts, double save_frac) {
3838
bool flag = false;
3939

40+
// Check for user interrupts in long-running recursive function
41+
if (sort_count % 1000 == 0) {
42+
R_CheckUserInterrupt();
43+
}
44+
4045
for (size_t i{}; i < n_items; i++) {
4146
if (indegree[i] == 0 && !visited[i]) {
4247
list<int>::iterator j;
@@ -102,7 +107,7 @@ arma::imat Graph::alltopologicalSort(long long int& sort_count, double save_frac
102107
//' The function generates all possible topological sorts for the provided preference matrix
103108
//' and saves approximately `save_frac` of the sorts in a matrix which is returned.
104109
//'
105-
//' @return This function returns the number of topological sorts.
110+
//' @return A list containing the number of topological sorts and optionally a matrix of sorts.
106111
//'
107112
//' @export
108113
//' @examples

src/distances.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ unsigned int CayleyDistance::d(const uvec& r1, const uvec& r2) {
3636
}
3737

3838
unsigned int FootruleDistance::d(const uvec& r1, const uvec& r2) {
39+
if(r1.size() != r2.size()) {
40+
Rcpp::stop("Rankings must have the same length");
41+
}
3942
unsigned int value{};
4043
for(size_t i{}; i < r1.size(); i++) {
4144
value += r1[i] > r2[i] ? r1[i] - r2[i] : r2[i] - r1[i];
@@ -61,6 +64,9 @@ unsigned int KendallDistance::d(const uvec& r1, const uvec& r2) {
6164
}
6265

6366
unsigned int SpearmanDistance::d(const uvec& r1, const uvec& r2) {
67+
if(r1.size() != r2.size()) {
68+
Rcpp::stop("Rankings must have the same length");
69+
}
6470
unsigned int value{};
6571
for(size_t i{}; i < r1.size(); i++) {
6672
value += r1[i] > r2[i] ? pow(r1[i] - r2[i], 2) : pow(r2[i] - r1[i], 2);

src/run_smc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// [[Rcpp::depends(RcppArmadillo)]]
22
#include <RcppArmadillo.h>
3+
#include <R_ext/Utils.h>
34
#include "prior.h"
45
#include "data.h"
56
#include "distances.h"
@@ -42,6 +43,7 @@ Rcpp::List run_smc(
4243
std::vector<double> iteration_times;
4344

4445
for(size_t t{}; t < T; t++) {
46+
R_CheckUserInterrupt();
4547
reporter.report_time(t);
4648

4749
for(auto& p : particle_vector) {

0 commit comments

Comments
 (0)