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
//! # libsvm-rs
//!
//! `libsvm-rs` is a pure Rust reimplementation of
//! [LIBSVM](https://github.com/cjlin1/libsvm) for training, prediction,
//! cross-validation, and LIBSVM text model/problem I/O without an FFI boundary.
//! The public API mirrors the original LIBSVM concepts while using owned Rust
//! data and `Result`-based error handling; see the
//! [migration guide](https://github.com/ricardofrantz/libsvm-rs/blob/main/docs/MIGRATION.md)
//! for a C-to-Rust mapping.
//!
//! ## LIBSVM parity
//!
//! The crate targets numerical equivalence and model-file compatibility with
//! upstream LIBSVM rather than bit-for-bit identity. Core counterparts include
//! [`train::svm_train`] for `svm_train`,
//! [`cross_validation::svm_cross_validation`] for `svm_cross_validation`,
//! [`predict::predict_values`] / [`predict::predict`] /
//! [`predict::predict_probability`] for the prediction APIs, and
//! [`io::save_model`] / [`io::load_model`] for LIBSVM model persistence.
//!
//! ## Quick example
//!
//! ```
//! use libsvm_rs::predict::predict;
//! use libsvm_rs::train::svm_train;
//! use libsvm_rs::{KernelType, SvmNode, SvmParameterBuilder, SvmProblem, SvmType};
//!
//! let problem = SvmProblem {
//! labels: vec![-1.0, -1.0, 1.0, 1.0],
//! instances: vec![
//! vec![SvmNode { index: 1, value: -2.0 }],
//! vec![SvmNode { index: 1, value: -1.0 }],
//! vec![SvmNode { index: 1, value: 1.0 }],
//! vec![SvmNode { index: 1, value: 2.0 }],
//! ],
//! };
//! let param = SvmParameterBuilder::new()
//! .svm_type(SvmType::CSvc)
//! .kernel_type(KernelType::Linear)
//! .build()?;
//!
//! let model = svm_train(&problem, ¶m);
//! let label = predict(&model, &[SvmNode { index: 1, value: 1.5 }]);
//! assert_eq!(label, 1.0);
//! # Ok::<(), libsvm_rs::SvmError>(())
//! ```
//!
//! ## Status
//!
//! Training works for all 5 SVM types (C-SVC, ν-SVC, one-class, ε-SVR,
//! ν-SVR). See [`train::svm_train`] for training, [`predict::predict`]
//! for inference, and [`predict::predict_probability`] for probabilistic
//! outputs. The project repository is
//! <https://github.com/ricardofrantz/libsvm-rs>.
//!
//! ## Trust Boundary
//!
//! Problem and model files are treated as untrusted text input by default.
//! The [`io`] loaders apply [`LoadOptions`] caps, reject malformed sparse
//! feature rows, and validate model-header consistency before allocating
//! support-vector storage. These checks bound parsing work and memory use; they
//! do not authenticate a model or prove that it is appropriate for a particular
//! deployment.
//!
//! ## Feature Flags
//!
//! - `rayon` — Enable parallel cross-validation (off by default), including
//! probability-calibration CV folds for binary SVC models. Fold assignment
//! remains serial and deterministic, then each fold trains on an
//! independent worker. Per-fold training diagnostics are suppressed while the
//! parallel workers run so output cannot interleave; use the default serial
//! path if you need fold-internal progress text. With `k` parallel folds, peak
//! memory can include up to `min(k, rayon_threads)` simultaneous kernel caches
//! of `SvmParameter::cache_size` each; the cache size is never divided
//! implicitly.
//! - `serde` — Enable `Serialize`/`Deserialize` for model and parameter
//! types. `SvmType` and `KernelType` serialize as pinned LIBSVM integer
//! codes (`0..4`). Deserializing `SvmModel` runs the same structural
//! validation as the text model loader; LIBSVM text model files remain the
//! C-compatible interchange format.
use ;
static QUIET_MODE: AtomicBool = new;
static SUPPRESS_INFO_DEPTH: AtomicUsize = new;
/// Enable or disable quiet mode. When quiet, solver diagnostic messages
/// are suppressed (equivalent to LIBSVM's `-q` flag).
/// Print an info message to stderr (suppressed in quiet mode).
pub
pub
/// Fluent builder for [`SvmParameter`](crate::SvmParameter) values.
/// Kernel-row cache used by the SMO solver.
/// Error types returned by fallible parsing, validation, and I/O APIs.
/// LIBSVM problem/model text-format loading and saving.
/// Kernel functions equivalent to LIBSVM's linear, polynomial, RBF, sigmoid, and precomputed kernels.
/// Helpers for classification accuracy and regression error summaries.
/// Q-matrix implementations consumed by the SMO solver.
/// Sequential Minimal Optimization solver internals corresponding to LIBSVM's `Solver` and `Solver_NU`.
/// Training entry points corresponding to LIBSVM's `svm_train`.
/// LIBSVM-compatible public data structures and C-style helper functions.
/// Utility routines shared by training, parsing, and parity-oriented algorithms.
/// Cross-validation entry point corresponding to LIBSVM's `svm_cross_validation`.
/// Prediction entry points corresponding to LIBSVM's `svm_predict*` APIs.
/// Probability-estimation routines corresponding to LIBSVM's Platt-scaling and related helpers.
/// Fluent parameter builder with LIBSVM-compatible defaults.
pub use SvmParameterBuilder;
/// Structured errors returned instead of LIBSVM integer/null failure codes.
pub use SvmError;
/// Resource caps for untrusted LIBSVM text input.
pub use LoadOptions;
/// Accuracy and regression metric helpers.
pub use ;
/// Public LIBSVM-compatible types and helper functions.
pub use *;