A tool for estimating a hidden state buried in noise with a swarm of weighted particles — the particle filter, or sequential Monte Carlo method. Change the particle count, the noise levels and the resampling scheme to watch the estimate error and the effective sample size respond in real time.
Parameters
Particle count
Number of samples representing the distribution. More gives accuracy at higher cost
Process noise σ_q
How much the state drifts randomly over time (model uncertainty)
Measurement noise σ_r
Noise on the sensor measurement. Larger means the measurement is less trustworthy
Time steps
Number of time instants the filter is run for (trajectory length)
Resampling scheme
How the particles are redistributed to fight weight degeneracy
Results
—
Estimate RMSE
—
Measurement-only RMSE
—
Final estimate error
—
Mean effective sample size ESS
—
Particle count
—
Estimate improvement (%)
—
State estimation animation — tracking the particle cloud
The bold curve is the true state, the scattered dots are the measurements, the second curve is the filter estimate. The vertical spray of small dots is the particle cloud at the current time, with brightness scaled by weight.
Each particle weight w_i is proportional to the Gaussian likelihood of the measurement y_t, and the normalised weighted mean is the state estimate x̂_t. σ_r is the standard deviation of the measurement noise.
$$\text{ESS}=\frac{1}{\sum_i w_i^2}$$
Effective sample size ESS. It equals the particle count when the weights are uniform and drops toward 1 when they concentrate on one particle. Resampling fights particle degeneracy when the ESS falls too low.
What is the Particle Filter Simulator?
🙋
I've heard the name "particle filter", but what does it actually do? If there are particles, is it a physics simulation?
🎓
Good question. They are not physics particles — they are particles for estimation. Say a robot wants to know its own position: the sensor readings are full of noise, so the true position is unknown. So you scatter many candidates, each one saying "maybe it's here". Each candidate is a particle. The spread of all the particles together represents the "probability distribution of the position" — that is the core idea of a particle filter.
🙋
Just holding a lot of candidates doesn't let you decide which one is right, though. How does it get closer to the true position?
🎓
That is where "weights" come in. Every time a new measurement arrives, each particle is scored by "how well it explains this measurement". A particle right on the measurement gets a large weight; one far off gets a small weight. The weight is the Gaussian likelihood w_i ∝ exp(−(y−x_i)²/(2σ_r²)). Take the weighted mean and that is the filter estimate. On the canvas above you can see the estimate curve tracking the true state far more smoothly than the scattered measurements.
🙋
Just assigning weights sounds easy. But there's a "resampling" parameter — what is that for?
🎓
That is the heart of the particle filter. If you keep multiplying weights, the weights of particles that disagree with the measurement keep shrinking toward zero. In the end all the weight piles onto a single particle. This is called "weight degeneracy". Resampling discards the low-weight particles and duplicates the high-weight ones, gathering the swarm back into "the most plausible place right now". Set the select on the left to "no resampling" and you'll see the ESS chart below crash toward 1.
🙋
The ESS chart really dropped sharply. With systematic resampling, though, it stays high while jittering. What am I looking at there?
🎓
That is the effective sample size, ESS = 1/Σw_i². It tells you how many equally weighted particles the weighted swarm is effectively worth. Just after resampling all particles are equally weighted, so the ESS jumps back up to the particle count. At the next step the weights skew again and it drops. That jitter is the proof of "degenerate, then rebuild" repeating. Once the ESS bottoms out and sticks near 1, the estimate stops improving.
🙋
I see. You also hear about the Kalman filter — how is it different from a particle filter?
🎓
Roughly speaking, the difference is "how the distribution is represented". A Kalman filter represents the distribution with one Gaussian — a mean and a covariance. For a linear, Gaussian system it is optimal and very light. But it cannot represent a multi-modal distribution like "in one of two places", and it loses accuracy under strong non-linearity. A particle filter represents the distribution with a cloud of samples, so it handles multi-modal, non-linear and non-Gaussian cases. The cost is being heavy in proportion to the particle count. That is why it is often used for "messy" problems like localisation and object tracking.
Frequently Asked Questions
A Kalman filter represents the state's probability distribution with a single Gaussian — a mean and a covariance — so it is optimal for linear, Gaussian systems but loses accuracy on non-linear, non-Gaussian ones. A particle filter represents the distribution with a cloud of many weighted samples (particles), so it can handle multi-modal distributions and non-linear dynamics. The price is a computational cost proportional to the particle count. In this tool you can vary the particle count and feel the trade-off between cost and accuracy.
Without resampling, the weights of particles that disagree with the measurement keep shrinking, until almost all the weight collapses onto a single particle (weight degeneracy). The effective sample size ESS then falls toward 1, the distribution is represented by just one point and the estimate stops improving. Resampling discards low-weight particles and duplicates high-weight ones, redistributing the swarm into the important region and restoring the ESS. Set the scheme to 'no resampling' in this tool to watch the ESS crash.
ESS = 1 / Σw_i² measures how many equally weighted particles the weighted swarm is effectively worth. When all particles share the same weight, the ESS equals the particle count; when the weight concentrates on one particle, the ESS drops to 1. A practical strategy is to resample only when the ESS falls below a threshold such as half the particle count, which avoids the loss of diversity (sample impoverishment) caused by unnecessary resampling.
More particles represent the probability distribution more finely, reducing the variance of the estimate and making it stable, but the cost grows in proportion to the particle count. A few hundred particles are often enough for a simple 1-D problem, while for a high-dimensional state the required count grows exponentially — the curse of dimensionality. In practice you raise the particle count within the affordable compute budget and check that the ESS does not collapse and that the estimate is stable.
Real-World Applications
Robot localisation (Monte Carlo localisation): Particle filters are used when a cleaning robot or autonomous vehicle estimates "where am I now" from only a map and noisy sensor data. Each particle represents a possible position and pose, and particles whose laser or camera observations match the map have their weights raised. A swarm that starts scattered across the whole room and converges around the true position as the robot moves is exactly the same idea as the cloud convergence in this tool.
Object tracking (visual tracking): Algorithms that keep following a person or car in a video also use particle filters. When the target is hidden behind another object, or several look-alike objects are present, the state distribution becomes multi-modal. Even in this situation, awkward for a Kalman filter that represents it with one Gaussian, a particle cloud can hold several candidates simultaneously and recover the correct one when the target re-emerges.
State-space models in finance and economics: Sequential Monte Carlo also shines in stochastic volatility models, which estimate a latent variable — such as the volatility of a stock price — that cannot be observed directly and changes over time, from an observed return series. Its flexibility in handling non-Gaussian distributions and non-linear models is highly valued.
Navigation and sensor fusion: Particle filters are also used for positioning in tunnels or indoors where GPS does not reach, and for fusing multiple sensors (inertial sensors plus a barometer plus a magnetometer). Even when the observation model is complex and non-linear, only the per-particle likelihood needs to be evaluated, which is a major practical advantage.
Common Misconceptions and Pitfalls
The biggest pitfall is assuming that adding particles always improves accuracy. Adding particles does reduce the variance of the estimate, but the cost grows in direct proportion to the particle count. More serious is the "curse of dimensionality": for a high-dimensional state, the number of particles needed to keep the same accuracy grows exponentially with the dimension. If you size the particle count with a 1-D intuition for a problem estimating 3-D position and pose at once, it will be hopelessly short and diverge. This tool is 1-D so a few hundred is enough, but in high dimensions techniques such as the auxiliary particle filter or Rao-Blackwellisation that keep the particle count down become essential.
Next is the belief that resampling must be done every step. While resampling fights weight degeneracy, it repeatedly duplicates high-weight particles, so it has a side effect of stealing particle diversity — "sample impoverishment". When the process noise is small, the duplicated particles barely move and the swarm collapses onto a handful of points. In practice "adaptive resampling", which resamples only when the ESS falls below a threshold such as half the particle count, is standard. A middle ground between this tool's "no resampling" and resampling every step is in fact often the best.
Finally, beware of the simplification that "the estimate is just the weighted mean". If the state distribution is unimodal and symmetric around the truth, the weighted mean is fine; but when the distribution is multi-modal — that is, "in A, or in B" — taking the mean produces a point halfway between A and B, "neither place", as the estimate. This is a typical failure when a tracked object is lost. When multi-modality is suspected you need a situation-aware summary instead of the mean, such as the maximum-weight particle (MAP estimate) or picking representatives by clustering.
How to Use
Set particle count (100–10,000) in nParticlesNum; more particles reduce estimation variance but increase computation cost.
Configure process noise (0.01–2.0) in processNoiseNum to model system dynamics uncertainty; measurement noise (0.1–5.0) in measNoiseNum to reflect sensor error magnitude.
Specify simulation steps (10–500) in stepsNum, then run the filter; monitor Estimate RMSE versus Measurement-only RMSE to quantify particle filter gain.
Worked Example
A thermal process control system tracking hidden temperature drift with noisy RTD readings. Set nParticlesNum=500, processNoiseNum=0.5 (system model uncertainty), measNoiseNum=1.2 (sensor noise σ), stepsNum=100. Results show Estimate RMSE=0.82°C versus Measurement-only RMSE=3.1°C, delivering 73% improvement. Mean ESS=240 particles indicates adequate resampling; if ESS drops below 50, increase nParticlesNum to 1000 to prevent filter degeneracy.
Practical Notes
Particle degeneracy occurs when few particles dominate; monitor Mean ESS—trigger resampling when it falls below 30% of nParticlesNum to maintain diversity in aerospace nav or robotics localization.
Process noise tuning is critical: underestimating (0.01) causes filter to ignore true dynamics; overestimating (2.0) inflates uncertainty. Start conservative, validate against offline batch smoothing results.
In GPS-denied navigation or chemical reactor state inference, Final estimate error under 2% indicates sufficient particle resolution; above 5% suggests increasing nParticlesNum or refining the process model.