+10 XP

Why Neurons Are Noisy

Real neurons receive thousands of random inputs simultaneously. We model this with Gaussian noise: I(t) = i_mean + i_std × N(0,1) × √dt

np.random.normal() samples from a normal distribution: mean 0, std 1. Each call returns a different random number. Multiply by i_std to set the noise level, and by np.sqrt(dt) to keep noise mathematically consistent across step sizes.

np.random.seed(n) fixes the random sequence so you get the same result every run — essential for reproducible science. Same seed → same trace every time.

python
import numpy as np
import matplotlib.pyplot as plt
dt=1e-3; tau=20e-3; el=-60e-3; vr=-70e-3; vth=-50e-3
r=100e6; i_mean=25e-11; i_std=0.5e-11; t_max=150e-3
np.random.seed(2024)
v = el
seed(2024): same random sequence every run
t_list, v_list = [], []
for step in range(int(t_max/dt)):
    t = step * dt
    i_t = i_mean + i_std * np.random.normal() * np.sqrt(dt)
np.sqrt(dt) scales noise correctly for step size
    v = v + (dt/tau) * (el - v + r * i_t)
    if v >= vth:
        v = vr
    t_list.append(t*1000); v_list.append(v*1000)
fig, ax = plt.subplots(figsize=(8, 3))
ax.plot(t_list, v_list, color='#FF6B6B')
ax.axhline(y=-50, color='red', linestyle='--', alpha=0.5, label='Threshold')
ax.set_xlabel('Time (ms)'); ax.set_ylabel('V (mV)')
ax.set_title('LIF with Random Input'); ax.legend()
plt.show()

Spike times are now irregular — just like a real neuron's response to noisy synaptic input.