Search code examples
c++machine-learningneural-networkmlpack

mlpack : index out of bounds in FFN<>


I have this code :

#include<mlpack/core.hpp>
#include<mlpack/methods/ann/ffn.hpp>
#include<mlpack/methods/ann/layer/linear.hpp>

int main(int argc, char** argv){
    assert(argc==3);
    arma::mat data_in, data_out;
    mlpack::data::Load(argv[1], data_in);
    mlpack::data::Load(argv[2], data_out);

    std::cout<<"creating model"<<std::endl;

    mlpack::ann::FFN<> model;
    model.Add<mlpack::ann::Linear<>>(data_in.n_rows, 10);
    model.Add<mlpack::ann::SigmoidLayer<>>();
    model.Add<mlpack::ann::Linear<>>(10, data_out.n_rows);
    model.Add<mlpack::ann::SigmoidLayer<>>();

    std::cout<<"training started"<<std::endl;

    model.Train(data_in, data_out);

}

When I try to run this I always get index out of bounds error :

creating model
training started

error: Mat::operator(): index out of bounds
terminate called after throwing an instance of 'std::logic_error'
  what():  Mat::operator(): index out of bounds
Aborted (core dumped)

I also checked the mlpack tutorial on ann::FFN<> and when I try to run that code, it works completely fine! The dataset which I am using here is a dataset of 10000 rows and 5 columns which when used here gets converted to 5 rows and 10000 columns as mlpack treats a column as a point. Each and every number in the dataset is a value in between 0 and 1 and is generated randomly. Both input and output datasets have same dimensions. The documentation was also not that helpful.


Solution

  • Make sure your training labels range from [1, #classes].