I have written an ANN algorithm. And after several iterations my weights grow largely and there's this error which says the value of them is overflowing and therefore the outputs are NaNs. Does it make sense to scale weights for each layer to avoid them from growing very large by dividing them by the largest weight?!
One approach to mitigate this issue could be normalise your inputs. For example, you could subtract the mean of your dataset from each element of your dataset such that the mean of your dataset is zero.