#svm #machine-learning #libsvm

nightly ffsvm

A libSVM compatible support vector machine, but up to 10x faster, for games or VR

12 unstable releases (4 breaking)

✓ Uses Rust 2018 edition

0.8.0 Jun 7, 2019
0.7.1 Mar 16, 2019
0.6.5 Mar 10, 2019
0.6.2 Oct 6, 2018
0.4.3 Aug 5, 2018

#5 in Machine learning

Download history 39/week @ 2019-03-25 30/week @ 2019-04-01 24/week @ 2019-04-08 1/week @ 2019-04-15 14/week @ 2019-04-22 7/week @ 2019-04-29 21/week @ 2019-05-06 13/week @ 2019-05-13 41/week @ 2019-05-20 39/week @ 2019-05-27 62/week @ 2019-06-03 70/week @ 2019-06-10 37/week @ 2019-06-17 267/week @ 2019-06-24 63/week @ 2019-07-01

122 downloads per month

MIT license

130KB
1.5K SLoC

Latest Version Travis-CI Status deps.svg docs MIT

In One Sentence

You trained a SVM using libSVM, now you want the highest possible performance during (real-time) classification, like games or VR.

Highlights

  • loads almost all libSVM types (C-SVC, ν-SVC, ε-SVR, ν-SVR) and kernels (linear, poly, RBF and sigmoid)
  • produces practically same classification results as libSVM
  • optimized for SIMD and can be mixed seamlessly with Rayon
  • written in 100% Rust
  • allocation-free during classification for dense SVMs
  • 2.5x - 14x faster than libSVM for dense SVMs
  • extremely low classification times for small models (e.g., 128 SV, 16 dense attributes, linear ~ 500ns)
  • successfully used in Unity and VR projects (Windows & Android)

Note: Currently requires Rust nightly (March 2019 and later), because we depend on RFC 2366 (portable SIMD). Once that stabilizes we'll also go stable.

Usage

Train with libSVM (e.g., using the tool svm-train), then classify with ffsvm-rust.

From Rust:

// Replace `SAMPLE_MODEL` with a `&str` to your model.
let svm = DenseSVM::try_from(SAMPLE_MODEL)?;

let mut problem = Problem::from(&svm);
let features = problem.features();

features[0] = 0.55838;
features[1] = -0.157895;
features[2] = 0.581292;
features[3] = -0.221184;

svm.predict_value(&mut problem)?;

assert_eq!(problem.solution(), Solution::Label(42));

Status

  • June 7, 2019: Gave up on 'no unsafe', but gained runtime SIMD selection.
  • March 10, 2019: As soon as we can move away from nightly we'll go beta.
  • Aug 5, 2018: Still in alpha, but finally on crates.io.
  • May 27, 2018: We're in alpha. Successfully used internally on Windows, Mac, Android and Linux on various machines and devices. Once SIMD stabilizes and we can cross-compile to WASM we'll move to beta.
  • December 16, 2017: We're in pre-alpha. It will probably not even work on your machine.

Performance

performance

Classification time vs. libSVM for dense models.

performance

Performance milestones during development.

All performance numbers reported for the DenseSVM. We also have support for SparseSVMs, which are slower for "mostly dense" models, and faster for "mostly sparse" models (and generally on the performance level of libSVM).

See here for details.

Tips

  • For an x-fold performance increase, create a number of Problem structures, and process them with Rayon's par_iter.

FAQ

See here for details.

Dependencies

~615KB
~13K SLoC