+ 10

Solving Math using Neural Network.

I was reading an article for Neural Networks from the below URL, and I was checking the example. https://www.sololearn.com/learn/731/?ref=app https://www.sololearn.com/learn/744/?ref=app Example - https://code.sololearn.com/cZSguJFA16ve/?ref=app 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?

19th Apr 2019, 2:09 PM
Felina
Felina - avatar
6 Respuestas
+ 6
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.
19th Apr 2019, 2:31 PM
Anna
Anna - avatar
+ 4
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.
20th Apr 2019, 2:16 AM
Felina
Felina - avatar
+ 2
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.
20th Apr 2019, 11:13 AM
Matthias
Matthias - avatar
+ 1
Nice work
21st Apr 2019, 12:00 PM
Victor
0
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 👍
9th May 2019, 11:16 PM
Pe Kie
Pe Kie - avatar
0
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
10th May 2019, 9:28 PM
Matthias
Matthias - avatar