0
$\begingroup$

In doing a project using neural networks with an input layer, 4 hidden layers and an output layer ,I used mini batch gradient descent. I noticed that the randomly initialised weights seemed to do a good performance and gave a low error. As the model started training after about 200 iterations there was large jump in error and then it came down slowly from there. I have also noticed that sometimes the cost just increases over a set of consecutive iterations. Can anyone explain why these happen? It is not like there are outliers or a new distribution as every iteration exposes it to the entire dataset. I used learning rate 0.01 and regularisation parameter 10. I also tried regularisation parameter 5 and also 1. And by the cost I mean, the sum of squared errors of all minibatches/2m plus regularisation term error. Further if this happens and my cost after the say 10000th iteration is more than my cost when I initialised with random weights (lol) can I just take the initial value? As those weights seem to be doing better.

The large jumps are the most puzzling.

This is the code

Any help would be greatly appreciated. Thanks

$\endgroup$
  • 2
    $\begingroup$ Can you share your code and data? A guess would be that your data isn't continuous and thus gradient descent won't work. See stats.stackexchange.com/questions/253088/… $\endgroup$ – ubershmekel Aug 1 '18 at 7:06
  • $\begingroup$ @ubershmekel i have added the code to the question. If you could go through it and figure something out, that would be really helpful. thanks $\endgroup$ – pranav Aug 1 '18 at 9:57
  • $\begingroup$ @ubershmekel You're right the problem are the training data. If the data only contains an XOR-problem the network will make no problems. But a complicated dataset and random datasets are trouble makers for a neural network. So the hint is, to let all parameters of the training algorithm untouched and only make the data more adorable for machine learning. $\endgroup$ – Manuel Rodriguez Aug 1 '18 at 18:58
  • $\begingroup$ @pranav please only paste the code as text, not screenshots. I don't want to have to transcribe your code to test it. $\endgroup$ – ubershmekel Aug 2 '18 at 22:28
  • $\begingroup$ @ubershemekel thank you for your help. But I figured out the problem. The learning rate was too high. So I reduced it down to a really low value and it worked fine. I also used Xavier initialisation. Check out this article: thelaziestprogrammer.com/sharrington/math-of-machine-learning/… $\endgroup$ – pranav Aug 3 '18 at 2:41
1
$\begingroup$

I would say just don't go for using regularization at first, try with lower learning rate = 0.0001 see the behavior. Try to post entire architecture of your model so that one can better answer your problem.

$\endgroup$
  • $\begingroup$ Yeah. I had posted the code. Tried Xavier initialisation. Decreased cost down to 0.0000075 and it converges fine. So I took it down. $\endgroup$ – pranav Aug 3 '18 at 7:04
1
$\begingroup$

I figured out the problem after a bit of trial and error. This article may help too

First i set about pruning the dataset and removed outliers. Then i initialised the weights to better values using xavier initialisation. These made the model slightly better but still the problem occured.

I then set the learning rate down to 0.000000075 and it converged after about 10000 iterations. I guess it was overshooting the minimum and reaching a point on the other side of the minimum that was farther than the previous point. This resulted in increased magnitude of gradient in the opposite direction and the cost explosively went up to the order of billions.

$\endgroup$
  • $\begingroup$ That is an unlikely learning rate, I have never seen anyone use that small learning rate $\endgroup$ – DuttaA Aug 3 '18 at 14:05
  • $\begingroup$ @DuttA I would hazard a guess that the OP has not normalised the inputs. $\endgroup$ – Neil Slater Aug 3 '18 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.