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
pub use crate;
pub use crateError;
pub use crate;
pub use crateModel;
pub use crateWarning;
/// Infers the asymptotic complexity of measured `(input size, cost)` pairs.
///
/// Repeated measurements of the same input size are collapsed to their median
/// before fitting, so an occasional descheduled run does not steer the result.
/// Non-finite measurements are dropped. A model that cannot describe what
/// remains — a logarithmic one given an input size of zero, say — is skipped
/// and listed in [`Inference::warnings`], and the models that can still compete.
///
/// Use [`Analysis`] to infer over a restricted set of models.
///
/// # Errors
/// Returns [`Error::NotEnoughData`] if fewer than three distinct input sizes
/// survive that preparation, and [`Error::NoValidComplexity`] if no model
/// describes what does.
///
/// # Example
/// ```
/// // Cost measured over growing inputs, with a few percent of timing noise.
/// let data = [
/// (100., 10_180.),
/// (200., 39_800.),
/// (400., 161_440.),
/// (800., 637_440.),
/// (1600., 2_570_240.),
/// (3200., 10_352_640.),
/// (6400., 40_673_280.),
/// (12800., 164_167_680.),
/// ];
///
/// let inference = big_o::infer_complexity(&data).unwrap();
///
/// assert_eq!(inference.best.model, big_o::Model::Quadratic);
/// assert_eq!(inference.best.to_string(), "O(n^2)");
/// assert!(inference.best.is_at_most(big_o::Model::Quadratic));
/// assert!(inference.confidence > 0.9);
/// ```