MLPACK: a scalable C++ machine learning library

Ryan R. Curtin, James R. Cline, N. P. Slagle, William B. March, Parikshit Ram, Nishant A. Mehta, Alexander G. Gray

TL;DR

MLPACK is a high-performance C++ machine learning library designed to bridge the gap between ease of use and extreme scalability. By leveraging C++ templates and the Armadillo linear algebra library, it provides a wide array of algorithms that consistently outperform popular alternatives like Weka, MATLAB, and scikit-learn, often by orders of magnitude.

What Problem Does This Paper Address?

In 2012, the machine learning landscape was fragmented. Researchers and engineers typically had to choose between three suboptimal paths:

  1. Ease of Use vs. Scale: Tools like Weka were accessible but scaled poorly to large datasets.
  2. Scalability vs. Overhead: Distributed libraries like Apache Mahout could handle big data but required expensive clusters and high configuration overhead.
  3. Breadth vs. Specialization: Highly efficient libraries like libsvm existed, but they only implemented a single method.

The authors introduced MLPACK to be the "LAPACK of machine learning"—a foundational, general-purpose library that is both computationally efficient and easy for a novice to use on a standard workstation.

Methods

MLPACK is built on several key technical pillars:

  • C++ Template Metaprogramming: This is the "secret sauce." By using templates, MLPACK performs expression optimizations and eliminates unnecessary data copying. It allows for "zero-cost abstractions," where users can swap out components (like switching from Euclidean to Manhattan distance) without the performance penalty usually associated with virtual functions in object-oriented programming.
  • Armadillo Integration: It uses the Armadillo library for highly efficient matrix operations and linear algebra.
  • Dual-Interface Design: Every algorithm is available both as a C++ library function (for integration into larger software systems) and as a standalone command-line executable (for quick experimentation).
  • Novel Algorithms: Beyond standard methods, it includes specialized implementations like "Cover Trees" for faster neighbor searches and "Density Estimation Trees."

Datasets

The authors evaluated MLPACK using ten diverse datasets, primarily sourced from the UCI Machine Learning Repository:

  • Standard Benchmarks: wine, cloud, wine-quality, isolet, corel, and covertype.
  • Large-Scale Data: miniboone (130k instances) and YearPredictionMSD (515k instances).
  • Computer Vision: mnist (70k handwritten digits).
  • Synthetic: randu (1 million instances of random data).

These datasets were chosen to test how the library handles varying dimensions (from 10 to 784) and instance counts.

Key Insights and Ideas

  • The Power of Generic Programming: The most significant insight is that machine learning algorithms can be decomposed into generic components. By using C++ templates, the library allows experts to customize the internal logic of an algorithm (like the tree-splitting rule or the initialization policy) while keeping the code as fast as a hand-optimized, hard-coded version.
  • Single-Machine Efficiency: The results suggest that before moving to a distributed cluster (which introduces network latency and complexity), one should first ensure the implementation is making full use of a single machine's resources.
  • Consistency is Key: By enforcing a consistent API, the authors lower the barrier to entry. A user who learns how to run k-means in MLPACK can intuitively understand how to run a Hidden Markov Model or Lasso regression.

Key Results

The benchmarks focused on k-Nearest Neighbors (k-NN) and k-means clustering, comparing MLPACK against Weka, Shogun, MATLAB, mlpy, and scikit-learn.

  • Speedup: In k-NN tests on the mnist dataset, MLPACK finished in ~2,720 seconds, while competitors either took over 9,000 seconds or failed entirely.
  • Memory Efficiency: On larger datasets like miniboone and covertype, scikit-learn frequently ran out of memory ("memory" error in tables), whereas MLPACK processed them efficiently.
  • Consistency: MLPACK was the fastest in all tested cases for both k-NN and k-means, often performing 5x to 50x faster than the next best competitor.

Limitations and Future Work

At the time of publication, the authors noted several areas for growth:

  • Parallelism: The initial release lacked multi-core support. The authors mentioned that experimental OpenMP support was in development to allow algorithms to scale across multiple CPU cores.
  • Large-Scale Storage: The library required datasets to be loaded entirely into RAM. Future plans included support for on-disk databases to handle datasets larger than available system memory.
  • Model Management: The team aimed to improve the validation and saving/loading of trained models (like decision trees or probability distributions).
  • Algorithm Breadth: While already comprehensive, the authors committed to continuously adding new machine learning methods to the library.

Summary updated

BibTeX
@article{curtin2013mlpack,
  author = {Ryan R. Curtin and James R. Cline and N. P. Slagle and William B. March and Parikshit Ram and Nishant A. Mehta and Alexander G. Gray},
  title = {{MLPACK: a scalable C++ machine learning library}},
  journal = {J. Mach. Learn. Res.},
  year = {2013},
  url = {https://openreview.net/forum?id=bK0AxflBChW},
}
Figure