Code Monkey home page Code Monkey logo

kmeansrex's Introduction

KMeansRex : Fast C++ implementation of K-Means using the Eigen matrix template library, with hooks to Matlab and Python/Numpy

This toolbox is meant to be the tyrant lizard king of k-means implementations. It is at least 2x as fast as the native kmeans implementations provided by matlab and scipy. It provides smart modern kmeans++ initialization as a default. Code is fully vectorized using the excellent Eigen matrix template library.

Repo Contents

  • src/ : C++ source files and header files
  • matlab/ : matlab MEX source files
  • python/ : python package files

Dependencies

  • Eigen Matrix Template Library (http://eigen.tuxfamily.org)
  • Python 2.7 (for python functionality)
    • Requires numpy and other standard numerical packages.
  • Matlab R2011 or greater (for matlab functionality)

Python Usage

Assuming your PYTHONPATH includes /path/to/KMeansRex/python/

  >> import numpy as np
  >> import KMeansRex
  >> X = np.random.rand(1000,5)
  >> Mu, Z = KMeansRex.RunKMeans(X, 3)

Matlab Usage

Assuming your current path includes /path/to/KMeansRex/matlab/

  >> X = rand(1000, 5)
  >> [Mu,Z] = KMeansRex( X, 3 );

C++ Usage

In your source file, include KMeansRexCoreInterface.h

    #include "KMeansRexCoreInterface.h"

Then you can call public functions like RunKMeans as needed.

Compiling

To build everything for Matlab

    $ cd /path/to/KMeansRex/
    $ make matlab

To build everything for Python

    $ cd /path/to/KMeansRex/
    $ make python

To build a custom C++ application

When compiling, modify your include and library paths as necessary.

    g++ main.cpp -o main \
        -I/path/to/eigen \
        -I/path/to/KMeansRex/src/ \
        -L/path/to/KMeansRex/lib/ \
        -Wl,-rpath=/path/to/KMeansRex/lib/ -lkmeansrex[32|64]

All Makefile builds require a correct path to the Eigen library in the environment variable EIGEN_INCLUDE, which will be detected automatically via pkg-config if possible. See Makefile for details.

Useful flags for eigen to suppress many warnings:

  • -Wno-ignored-attributes
  • -Wno-misleading-indentation
  • -Wno-deprecated-declarations

Author:

Mike Hughes (www.michaelchughes.com). Please email all comments/questions to mike AT michaelchughes.com

License

This software is released under a BSD 3-clause license. See the LICENSE file for details.

Acknowledgements

Thanks to Alexander Grebenyuk and Kaveh Vakili for many helpful suggestions which improved the organization and usefulness of this code.

Includes the random number generation code provided by Makoto Matsumoto and Takuji Nishimura. Source: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.