0

I was trying to use the neural network tool in MATLAB 2011.

I have come across a very weird problem.

I just used the GUI of the neural network to feed my inputs and everything.

My gradient of the neural network is NaN while it gets initialized.

The neural network stops in 1 iteration. ( which I am guessing is because of the gradient being NaN).

As far as my understanding of the NN goes, the gradient isn't supposed to be NaN.

I did check up things using the script mode.

The hidden layer size was 25. (Tried changing this, no effect. Didn't expect it to be, but just in case.)

The default function of trainlm was being used.

It was set to 80/10/10 split for training/validation/testing. (Played around with this too.)

The maximum stopping epochs were set to 1000. Validation iterations that are needed (for the continous check, was set to 6 the default).

So any idea, why my gradient is coming to be NaN? Any help is much appreciated!

1 Answers1

1

Check that the input data doesn't have NaN in it:

any(isnan(inputData(:)))

Also make sure that your preprocessing step (data normalization for example), doesn't introduce NaN values (dividing by zero for example)

Amro
  • 123,847
  • 25
  • 243
  • 454
  • Yes it does. But should it really matter? There are like 1 in 40. –  Jul 29 '12 at 19:29
  • Yes it matters, you see `NaN` tends to spread: `nan*rand(10,1)` – Amro Jul 29 '12 at 19:30
  • Oh okay. Secondly, I am sorry for my naivity in MATLAB but I am currently reading some values from a file, calculating some statistical values and then using the GUI tool. So when you see preprocessing, do you mean whatever piece of code I have written, or is there some internal normalization done in the tool which I would be able to check upon? –  Jul 29 '12 at 19:33
  • 1
    some common approaches to deal with missing data (NaN): replace with mean, imputation, ... – Amro Jul 29 '12 at 19:33
  • @Sylar: mostly your code (honestly I don't recall if NN internally does some normalization, but I doubt it. Documentation will say for sure if there is any) – Amro Jul 29 '12 at 19:37
  • @Sylar: I thought I should clear that input and output are scaled to [-1,1] by default. You can find more info in this other answer of mine: [try to simulate neural network in Matlab by myself](http://stackoverflow.com/a/11853201/97160). Type `help nnprocess` to see a list of pre-processing functions in the NN toolbox. – Amro Aug 09 '12 at 17:44