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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//!
//! A crate that provides some boosting algorithms.
//! All the boosting algorithm in this crate,
//! except `LPBoost`, has theoretical iteration bound
//! until finding a combined hypothesis.
//!
//! This crate includes three types of boosting algorithms.
//!
//! * Empirical risk minimizing (ERM) boosting
//! - [`AdaBoost`],
//! - [`GraphSepBoost`].
//!
//!
//! * Hard margin maximizing boosting
//! - [`AdaBoostV`],
//! - [`TotalBoost`](crate::booster::TotalBoost).
//!
//!
//! * Soft margin maximizing boosting
//! - [`LPBoost`](crate::booster::LPBoost),
//! - [`SoftBoost`](crate::booster::SoftBoost),
//! - [`SmoothBoost`],
//! - [`ERLPBoost`](crate::booster::ERLPBoost),
//! - [`CERLPBoost`],
//! - [`MLPBoost`](crate::booster::MLPBoost).
//!
//!
//! This crate also includes some Weak Learners.
//! * Classification
//! - [`DecisionTree`],
//! - [`NeuralNetwork`],
//! - [`GaussianNB`],
//! - [`BadBaseLearner`] (The bad base learner for LPBoost).
//! * Regression
//! - [`RegressionTree`]. Note that the current implement is not efficient.
//!
//! # Example
//! The following code shows a small example for running [`LPBoost`].
//! See also:
//! - [`LPBoost::nu`]
//! - [`LPBoost::tolerance`]
//! - [`DecisionTree`]
//! - [`DecisionTreeClassifier`]
//!
//! [`LPBoost::nu`]: LPBoost::nu
//! [`LPBoost::tolerance`]: LPBoost::tolerance
//! [`DecisionTree`]: crate::weak_learner::DecisionTree
//! [`DecisionTreeClassifier`]: crate::weak_learner::DecisionTreeClassifier
//! [`NeuralNetwork`]: crate::weak_learner::NeuralNetwork
//! [`WeightedMajority<F>`]: crate::hypothesis::WeightedMajority
//! [`GaussianNB`]: crate::weak_learner::GaussianNB
//! [`BadBaseLearner`]: crate::weak_learner::BadBaseLearner
//!
//! ```no_run
//! use miniboosts::prelude::*;
//!
//! // Read the training sample from the CSV file.
//! // We use the column named `class` as the label.
//! let path = "path/to/dataset.csv";
//! let sample = SampleReader::new()
//! .file(path)
//! .has_header(true)
//! .target_feature("class")
//! .read()
//! .unwrap();
//!
//! // Get the number of training examples.
//! let n_sample = data.shape().0 as f64;
//!
//! // Initialize `LPBoost` and set the tolerance parameter as `0.01`.
//! // This means `booster` returns a hypothesis whose training error is
//! // less than `0.01` if the traing examples are linearly separable.
//! // Note that the default tolerance parameter is set as `1 / n_sample`,
//! // where `n_sample = data.shape().0` is
//! // the number of training examples in `data`.
//! // Further, at the end of this chain,
//! // LPBoost calls `LPBoost::nu` to set the capping parameter
//! // as `0.1 * n_sample`, which means that,
//! // at most, `0.1 * n_sample` examples are regarded as outliers.
//! let booster = LPBoost::init(&sample)
//! .tolerance(0.01)
//! .nu(0.1 * n_sample);
//!
//! // Set the weak learner with setting parameters.
//! let weak_learner = DecisionTreeBuilder::new(&sample)
//! .max_depth(2)
//! .criterion(Criterion::Entropy)
//! .build();
//!
//! // Run `LPBoost` and obtain the resulting hypothesis `f`.
//! let f = booster.run(&weak_learner);
//!
//! // Get the predictions on the training set.
//! let predictions = f.predict_all(&data);
//!
//! // Calculate the training loss.
//! let target = sample.target();
//! let training_loss = target.into_iter()
//! .zip(predictions)
//! .map(|(&y, fx)| if y as i64 == fx { 0.0 } else { 1.0 })
//! .sum::<f64>()
//! / n_sample;
//!
//! println!("Training Loss is: {training_loss}");
//! ```
// pub mod pywriter;
// Export the struct that represents batch sample
pub use ;
// Export some traits and the combined hypothesis struct.
pub use ;
// Export the `Booster` trait.
pub use Booster;
// Export the boosting algorithms that minimizes the empirical loss.
pub use ;
// Export the boosting algorithms that maximizes the hard margin.
pub use ;
// Export the boosting algorithms that maximizes the soft margin.
// (These boosting algorithms use Gurobi)
pub use ;
// Export the boosting algorithms for regression
pub use ;
// Export other boosting algorithms
pub use GraphSepBoost;
// Export the `WeakLearner` trait.
pub use WeakLearner;
// Export the instances of the `WeakLearner` trait.
pub use ;
// Export the instances of the `Classifier` trait.
// The `CombinedClassifier` is the output of the `Boosting::run(..)`.
pub use ;
pub use ;
/// Some useful functions / traits
pub use ;
pub use ;