Solving Math using Neural Network. | Sololearn: Learn to code for FREE!


Solving Math using Neural Network.

I was reading an article for Neural Networks from the below URL, and I was checking the example. Example - but I can't understand the Line No 7 in the example which says self.weights = 2 * random.random((2, 1)) - 1 How this formula derived for adding random weight? I mean does this formula will always same for any mathematic operation, if not how we can derive formula?

4/19/2019 2:09:19 PM


7 Answers

New Answer


That's just how the weights are initialized. x * numpy.random.random((y, z)) means: Create a 2 dimensional array of pseudo random numbers between 0 and 1 with y rows * z columns and multiply each number in the array with x.


Anna yh I got that, but I want to know how this formula derived. I mean if I want to create a code for square of a number similar as above example this formula won't work. so for me, how this things are working is more important, what would be the formula for square of number.


If I adjust the outputs to be the result of (a+b)² it works quite well. For the new input it says 281.5 as a result. The exact result would be 289, which is quite close in my opinion.


Nice work


Matthias I would be interested to know the reason why the neural network is not able to learn the weights for (a+b)^2 exactly although it is provided perfect training data... just like for (a+b)*2? Would a code update work? Would you require more training data? Should the network structure be more complex? Thanks for any input if you read this still 👍


Pe Kie Unfortunately I can't explain it well, I only know very bit of machine learning 🙈 There was a comment of another user explaining it quite well, but it seems it got deleted :/ What it was basically saying is, that the structure of used network corresponds to linear functions. For quadratic function we need a different network. Something like this. But take it with care, I know nothing xD