[mlpack] sparse coding test examples in mlpack

Jianyu Huang hjyahead at gmail.com
Wed Jun 3 11:52:11 EDT 2015


Hi all,



I am new to sparse coding, and I try to use mlpack to test sparse coding. I
have sucessfully installed mlpack on a Ubuntu 14.04 64-bit machine.



1.

I run "make test". So if I understand correctly, I am running
"bin/mlpack_test" actually. I check the DEBUG/WARN log output for the test.
In the beginning, it shows "Running 402 test cases...". In almost the end,
I find "Sparse Coding" is examined in this test. It shows the Data is
40x40, Atoms is 3, Lambda 1 is 0.1 and Lambda 2 is 0.

So what data set is tested here? Where can I get this “40x40” data?



2.

I copy src/mlpack/tests/sparse_coding_test.cpp to a separate cpp file, and
try to remove all macros depending on boost/test/unit_test. So the new test
cpp file looks like:



int main() {

  double lambda1 = 0.1;

  uword nAtoms = 25;


  mat X;

  X.load("mnist_first250_training_4s_and_9s.arm");

  uword nPoints = X.n_cols;


  // Normalize each point since these are images.

  for (uword i = 0; i < nPoints; ++i) {

    X.col(i) /= norm(X.col(i), 2);

  }


  SparseCoding<> sc(X, nAtoms, lambda1);

  sc.OptimizeCode();


  mat D = sc.Dictionary();

  mat Z = sc.Codes();


  for (uword i = 0; i < nPoints; ++i)

  {

    vec errCorr = trans(D) * (D * Z.unsafe_col(i) - X.unsafe_col(i));

    SCVerifyCorrectness(Z.unsafe_col(i), errCorr, lambda1);

  }


}



However, it shows the following error:

-------------------------------------------------------------------------------------------

Mat::load(): couldn't read mnist_first250_training_4s_and_9s.arm


error: Mat::col(): index out of bounds


terminate called after throwing an instance of 'std::logic_error'

  what():  Mat::col(): index out of bounds

Aborted (core dumped)
-------------------------------------------------------------------------------------------

I checked the data “mnist_first250_training_4s_and_9s.arm” is only 3M, so
it should not exceed the “4 billion elements” restrictions for Armadillo
without “ARMA_64BIT_WORD” configurations. Do you have any idea about why
this error happen?

Also, how can visualize/show the data in “
mnist_first250_training_4s_and_9s.arm”? I don’t know what the data looks
like.





3.

The command line interface for sparse_coding is as the following,

$ sparse_coding -i data.csv -k 200 -l 0.1 -d dict.csv -c codes.csv

Could you give me an example of data.csv? Sorry I don't know what the input
of sparse coding should look like.



Thank you!
Jianyu Huang

Department of Computer Science
The University of Texas at Austin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack/attachments/20150603/1cd412f1/attachment.html>


More information about the mlpack mailing list