10.02.2021 Views

Neural Networks from Scratch in Python by Harrison Kinsley, Daniel Kukie a

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2 - Coding Our First Neurons - Neural Networks from Scratch in Python

9

What might we need to change if we have 4 inputs, rather than the 3 we’ve just shown? Next to

the additional input, we need to add an associated weight, which this new input will be multiplied

with. We’ll make up a value for this new weight as well. Code for this data could be:

inputs ​= ​[​1.0​, ​2.0​, ​3.0​, ​2.5​]

weights ​= ​[​0.2​, ​0.8​, ​-​0.5​, ​1.0​]

bias ​= ​2.0

Which could be depicted visually as:

Fig 2.02:​ Visualizing how the inputs, weights, and biases from the code interact with the neuron.

Anim 2.02:​ ​https://nnfs.io/djp

All together in code, including the new input and weight, to produce output:

inputs ​= ​[​1.0​, ​2.0​, ​3.0​, ​2.5​]

weights ​= ​[​0.2​, ​0.8​, ​-​0.5​, ​1.0​]

bias ​= ​2.0

output ​= ​(inputs[​0​]​*​weights[​0​] ​+

​inputs[​1​]​*​weights[​1​] ​+

​inputs[​2​]​*​weights[​2​] ​+

​inputs[​3​]​*​weights[​3​] ​+ ​bias)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!