HexaHype
Start reading
Neural Networks Browse lessons

Neural Networks Β· Neural Networks Β· 4 min read

What one neuron computes

A neural network looks complicated, but it is built from one small unit repeated thousands of times. That unit is the neuron, and it does something simple enough to write on one line. Learn this single operation and the rest of the course is just arrangement and repetition.

A neuron multiplies each input by a weight, adds the results together, and adds a bias. That one number is everything a neuron does.

The inputs, the weights, and the bias

A neuron receives several numbers as input. Each input is multiplied by its own weight, a number that says how much that input matters. The neuron adds up all those products and then adds one more number, the bias. The result is a single number:

z=βˆ‘i=1nwixi+b=wβ‹…x+bz = \sum_{i=1}^{n} w_i x_i + b = \mathbf{w} \cdot \mathbf{x} + b

Reading the symbols one by one:

  • xix_i is the ii-th input, and nn is how many inputs there are.
  • wiw_i is the weight on input xix_i. A large weight makes that input count for more.
  • bb is the bias, a fixed number added regardless of the inputs.
  • wβ‹…x\mathbf{w} \cdot \mathbf{x} is the dot product, a compact way to write w1x1+w2x2+β‹―+wnxnw_1 x_1 + w_2 x_2 + \dots + w_n x_n.
  • zz is the neuron’s output so far, a single number.
One neuron: each input is multiplied by a weight, the products are summed, and a bias is added to produce the output z.
One neuron: each input is multiplied by a weight, the products are summed, and a bias is added to produce the output z.

A worked example

Suppose a neuron has two inputs, x=[2,3]\mathbf{x} = [2, 3], with weights w=[0.5,βˆ’1]\mathbf{w} = [0.5, -1] and bias b=1b = 1. Then:

z=(0.5)(2)+(βˆ’1)(3)+1=1βˆ’3+1=βˆ’1z = (0.5)(2) + (-1)(3) + 1 = 1 - 3 + 1 = -1

The same calculation in code:

# the inputs to the neuron
x = [2.0, 3.0]
# one weight per input
w = [0.5, -1.0]
# a single bias term
b = 1.0

# multiply each input by its weight, sum them, then add the bias
z = sum(w_i * x_i for w_i, x_i in zip(w, x)) + b

print(z)  # -1.0

That is the entire computation of one neuron. Notice the output zz can be any number, large, small, positive, or negative, because nothing yet limits its range.

In the next lesson, we will pass zz through an activation function so that neurons stacked together can do more than draw a single straight line.