| Crates.io | asap-ranking |
| lib.rs | asap-ranking |
| version | 0.1.0 |
| created_at | 2025-05-27 00:03:11.414923+00 |
| updated_at | 2025-05-27 00:03:11.414923+00 |
| description | Active Sampling for Pairwise Comparisons (ASAP) algorithm implementation in Rust |
| homepage | |
| repository | https://github.com/sanity/asap/ |
| max_upload_size | |
| id | 1690442 |
| size | 96,236 |
A Rust implementation of the ASAP algorithm for active sampling in pairwise comparison preference aggregation. The algorithm offers high accuracy for inferring scores while minimizing the number of comparisons needed.
Based on the paper: "Active Sampling for Pairwise Comparisons via Approximate Message Passing and Information Gain Maximization" by A. Mikhailiuk, C. Wilmot, M. Perez-Ortiz, D. Yue and R. K. Mantiuk (2020).
use asap_ranking::{RankingModel, Comparison};
// Create a new model with items
let items = vec!["A".to_string(), "B".to_string(), "C".to_string()];
let mut model = RankingModel::<String>::new(&items);
// Add pairwise comparisons
model.add_comparison(Comparison::<String> {
winner: "A".to_string(),
loser: "B".to_string(),
}).unwrap();
model.add_comparison(Comparison::<String> {
winner: "B".to_string(),
loser: "C".to_string(),
}).unwrap();
// Get inferred scores
let scores = model.get_scores().unwrap();
println!("Scores: {:?}", scores);
// Get ordered ranking
let ranking = model.get_ordering().unwrap();
println!("Ranking: {:?}", ranking);
// Get suggestions for next comparisons
let suggestions = model.suggest_comparisons(3).unwrap();
println!("Suggested comparisons: {:?}", suggestions);
// Check if we have enough confidence in the ranking
let is_confident = model.is_sufficiently_confident(0.8).unwrap();
println!("Is ranking confident: {}", is_confident);
This implementation provides both the accurate and approximate versions of the ASAP algorithm:
The accurate version is used by default, but the approximate version can be enabled for larger datasets where performance is a concern.
The repository includes an example binary that demonstrates:
Run the example with:
cargo run --bin example
The implementation includes both unit tests and integration tests:
Run the tests with:
cargo test
AGPL-3.0