11. Discrete Probabilistic Demand
Earlier lessons often assumed Normal demand, then introduced gamma as a continuous alternative. Those parametric families are convenient, but they can misrepresent a custom sales history.
This lesson builds a tailor-fitted discrete demand model from observations: start with histograms and their limits, improve with kernel density estimation (KDE), then discretize the smooth density into a probability mass function (PMF) suitable for simulation and later policy optimization.
Original teaching rewrite for this course. Numeric drills use synthetic samples; they mirror the chapter workflow without reprinting a commercial dataset or textbook figures.
Why leave parametric densities?
A Normal or gamma model forces a fixed shape. Histograms and KDEs instead estimate density from the data, then compress the result onto integer demand values. The next chapter in the track uses such a custom PMF inside simulation-based policy search.
Histograms as a first density estimate
A histogram splits the observed range into bins. Each bin’s height is the fraction (or count) of observations that fall inside it. A common inventory shortcut treats that frequency as a point mass at the bin center.
How a histogram is built
- Choose left and right edges of the support.
- Divide that interval into bins.
- Count observations in each bin and convert counts to frequencies.
- Optionally assign each frequency to the bin midpoint.
That yields a crude discrete distribution—but only at the midpoints.
Four histogram limitations
- Sparse support. Probability lives only on bin centers (e.g. 21.7% at 1375 and 0% at 1376).
- Arbitrary bin count. Changing changes the shape of the estimated density.
- Arbitrary edges. Shifting the left/right limits reshapes the same sample into a different “distribution.”
- Not smooth. Adjacent bins can jump abruptly even when the true process is gradual.
Histograms remain useful for exploration. They are a weak default for a simulation PMF.
Kernel density estimation
Kernel density estimation places a small probability kernel around every observation, then sums and normalizes those kernels. You no longer choose bin edges or a bin count; each point gets its own local contribution.
Kernel: a probability density used to spread mass around one observation.
Bandwidth: the width of that kernel (for a Gaussian kernel, its standard deviation).
Box (squared) kernel
A box kernel spreads equal density on an interval of width equal to the bandwidth centered at each observation. Overlapping boxes add. The result is continuous in the support sense (every nearby real value gets mass) but not smooth—edges of the boxes create flat stretches and abrupt slopes.
Bandwidth still matters: a narrow box is jagged; a wide box oversmooths multimodal structure.
Gaussian kernel
A Normal kernel around each point yields a smooth density. The estimated PDF at is the average of Normal densities centered at the observations (scaled so the whole curve integrates to 1).
Larger bandwidth → smoother, flatter estimate. Smaller bandwidth → more peaks that hug the sample.
Choosing bandwidth: Scott and Silverman
With observations and sample standard deviation :
Both are rules of thumb. Scott’s rule often undersmooths less aggressively than intuition wants in the other direction: in practice it can look too smooth (underfit). A common heuristic is to use about when the Scott curve looks too loose.
KDE support extends slightly beyond the sample min and max—which is desirable: never observing 1902 does not prove .
Near-zero demand: Gaussian kernels can leak probability onto negative demand. Fold that mass onto 0 when building a PMF (below).
Practical SciPy sketch
scipy.stats.gaussian_kde(data, bw_method=...) accepts 'scott', 'silverman', or a scalar factor times . The object exposes .pdf(x). SciPy does not ship a vectorized KDE .cdf; integrate one point at a time, e.g. integrate_box_1d(-inf, x), or build your own loop.
From continuous KDE to a discrete PMF
Simulation engines need a finite integer domain and a PMF that sums to 1. Continuous KDE lives on in theory, so truncate thoughtfully.
Bounds from the sample and bandwidth
With safety factor (often 3 or 4):
For a single Normal kernel, , so mass below from the lowest observation’s kernel is tiny; across kernels the tail is still small if other kernels sit higher. Floor and ceil for a conservative integer grid.
Then take domain (or through , consistently), evaluate the KDE PDF on , and normalize:
Sampling: numpy.random.choice(x, size=..., p=pmf).
Fold negative demand to zero
If any carry mass:
- Add onto the probability at .
- Drop all negative support from and
pmf.
Mean and variance from a PMF
Independence reminder
A good per-period fit does not automatically describe lead-time demand. Autocorrelation (high after high, or high after low) breaks the independent-period assumption. When dependence matters, simulate demand over the risk period as a path, not as i.i.d. draws of one-period PMFs.
Recap path
- Prefer KDE over raw histograms when you need a custom density.
- Use a Gaussian kernel for smoothness; set bandwidth with Scott/Silverman (or a tuned fraction of Scott).
- Truncate with and , evaluate PDF on integers, normalize to a PMF.
- Clamp negative mass to 0; report and from the discrete support.
- Feed that PMF into simulation / policy search (next lessons).
Practice
Concept check
Histograms, KDE, and discrete PMFs
1 / 5Which is a core limitation of using a histogram as an inventory demand PMF?
Pick an answer to see if you are right.
Rank the KDE → PMF workflow
Build a custom discrete demand PMF
1 / 1You have a cleaned one-period demand sample and want an integer PMF for simulation.
OrderDrag the handle to rearrange — top should be first.
- 1If needed, fold negative mass onto 0 and compute μ_d, σ_d from the final PMF.
- 2Set integer bounds with sample min/max ± m · bandwidth and evaluate the PDF on that grid.
- 3Choose a bandwidth (Scott, Silverman, or a tuned fraction of Scott).
- 4Fit the Gaussian KDE on the observations with the chosen bandwidth.
- 5Normalize the evaluated PDF values so the discrete probabilities sum to 1.
Drag items into the correct order (or use ↑↓), then check.
Code: Scott bandwidth and truncation bounds
Implement Scott’s rule and the integer domain bounds used before discretizing a KDE.
Code: normalize PDF weights, then moments and clamp
First turn raw nonnegative weights into a PMF. Then compute mean/SD and fold negative support onto zero.
Takeaways
- Histograms need arbitrary bins and edges; they put mass only on midpoints and stay jagged.
- Gaussian KDE places a Normal kernel on each observation; bandwidth (Scott/Silverman or a tuned fraction) controls smoothness.
- Discretize by truncating with / , evaluating the PDF on integers, and normalizing.
- Fold negative KDE mass onto 0 for operational demand.
- PMF moments follow from and ; check independence before stacking periods.
Previous: Newsvendor Model.
Next: Simulation Optimization — search inventory policies when closed forms fail.