**New course!**Every coder should learn

**Generative AI!**

+ 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?

6 Answers

+ 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.

+ 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.

+ 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.

+ 1

Nice work

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 👍

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