You Want to Study Rare Disasters, but They Almost Never Happen.
*Free version*
You Want to Study Rare Disasters, but They Almost Never Happen. So Make Them Happen on Purpose — Then Correct for Cheating. By Hand.
You need to know how often a rare catastrophe strikes, but it is so rare you would wait a lifetime to see enough of them. Watching the real world is hopeless — disasters barely show up.
So you cheat: you rig a fake world where disasters are common, you study them there, and then you mathematically undo the cheating to get the true rare rate. It sounds impossible to cheat and still get the right answer.
We will do exactly that, with small numbers, by hand.
This trick — sample from a convenient fake distribution, then reweight to recover the true one — is called importance sampling, and it quietly powers an enormous amount of modern computation: estimating rare risks, training models, and the reweighting that sits at the heart of how systems learn from data collected under one policy and evaluate another.
It is almost always drowned in symbols. We will do it as honest bookkeeping.
The problem: the thing you care about almost never happens
Suppose a certain failure happens 1 percent of the time. One in a hundred. You want to know the average cost when things go, including these rare failures.
Here is the situation. Ninety-nine percent of the time, everything is normal and the cost is small — say a cost of 1. But 1 percent of the time, disaster strikes and the cost is enormous — say a cost of 1000. You want the true average cost across all events.
We can actually compute the true answer here, because we set it up, and we will use it to check our cheat later. The true average cost is each cost times how often it happens:
- normal: cost 1, happens 99 percent of the time, contributes 1 times 0.99, which is 0.99
- disaster: cost 1000, happens 1 percent of the time, contributes 1000 times 0.01, which is 10
- true average cost: 0.99 plus 10, which is 10.99
So the true average cost is about 11. And notice — almost all of it, the 10 out of 11, comes from the rare disaster. The thing that almost never happens is the thing that dominates the average.
That is exactly why rare events matter and exactly why they are maddening to study.
Now pretend we did not set this up and did not know the answer. We want to estimate the average cost by sampling — by drawing events and averaging their costs. The honest way is to sample from the real world.
Why the honest way is hopeless
Sample from reality and you almost only ever see normal events. Draw 100 events from the true world, and on average you get 99 normals and 1 disaster — maybe.
Often you get zero disasters in 100 draws, because 1 percent is rare. And the entire average hinges on the disaster, the one event you keep failing to see.
So your estimate swings wildly. In a batch where you happened to catch a disaster, your average leaps up. In a batch where you caught none, your average is about 1, completely missing the catastrophe that dominates the truth.
To pin down the rare event’s contribution by honest sampling, you would need to draw hundreds of thousands of events just to collect enough disasters to average them reliably.
That is the curse of rare-event estimation: the thing you most need to measure is the thing you least often see, so honest sampling is agonizingly slow.
We need to see more disasters. So we will build a world where disasters are common — and then pay for the lie.
Rig a world where the rare thing is common
Here is the move. Instead of sampling from the true world, where disaster is 1 percent, we sample from a fake world where disaster is, say, 50 percent.
A coin flip. In this rigged world, half of everything we draw is a disaster. Now we will see plenty of them, fast.
But obviously we cannot just average the costs from this rigged world — it is crawling with disasters that should be rare, so its average cost would be absurdly, falsely high.
We cheated, and a naive average would reflect the cheating. We have to correct for it.
The correction is the soul of importance sampling, and it is fair-minded. Every time we draw an event from the fake world, we ask: how much more, or less, likely was this event in the real world than in the fake world?
And we weight the event by that ratio — true chance divided by fake chance.
Think about what that ratio does. A disaster was 1 percent likely in the real world but 50 percent likely in the fake one.
So a disaster is over-represented in our fake samples — we are seeing it 50 times too often, roughly.
Its weight is its true chance divided by its fake chance: 0.01 divided by 0.50, which is 0.02.
We multiply each disaster’s contribution by 0.02 — we shrink it, hard, because we conjured far too many disasters and must discount them back down to their true rarity.
A normal event was 99 percent likely in the real world but only 50 percent likely in the fake one.
So normals are under-represented in our fake samples — we are seeing too few of them. Its weight is 0.99 divided by 0.50, which is 1.98.
We multiply each normal’s contribution by 1.98 — we inflate it, because we conjured too few normals and must boost them back up to their true commonness.
Over-sampled events get shrunk. Under-sampled events get boosted. The weights exactly undo the rigging.
The cheat, paid for, by hand
Let us draw from the fake world and reconstruct the true average.
In the fake world, disaster and normal are each 50 percent, so a clean batch is half and half. Take 100 fake draws: 50 disasters, 50 normals.
For each event, we take its real cost, and multiply by its importance weight (true chance divided by fake chance).
Disasters: there are 50 of them, each with cost 1000 and weight 0.02.
- each disaster’s weighted cost: 1000 times 0.02, which is 20
- total from disasters: 50 times 20, which is 1000
Normals: there are 50 of them, each with cost 1 and weight 1.98.
- each normal’s weighted cost: 1 times 1.98, which is 1.98
- total from normals: 50 times 1.98, which is 99
Now average over the 100 draws. Total weighted cost: 1000 plus 99, which is 1099. Divide by 100 draws: 1099 divided by 100, which is 10.99.
Ten point nine nine.
That is the true average cost — exactly the 10.99 we computed at the start from the real probabilities.
We sampled from a rigged world swarming with disasters, weighted each draw by how over- or under-represented it was, and recovered the true rare-world answer on the nose.
event | real cost | true chance | fake chance | weight = true/fake | weighted cost
---------|-----------|-------------|-------------|--------------------|---------------
disaster | 1000 | 0.01 | 0.50 | 0.01/0.50 = 0.02 | 1000 x 0.02 = 20
normal | 1 | 0.99 | 0.50 | 0.99/0.50 = 1.98 | 1 x 1.98 = 1.98
50 disasters x 20 = 1000
50 normals x 1.98 = 99
total 1099 over 100 draws = 10.99 (the true average)
And here is the payoff over the honest method: we got a stable, correct answer from just 100 draws, half of which were the disasters we cared about.
The honest sampler might have needed hundreds of thousands of draws to catch enough disasters to be this confident. By rigging the world toward the rare event and paying for the rigging with weights, we studied the rare thing efficiently — and still got the true rate.
Why this matters far beyond disasters
Swap the words and the trick is everywhere.
It is how rare risks get estimated — failures, defaults, extreme losses — when waiting for them in the wild is too slow: rig a simulation where they are common, then weight back to reality.
It is woven through how models are trained, wherever you must average something over a distribution you cannot easily draw from, so you draw from an easier one and reweight.
And it is the heart of a problem at the center of modern agent learning: you have data collected while following one strategy, and you want to know how a different strategy would have done.
You cannot rerun history under the new strategy. So you reweight the data you have — each past decision weighted by how likely the new strategy would have been to make it versus the old one — true chance over sampling chance, exactly our move.
That single idea, reweighting actions by the ratio of new-policy to old-policy probability, lets a system evaluate a strategy it never actually ran, from data gathered under a strategy it did. It is importance sampling wearing a different hat.
The danger the arithmetic whispers
There is a catch, and it hides in the weights. The trick works beautifully when the fake world is not too far from the real one.
But push them far apart and the weights explode. Suppose an event was almost impossible in your fake world — fake chance near zero — but not in the real world.
Its weight, true chance divided by a near-zero fake chance, becomes enormous. A single such event, multiplied by a giant weight, hijacks your whole estimate, and your average starts swinging wildly again — the very instability you were trying to escape.
So the fake world has to be chosen with care: it must make the rare thing common, yes, but it must still give every real possibility a fair chance of appearing, or the weights blow up.
This is the same shape of warning we keep meeting — dividing by a near-zero probability is where these methods go to die. The cheat is powerful only when the world you cheat with overlaps honestly with the world you care about.
What stays with me
What I find genuinely clever about importance sampling is its refusal to accept the world’s frequencies as a constraint.
The naive view says: rare things are rare, so studying them is slow, and there is nothing to be done.
Importance sampling says: the rarity is not a law I must obey while gathering data — it is just a number, and I can sample from whatever distribution is convenient, as long as I keep honest books and weight each draw by how much I distorted its frequency.
It separates “what is easy to sample” from “what is actually true,” and bridges them with a ratio. You get to study the world you wish you had, and still answer about the world you have.
There is a small, almost philosophical lesson in it. You are allowed to look where the light is good — to deliberately go where the interesting events are common, even if that is not how the world really is — provided you remember exactly how much you tilted the floor, and tilt your conclusions back by the same amount.
Cheating is fine if you keep perfect track of the cheat and undo it precisely. The weights are the conscience of the method.
So here is the question to leave you with. We avoid studying rare things — rare failures, rare successes, rare cases — because they almost never happen and the waiting is hopeless.
But importance sampling says you do not have to wait: you can manufacture a world where the rare thing is common, study it there, and weight your way back to the truth.
So the next time something important is too rare to observe honestly — could you build the rigged world where it is common, and do you trust yourself to keep the books well enough to undo the rigging exactly?
Source: importance sampling, a foundational Monte Carlo technique; in modern machine learning it underlies off-policy evaluation in reinforcement learning, where actions are reweighted by the ratio of target-policy to behavior-policy probabilities.
메타데이터
- post_id
- ca1f3a2a77f2
- slug
- you-want-to-study-rare-disasters-but-they-almost-never-happen-ca1f3a2a77f2
- url
- https://medium.com/data-science-collective/you-want-to-study-rare-disasters-but-they-almost-never-happen-ca1f3a2a77f2
- canonical_url
- https://medium.com/data-science-collective/you-want-to-study-rare-disasters-but-they-almost-never-happen-ca1f3a2a77f2
- author_url
- https://medium.com/@swarnenduiitb2020i
- status
- ok
- fetched_at
- 2026-07-14 06:46:45