Thanks @superunification! I will try. By the way, would you have a recommendation of how the convergence criterion should be used. So far I used the value of the cost function obtained after the last epoch. However, this might not necessarily be the best as the cost function can be lower at an intermediate epoch. What is the best way to deal with this?