Mlpack: Error running ANN code

Created on 17 Oct 2018  路  3Comments  路  Source: mlpack/mlpack

I'm trying to create an FFN to predict a continuous value. The code compiles but I get the following error when calling model.Train():

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)

Here's the network:

FFN<> model;
model.Add<Linear<> > (train_x.n_rows, 20);
model.Add<Linear<> > (20, 30);
model.Add<Linear<> > (30, train_y.n_rows);
model.train(train_x, train_y); //train_x and train_y are arma::mat-s of shapes (8, 2000) and  (1, 2000)

I found some issues similar to this, like #1525 and #1415, but couldn't solve it.
Any help would be appreciated. Thank you.

Most helpful comment

Hi there,

By default the FFN<> class uses NegativeLogLikelihood<> as a loss function, which is for classification problems. Since you're trying to predict a continuous value, this is now regression, so I think you'll need to use a loss function like mean squared error:

FFN<MeanSquaredError<>> model;

Hope this helps. :)

All 3 comments

Hi there,

By default the FFN<> class uses NegativeLogLikelihood<> as a loss function, which is for classification problems. Since you're trying to predict a continuous value, this is now regression, so I think you'll need to use a loss function like mean squared error:

FFN<MeanSquaredError<>> model;

Hope this helps. :)

That did it. Thanks again @rcurtin ! :D

Glad to help :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KoushikSahu picture KoushikSahu  路  6Comments

FloopCZ picture FloopCZ  路  6Comments

mrityunjay-tripathi picture mrityunjay-tripathi  路  6Comments

kartikdutt18 picture kartikdutt18  路  3Comments

joeljosephjin picture joeljosephjin  路  5Comments