A Neuron Is a Weighted Vote
Calculate a weighted sum and threshold decision, then connect it to the neurons used in a network.
Build one numerical decision
This optional reading builds the single unit that neural networks are made of. The stages use the Neurons blocks: in this article's editor, choose the Neurons group in Add blocks.
Imagine a toy decision about attending an outdoor event. Encode three inputs as numbers: a friend is going, the event is nearby, and rain is forecast. Use 1 for yes and 0 for no. These encodings are choices you must define before calculating anything.
Choose weights 0.6, 0.3, and -0.4. Multiply each input by its matching weight and add the products. For inputs [1, 1, 0], the total is 1×0.6 + 1×0.3 + 0×(-0.4) = 0.9. With a threshold of 0.5, the neuron fires because 0.9 is at least 0.5.
For [1, 0, 1], the total is 0.6 + 0 - 0.4 = 0.2, so it does not fire. The negative rain weight reduces the total. The magnitude of a weight only makes sense alongside the input's scale.
Build with me · 1
Name the meaning of each input position
A vector is an ordered list of values. Position matters because each position will be multiplied by its corresponding weight. Here [1, 1, 0] means a friend is going, the event is nearby, and rain is not forecast.
The computer sees numbers; your data contract supplies their meanings. Swapping rain and friend would change the decision while still producing a perfectly valid numerical calculation.
Store a three-item list under features and label its output with the intended order.
What to look for
The printed input is [1, 1, 0].
Make it yours
Choose a different fictional scenario and encode it in the same order.
Build with me · 2
Give each input a weight and choose a threshold
The weights are 0.6, 0.3, and -0.4. Positive contributions support activation; the negative rain contribution opposes it. The threshold 0.5 is the bar the total must reach.
This is a manually designed threshold neuron. We have not trained these numbers or claimed that hard thresholding is how every modern network unit works.
Create decision with a list-of-weights value and threshold 0.5. Keep three weights for three input features.
What to look for
The report shows the three weights and the 0.5 threshold.
Make it yours
Explain why a negative weight is different from a feature being absent, whose value is zero.
Build with me · 3
Multiply corresponding values and add them
The products are 1 × 0.6, 1 × 0.3, and 0 × -0.4. They sum to 0.9. The third feature contributes zero because no rain was encoded, even though its weight is negative.
A weighted sum is a number, not yet the final yes/no decision. Keep that intermediate value visible before applying the threshold.
Put the input list in weighted total of decision, then put that value in labelled output.
What to look for
Weighted total is 0.9.
Make it yours
Calculate the total for [1, 0, 1] by hand before changing the input.
Build with me · 4
Compare the sum with its boundary
The neuron fires when its total is greater than or equal to 0.5. Since 0.9 reaches that threshold, the result is True. Equality is included by this implementation.
The activation turns the weighted total into a particular kind of output. A hard threshold returns a Boolean, while other activations can preserve a range of numerical values.
Print both total and fires for exactly the same input list.
What to look for
Total is 0.9 and Fires is True.
Make it yours
Change the threshold to 0.9 and confirm the equality case, then try 1.0.
Build with me · 5
Inspect how one feature can oppose activation
With friend present and rain absent, the total is 0.6. Turning rain on contributes -0.4, reducing the total to 0.2. That falls below 0.5, so this manually chosen decision no longer fires.
The sign of the contribution comes from both the input and weight. Here the input is positive one, yet its contribution is negative because the weight is negative.
Compare the two lists while keeping all weights and the threshold fixed.
What to look for
Totals are 0.6 and 0.2, and the rain case does not fire.
Make it yours
Set the rain weight to zero. Predict which of these two totals would change and why the distinction would disappear.
Threshold and bias
Comparing a total with threshold t can be rewritten as checking whether weighted sum - t is at least zero. The extra constant is a bias. In this hard-threshold form, bias equals negative threshold.
In a neural-network layer, each unit normally computes a weighted sum plus bias, then applies an activation function. A hard threshold returns yes or no. ReLU, used later, returns zero for a negative input and otherwise leaves the value unchanged. A sigmoid produces a value between zero and one. These functions have different behaviours and training implications.
The block above is therefore a simplified neuron you can inspect, not a complete replica of every unit inside a language or image model.
Build with me · 6
Rewrite a threshold as a bias
Comparing sum with threshold is equivalent to subtracting the threshold and comparing with zero. For a threshold of 0.5, the bias in this form is -0.5. The total 0.9 becomes 0.4 after adding that bias.
A neural-network unit commonly computes a weighted sum plus bias before an activation. This algebra connects the inspectable teaching block to that more general notation.
Store the weighted total, subtract 0.5, and compare the result with zero.
What to look for
Sum minus threshold is 0.4, and At least zero is True.
Make it yours
Check the same rewrite for total 0.2 and explain why both versions give the same false decision.
Check several inputs with one fixed set of weights
Keep the feature order friend, nearby, rain, and use the same weights and threshold throughout. Multiplication happens separately for each feature, then addition combines the contributions.
| Inputs | Friend contribution | Nearby contribution | Rain contribution | Total | Fires at 0.5? |
|---|---|---|---|---|---|
| [0, 1, 0] | 0 | 0.3 | 0 | 0.3 | No |
| [1, 0, 0] | 0.6 | 0 | 0 | 0.6 | Yes |
| [0, 1, 1] | 0 | 0.3 | -0.4 | -0.1 | No |
| [0, 0, 1] | 0 | 0 | -0.4 | -0.4 | No |
In the third row, nearby contributes positive 0.3 while rain contributes negative 0.4. Their sum is negative 0.1, below the threshold. Do not discard a negative contribution just because the feature itself is encoded as positive one. The sign comes from its weight.
If you accidentally supply rain before friend, the same numbers multiply the wrong weights. The block can execute without knowing that your feature meanings moved. Keep feature names and order beside the model, just as you do for CSV columns and digit pixels.
Build with me · 7
Inspect a batch with fixed weights
These four cases use one fixed neuron. Their totals are 0.3, 0.6, -0.1, and -0.4. Only 0.6 reaches the threshold. A loop lets you inspect each case without reconstructing the weights between them.
Testing a set of deliberate cases is stronger than showing only the one positive example that motivated your weights. You can see which features help, oppose, or contribute nothing.
Build the list of input lists, then print input, total, and fires inside for each.
What to look for
Only [1, 0, 0] fires among these four supplied cases.
Make it yours
Add [0, 0, 0] and predict its result. Explain why zero inputs with this threshold do not fire.
Manual design versus learning
We selected these weights to illustrate arithmetic. Nothing in the example proves they represent a person's real preferences. During model training, an algorithm adjusts weights and biases based on examples and a loss. The training process needs a differentiable or otherwise suitable model formulation; a raw hard threshold is not the usual unit trained by ordinary backpropagation.
You have understood this article when you can calculate one total, explain the contribution of a negative weight, and distinguish the weighted sum from the activation applied afterward. The next article combines several such computations.
Build with me · 8
Connect the numerical result to an application response
This final stack stores the activation before choosing a message. The weighted sum, activation, and response remain separate operations. In an actual learned model, training would choose suitable parameters from examples and a loss.
Practical neural networks often use ReLU, sigmoid, or other activations compatible with their learning procedure, rather than training a raw hard threshold by ordinary backpropagation. The small block is a transparent arithmetic model, not a complete replica of all neural units.
Choose your fictional input list, inspect the total, and read the activation-driven response. Compare your construction with the collapsed reference only after tracing it.
What to look for
The supplied [1, 0, 1] totals 0.2 and gives the nonfiring message.
Make it yours
Explain the difference between changing a weight, changing a threshold, and supplying a different input.
Full reference solution
This is the complete worked program. Try building it yourself first, then use this reference to find the first place your version behaves differently. The Python below is generated from these exact blocks; helper functions are included so its behaviour can be inspected.
# ---------------------------------------------------------------# Building blocks, written out in plain Python.# This part is generated for you. Your script starts further down.# --------------------------------------------------------------- class Neuron: """A weighted vote. Multiply each input by how much it counts, add it all up, and fire only if the total clears the bar.""" def __init__(self, weights=None, threshold=0.0, name="neuron"): self.weights = [float(w) for w in (weights or [])] self.threshold = float(threshold) self.name = name def total(self, inputs): values = inputs if isinstance(inputs, (list, tuple)) else [inputs] total = 0.0 for i in range(min(len(values), len(self.weights))): total += float(values[i]) * self.weights[i] return round(total, 4) def fires(self, inputs): return self.total(inputs) >= self.threshold def show(self): print( self.name + ": weights " + str(self.weights) + ", fires at " + str(self.threshold) + " or more" ) def new_neuron(weights=None, threshold=0.0, name="neuron"): return Neuron(weights, threshold, name) # ---------------------------------------------------------------# Your script# --------------------------------------------------------------- decision = new_neuron([0.6, 0.3, -0.4], 0.5, "decision")features = [1, 0, 1]print("Weighted total", decision.total(features))activated = decision.fires(features)if activated: print("The toy decision fires")else: print("The toy decision does not fire")Compare this with your version. Different names and personal choices are fine when the program follows the same logic.
Keep your progress
Sign in and every reading, quiz, and exercise you finish is saved.