Spiking neurons vs artificial neurons
Real neurons talk in brief electrical spikes over time. Neurons in most AI models pass smooth numbers. Build a simple spiking neuron and see the difference.
In 60 seconds
Spiking neurons vs artificial neurons
Real neurons talk in brief electrical spikes over time. Neurons in most AI models pass smooth numbers. Build a simple spiking neuron and see the difference.
The artificial neuron
import numpy as np
x = np.array([0.5, 0.2, 0.9]) # inputs
w = np.array([0.8, -0.4, 0.3]) # weights (learned in training)
b = 0.1 # bias
total = x @ w + b
output = max(0.0, total) # "ReLU": keep positive values
print("total =", round(total, 3), "-> output =", round(output, 3))The spiking neuron
- Integrate: add up input over time, like water filling the bucket.
- Leaky: the voltage slowly drifts back to rest, like the hole in the bucket.
- Fire: when the voltage reaches the threshold, record a spike and reset.
Side by side
| Artificial neuron (most AI) | Spiking neuron (brains, LIF model) | |
|---|---|---|
| Output | A number, every time | Spikes at certain moments, often none |
| Time | Usually no built-in sense of time | Voltage changes over time; timing matters |
| Activity | Every neuron computes for every input | Most neurons are quiet most of the time |
| Learning | Weights trained with backpropagation | Brains change synapses in many ways, still being studied |
| Hardware | Runs very well on GPUs | Suits event-driven neuromorphic chips (lesson 7) |
A key behaviour: the firing threshold
Watch and read more
Lab
A working leaky integrate-and-fire neuron in numpy, its firing threshold behaviour, and the smallest steady input that makes it spike.
The problem
This runs in your browser.
- Run the starter. It simulates the voltage of a neuron with a steady input
I(in millivolts), but the "fire" part is missing, so it never spikes. - In
simulate_lif, add the fire rule: whenV >= V_TH, record the time inspikesand resetVtoV_RESET. - Run it for inputs 10, 20 and 40. Note how many spikes each gives in 200 ms.
- Find the smallest steady input (to about 0.5) that gives at least one spike, and store it in
rheobase. You can search with a loop. - Write one sentence explaining why input 10 gives no spikes.
Practice lab
Edit the code and run it. Python runs in your browser — nothing is sent to our server.
No output. Add print(...) to see values.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1Why is the smallest input that spikes close to 15 in this model? Use the numbers.Reveal
With a steady input I, the voltage settles where the leak cancels the input: at V_REST + I. The neuron can only fire if that level reaches the threshold, so -70 + I >= -55, which gives I >= 15. Just above 15 it takes a long time to get there, so in a 200 ms run the smallest input that spikes is a tiny bit above 15.
Q2Real neurons cannot fire again immediately after a spike. How would you add this "refractory period" to the model, and what would it change?Reveal
Keep a counter: after each spike, hold V at V_RESET and ignore input for a few milliseconds before integrating again. This puts a ceiling on the firing rate: even a huge input cannot make the neuron fire faster than once per refractory period plus the time to climb to threshold. Without it, the LIF model can fire unrealistically fast for very large inputs.
Questions people ask
Were artificial neurons copied from real ones?
They were inspired by real neurons many decades ago, but they are far simpler. Modern AI models are shaped much more by maths and computer hardware than by biology.
Can spiking networks learn like normal AI networks?
Researchers train spiking networks with several methods, including adapted versions of the methods used for normal networks. It is an active research area, and spiking networks are generally harder to train today.
Is the LIF model how real neurons really work?
It captures the main idea, but real neurons are much richer. They have branches that process input, many kinds of ion channels, and many types of synapses. Scientists choose simple or detailed models depending on the question.
What units are the numbers in the lab?
Voltages in millivolts and time in milliseconds, with values in a typical textbook range. The input is written directly in millivolts to keep the maths simple. It is a teaching model, not a measurement of a real neuron.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.