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
//! The random-world crate.
//!
//! A crate implementing Machine Learning ML methods for confident prediction
//! (e.g., Conformal Predictors) and related ones introduced in the book
//! Algorithmic Learning in a Random World ([ALRW](http://alrw.net/)).
//!
//!
//! # Goals
//! * Fast implementation of methods introduced in the book ALRW.
//! * Should easily allow to wrap existing rust implementations of ML
//!   classifiers/scorers.
//! * (Maybe) allow interfacing to Python.
//! * (Maybe) can be called as a binary.
//!
//! # Examples
//!
//! Create a Conformal Predictor with k-NN nonconformity measure, `k=2`,
//! and with significance level `epsilon=0.3`, train it on some training
//! set and use it to predict two test vector inputs.
//!
//! The output predictions will be a matrix, one row per each training
//! input, and one column per label, where each `bool` element is `true`
//! if the label conforms the distribution, `false` otherwise.
//!
//! ```
//! #[macro_use(array)]
//! extern crate ndarray;
//! extern crate random_world;
//!
//! # fn main() {
//! use random_world::cp::*;
//! use random_world::ncm::*;
//!
//! let ncm = KNN::new(2);
//! let n_labels = 2;
//! let mut cp = CP::new(ncm, n_labels, Some(0.3));
//! let train_inputs = array![[0., 0.],
//!                           [1., 0.],
//!                           [0., 1.],
//!                           [1., 1.],
//!                           [2., 2.],
//!                           [1., 2.]];
//! let train_targets = array![0, 0, 0, 1, 1, 1];
//! let test_inputs = array![[2., 1.],
//!                          [2., 2.]];
//!
//! // Train and predict
//! cp.train(&train_inputs.view(), &train_targets.view())
//!   .expect("Failed prediction");
//! let preds = cp.predict(&test_inputs.view())
//!               .expect("Failed to predict");
//! assert!(preds == array![[false, true],
//!                         [false, true]]);
//! # }
//! ```
//!
//! More examples on deterministic/smooth Conformal Predictors at
//! [CP](/cp/cp/struct.CP.html).
#![warn(missing_docs)]

extern crate rand;
extern crate pcg_rand;
extern crate itertools;
extern crate rusty_machine;
extern crate ordered_float;
#[macro_use]
extern crate ndarray;
extern crate csv;
extern crate statrs;
extern crate quadrature;
extern crate lazysort;
#[macro_use]
extern crate approx;

pub mod cp;
pub mod ncm;
pub mod utils;
pub mod exchangeability;