1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! # `lt.rs`
//!
//! ltrs is a Learning to Rank library.
//! Think `RankLib`, but in Rust.
//!
//! ```ignore
//! use ltrs::{
//! ensemble::adarank::AdaRank,
//! eval::map::MAP,
//! learner::Learner,
//! loader::{LtrFormat, svmlight::SVMLight},
//! ranker::Ranker,
//! };
//!
//! fn main() {
//!
//! // Let's load a dataset from the ohsumed corpus
//! let corpus = std::path::Path::new("benchmarks/OHSUMED").join("Data/All/OHSUMED.txt");
//!
//!
//! // Load a SVMLight dataset.
//! let ohsumed_dataset = SVMLight::load(corpus.to_str().unwrap()).unwrap();
//! // Clone a `RankList` to test later...
//! let test_sample = ohsumed_dataset[0].clone();
//!
//! // Create an AdaRank learner with MAP as the evaluation metric, 50 iterations,
//! // 3 max consecutive selections, and 0.003 tolerance.
//! let mut adarank = AdaRank::new(ohsumed_dataset, Box::new(MAP), 50, 3, 0.003, None, None);
//!
//!
//! // Fit the learner to the dataset.
//! adarank.fit().unwrap();
//!
//! // Get the test `DataPoint` from the `RankList`.
//! let dp = test_sample.get(0).unwrap();
//!
//!
//! // Predict the score for the test `DataPoint`.
//! let doc_label = adarank.predict(&test_sample.get(0).unwrap());
//! println!("Document {} has the score {:.2} for query {}",
//! dp.get_description().unwrap(),
//! doc_label,
//! dp.get_query_id());
//!
//! }
//!
//! ```
//!
//!
//!
//! A good place for you to get started is to check out
//! the example code (
//! [source code](https://github.com/marcosfpr/ltrs/blob/master/examples/ohsumed.rs))
extern crate lazy_static;
///
/// Define a core primitive for the library: `DataPoint`.
/// A `DataPoint` is a element of a `RankList` in a `DataSet`.
///
///
/// Define a core primitive for the library: `RankList`.
/// A `RankList` is a list of `DataPoint`s and provides methods for
/// ranking them.
///
///
/// Define the error type for the library.
///
///
/// Define evaluators for the library.
/// Evaluators are used to evaluate the performance of a `Learner`.
///
///
/// Utility functions for the library.
/// These functions are not part of the core API, but are useful inside the library.
///
///
/// Define the loader for the library. A `Loader` is used to load a `DataSet` from a
/// IO stream.
///
///
/// Define the `Ranker` primitive. All AI algorithms in the library are `Ranker`s,
/// which means they can be used to predict the score of `DataPoint`s in `RankList`s .
///
///
/// Define the `Learner` primitive. A `Learner` is define operationss required
/// to train a `Ranker`.
///
///
/// Define a class of `Ranker`s based on ensemble methods.
///
///
/// A particular Feature for lt.rs is just a floating point value.
/// The feature_value is the value of the feature.
type Feature = f32;
///
/// For simplicity, we will use a DataSet as a vector of RankLists.
///
pub type DataSet = ;