#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum SvmType {
CSvc = 0,
NuSvc = 1,
OneClass = 2,
EpsilonSvr = 3,
NuSvr = 4,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum KernelType {
Linear = 0,
Polynomial = 1,
Rbf = 2,
Sigmoid = 3,
Precomputed = 4,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SvmNode {
pub index: i32,
pub value: f64,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SvmProblem {
pub labels: Vec<f64>,
pub instances: Vec<Vec<SvmNode>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SvmParameter {
pub svm_type: SvmType,
pub kernel_type: KernelType,
pub degree: i32,
pub gamma: f64,
pub coef0: f64,
pub cache_size: f64,
pub eps: f64,
pub c: f64,
pub weight: Vec<(i32, f64)>,
pub nu: f64,
pub p: f64,
pub shrinking: bool,
pub probability: bool,
}
impl Default for SvmParameter {
fn default() -> Self {
Self {
svm_type: SvmType::CSvc,
kernel_type: KernelType::Rbf,
degree: 3,
gamma: 0.0, coef0: 0.0,
cache_size: 100.0,
eps: 0.001,
c: 1.0,
weight: Vec::new(),
nu: 0.5,
p: 0.1,
shrinking: true,
probability: false,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct SvmModel {
pub param: SvmParameter,
pub nr_class: usize,
pub sv: Vec<Vec<SvmNode>>,
pub sv_coef: Vec<Vec<f64>>,
pub rho: Vec<f64>,
pub prob_a: Vec<f64>,
pub prob_b: Vec<f64>,
pub prob_density_marks: Vec<f64>,
pub sv_indices: Vec<usize>,
pub label: Vec<i32>,
pub n_sv: Vec<usize>,
}