Giter VIP home page Giter VIP logo

sparsifiedkmeans's Introduction

SparsifiedKMeans

KMeans for big data using preconditioning and sparsification, Matlab implementation. Uses the KMeans clustering algorithm (also known as Lloyd's Algorithm or "K Means" or "K-Means") but sparsifies the data in a special manner to achieve significant (and tunable) savings in computation time and memory.

The code provides kmeans_sparsified which is used much like the kmeans function from the Statistics toolbox in Matlab. There are three benefits:

  1. The basic implementation is much faster than the Statistics toolbox version. We also have a few modern options that the toolbox version lacks; e.g., we implement K-means++ for initialization. (Update: Since 2015, Matlab has improved the speed of their routine and initialization, and now their version and ours are comparable).
  2. We have a new variant, called sparsified KMeans, that preconditions and then samples the data, and this version can be thousands of times faster, and is designed for big data sets that are unmangeable otherwise
  3. The code also allows a big-data option. Instead of passing in a matrix of data, you give it the location of a .mat file, and the code will break the data into chunks. This is useful when the data is, say, 10 TB and your computer only has 6 GB of RAM. The data is loaded in smaller chunks (e.g., less than 6 GB), which is then preconditioned and sampled and discarded from RAM, and then the next data chunk is processed. The entire algorithm is one-pass over the dataset.

/Note/: if you use our code in an academic paper, we appreciate it if you cite us: "Preconditioned Data Sparsification for Big Data with Applications to PCA and K-means", F. Pourkamali Anaraki and S. Becker, IEEE Trans. Info. Theory, 2017.

Why use it?

For moderate to large data, we believe this is one of the fastest ways to run k-means. For extremely large data that cannot all fit into core memory of your computer, we believe there are almost no good alternatives (in theory and practice) to this code.

Installation

Every time you start a new Matlab session, run setup_kmeans and it will correctly set the paths. The first time you run it, it may also compile some mex files; for this, you need a valid C compiler (see http://www.mathworks.com/support/compilers/R2015a/index.html).

Version

Current version is 2.1

Authors

Reference

Preconditioned Data Sparsification for Big Data with Applications to PCA and K-means, F. Pourkamali Anaraki and S. Becker, IEEE Trans. Info. Theory, 2017. See also the arXiv version

Bibtex:

@article{SparsifiedKmeans,
    title = {Preconditioned Data Sparsification for Big Data with Applications to {PCA} and {K}-means},
    Author = {Pourkamali-Anaraki, F. and Becker, S.},
    year = 2017,
    doi = {10.1109/TIT.2017.2672725},
    journal = {IEEE Trans. Info. Theory},
    volume = 63,
    number = 5,
    pages = {2954--2974}
}

Related projects

  • sparsekmeans by Eric Kightley is our joint project to implement the algorithm in python, and support out-of-memory operations. The sparseklearn is the generalization of this idea to other types of machine learning algorithms (also python).

Further information

Some images taken from the paper or slides from presentations; see the journal paper for full explanations

Example on synthetic data

Example on synthetic data

Main idea

Main idea

MNIST experiment

MNIST experiment MNIST accuracy

Infinite MNIST big data experiment

MNIST2 accuracy

Two-pass mode for increased accuracy

Two pass

Theory

Theory

sparsifiedkmeans's People

Contributors

stephenbeckr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sparsifiedkmeans's Issues

can't run 'example_loadFromDisk.m'

Hello, when I try to run your demo, I have come across a problem. When I run the file 'example_loadFromDisk.m', the bug shows that Y = [Y Yj]; in file sampleAndMixFromLargeFile.m that the dim of Y and Yj is not equal. Could you help me with this problem? Thanks a lot.

Compile error of 'hadamard_pthreads.c'

Hey, dear stephen
When I run 'setup_kmeans', 'hadamard_pthreads.c' can't compile successfully, because “pthread.h”: No such file or directory.
Can you tell me if it is a real missing file or I can simply remove this line from code?
Best regards.

Customizing distance function in k-means algorithm

Hi~
I want to use a specific distance function (not provided in Matlab's original k-means) due to the structure of data I am dealing with. Since the distance function can simply be written as "distance = function(point_1, point_2)", I am wondering if customized distance function can be used in your wonderful implementation of K-means algorithm. Thank you~

FOR loop index is too large. Truncating to 9223372036854775807.

Hi!

I was using your sparsified kmeans and i think it is absolutely great. But i had encountered this error when using your code

Input: 5244949 x 35 in a mat file

Output: Splitting 5244949 x 35 matrix into Inf 5244949 x 0 chunks

The error code goes like this in matlab

`Warning: FOR loop index is too large. Truncating to 9223372036854775807.

In sampleAndMixFromLargeFile (line 96)
In kmeans_sparsified (line 301)
In example_loadFromDisk (line 55)
Error using sampleAndMixFromLargeFile (line 100)
Cannot index into 'X' because indices cannot be empty.

Error in kmeans_sparsified (line 301)
[X,timeLoad,timeMix,timeSample] = sampleAndMixFromLargeFile( DataFile, SparsityLevel, mix, p2,...

Error in example_loadFromDisk (line 55)
[indx,centers,sumd,dist_sketch] = kmeans_sparsified( [], k,'ColumnSamples',true,... '

I am using the loadfromDisk function but i've also tried using smaller values and it works like a charm.

small_p = 0 prevents code from running

To prevent small_p from being 0, maybe it's better to replace ln. 326 in kmeans_sparsified with:
small_p = max(1, round( SparsityLevel*p2 ));

(similarly ln. 323)

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.