MixtureDistribution[{w1,…,wn},{dist1,…,distn}]
represents a mixture distribution whose CDF is given as a sum of the CDFs of the component distributions disti, each with weight wi.
MixtureDistribution
MixtureDistribution[{w1,…,wn},{dist1,…,distn}]
represents a mixture distribution whose CDF is given as a sum of the CDFs of the component distributions disti, each with weight wi.
Details
- The cumulative distribution function for value
is proportional to
, where
is the CDF for disti. - The distributions disti need to be all continuous or all discrete, and have the same dimensionality.
- The weights wi can be any non-negative real numbers.
- MixtureDistribution can be used with such functions as Mean, CDF, and RandomVariate, etc.
Examples
open all close allBasic Examples (3)
Define a mixture of two continuous distributions:
𝒟 = MixtureDistribution[{2, 1}, {NormalDistribution[], NormalDistribution[2, 1 / 2]}];Plot[PDF[𝒟, x], {x, -3, 4}, Filling -> Axis]Define a mixture of two discrete distributions:
𝒟 = MixtureDistribution[{4, 3}, {PoissonDistribution[8], GeometricDistribution[0.3]}];DiscretePlot[PDF[𝒟, x], {x, 0, 12}, ExtentSize -> 1 / 2]Define a multivariate mixture:
𝒟 = MixtureDistribution[{3, 1}, {MultivariatePoissonDistribution[7, {9, 10}], MultivariatePoissonDistribution[2, {5, 4}]}];DiscretePlot3D[PDF[𝒟, {x, y}], {x, 0, 30}, {y, 0, 30}, ExtentSize -> Full]Scope (30)
Basic Uses (10)
A mixture with numeric weights:
𝒟 = MixtureDistribution[{5, 9}, {NormalDistribution[3, 2], NormalDistribution[1, 4]}];Cumulative distribution function:
CDF[𝒟, x]A mixture with symbolic weights:
𝒟 = MixtureDistribution[{a, b}, {NormalDistribution[3, 2], NormalDistribution[1, 4]}];PDF[𝒟, x]The weights control the contribution by each distribution:
𝒟[w_] := MixtureDistribution[{w, 1 - w}, {NormalDistribution[-1, 1 / 2], NormalDistribution[1, 1 / 2]}];Table[Plot[PDF[𝒟[w], x]//Evaluate, {x, -3, 3}, PlotLabel -> NumberForm[{w, 1 - w}, 2], Filling -> Axis, PlotRange -> {0, 0.8}], {w, 0., 1., 0.2}]Two univariate continuous distributions:
𝒟1 = NormalDistribution[1, 1 / 2];
𝒟2 = NormalDistribution[2, 1 / 6];
𝒟 = MixtureDistribution[{3 / 5, 2 / 5}, {𝒟1, 𝒟2}];The mixture combines the densities according to their weights:
PDF[𝒟, x] == 3 / 5 PDF[𝒟1, x] + 2 / 5PDF[𝒟2, x]Plot[{3 / 5 PDF[𝒟1, x], 2 / 5PDF[𝒟2, x], PDF[𝒟, x]}, {x, -1, 3}, Filling -> Axis]Two bivariate continuous distributions:
𝒟1 = BinormalDistribution[{1, 1}, {1, 1}, 1 / 2];
𝒟2 = BinormalDistribution[{3, 3}, {1, 1}, -1 / 2];
𝒟 = MixtureDistribution[{3 / 5, 2 / 5}, {𝒟1, 𝒟2}];The mixture combines the densities according to their weights:
PDF[𝒟, {x, y}] == 3 / 5 PDF[𝒟1, {x, y}] + 2 / 5PDF[𝒟2, {x, y}]{Plot3D[{3 / 5 PDF[𝒟1, {x, y}], 2 / 5PDF[𝒟2, {x, y}]}, {x, -1, 5}, {y, -1, 5}, Mesh -> None, Lighting -> "Neutral", PlotStyle -> Table[Lighter[ColorData[1, i], 0.5], {i, 2}], PlotPoints -> 35, PlotRange -> All], Plot3D[PDF[𝒟, {x, y}], {x, -1, 5}, {y, -1, 5}, PlotPoints -> 35, Mesh -> None, Lighting -> "Neutral", PlotStyle -> Lighter[ColorData[1, 3], 0.5]]}Two univariate discrete distributions:
𝒟 = MixtureDistribution[{w, 1 - w}, {NegativeBinomialDistribution[2, 0.2], NegativeBinomialDistribution[30, 0.6]}];PDF[𝒟, x]Plot a density function for different weights:
Table[DiscretePlot[PDF[𝒟, x]//Evaluate, {x, 0, 30}, ExtentSize -> 1 / 2, PlotLabel -> {w, 1 - w}], {w, {0.3, 0.5, 0.7}}]Mean[𝒟]//SimplifyVariance[𝒟]Two multivariate discrete distributions:
𝒟1 = MultivariatePoissonDistribution[5, {5, 4}];
𝒟2 = MultivariatePoissonDistribution[1, {2, 5}];
𝒟 = MixtureDistribution[{5, 4}, {𝒟1, 𝒟2}];{DiscretePlot3D[{5 / 9PDF[𝒟1, {x, y}], 4 / 9PDF[𝒟2, {x, y}]}, {x, 0, 15}, {y, 0, 15}, ExtentSize -> 0.5], DiscretePlot3D[PDF[𝒟, {x, y}], {x, 0, 15}, {y, 0, 15}, ExtentSize -> 0.5, PlotStyle -> ColorData[1, 3]]}Histogram3D[RandomVariate[𝒟, 10 ^ 4], {-0.5, 15.5, 1}, "PDF"]Several univariate continuous distributions:
ghosty𝒟 = MixtureDistribution[{1, 4, 1.5}, {NormalDistribution[-3, 1 / 2], NormalDistribution[], NormalDistribution[3, 2 / 3]}];Plot[PDF[ghosty𝒟, x], {x, -6, 6}, Filling -> Axis]Table[Moment[ghosty𝒟, i], {i, 6}]Table[FactorialMoment[ghosty𝒟, i], {i, 6}]Table[CentralMoment[ghosty𝒟, i], {i, 6}]Table[Cumulant[ghosty𝒟, i], {i, 6}]Several univariate discrete distributions:
𝒟 = MixtureDistribution[{2, 1, 4, 6}, {PoissonDistribution[3], PoissonDistribution[6], PoissonDistribution[11], PoissonDistribution[20]}];PDF[𝒟, x]//SimplifyDiscretePlot[PDF[𝒟, x], {x, 0, 30}, ExtentSize -> 1 / 2]CharacteristicFunction[𝒟, t]MomentGeneratingFunction[𝒟, t]CumulantGeneratingFunction[𝒟, t]FactorialMomentGeneratingFunction[𝒟, t]Estimate weights in a mixture:
𝒟 = MixtureDistribution[{a, b}, {NormalDistribution[], NormalDistribution[3, 1 / 2]}];sample = Block[{a = 1 / 4, b = 3 / 4}, RandomVariate[𝒟, 10 ^ 3]];EstimatedDistribution[sample, 𝒟]Parametric Distributions (5)
Define a mixture of two different continuous distributions:
𝒟 = MixtureDistribution[{1 / 3, 2 / 3}, {ChiSquareDistribution[18], ExponentialDistribution[1 / 14]}];Plot[PDF[𝒟, x], {x, 0, 50}, PlotRange -> {0, 0.06}, Filling -> Axis]PDF[𝒟, x]Plot[HazardFunction[𝒟, x], {x, 0, 60}, AxesOrigin -> {0, 0}, Filling -> Axis]In the limit the exponential distribution component dominates:
Limit[HazardFunction[𝒟, x], x -> ∞]HazardFunction[ExponentialDistribution[1 / 14], x]Define a mixture of two distributions with different supports:
𝒟 = MixtureDistribution[{a, 1}, {ExponentialDistribution[2], BetaDistribution[6, 3]}];Probability density function for a few values of the weight:
Table[Plot[PDF[𝒟, x]//Evaluate, {x, 0, 2}, Filling -> Axis, Exclusions -> None, PlotLabel -> {a, 1}], {a, {0.5, 1, 3}}]PDF[𝒟, x]Mean[𝒟]//SimplifyDefine a mixture of two different univariate discrete distributions:
𝒟 = MixtureDistribution[{1 / 2, 1 / 2}, {BernoulliDistribution[0.3], BinomialDistribution[8, 0.6]}];DiscretePlot[PDF[𝒟, x], {x, 0, 9}, ExtentSize -> 1 / 2]Cumulative distribution function:
DiscretePlot[CDF[𝒟, x], {x, 0, 8}, ExtentSize -> Right, ExtentMarkers -> {"Filled", "Empty"}, AxesOrigin -> {0, 0}]Moments can be obtained numerically:
{Moment[𝒟, 3], CentralMoment[𝒟, 4], Cumulant[𝒟, 2], FactorialMoment[𝒟, 5]}Define a mixture of two different multivariate discrete distributions:
𝒟 = MixtureDistribution[{2, 1}, {DiscreteUniformDistribution[{{0, 2}, {0, 2}}], MultivariateHypergeometricDistribution[8, {6, 5}]}];DiscretePlot3D[PDF[𝒟, {x, y}], {x, 0, 8}, {y, 0, 8}, ExtentSize -> 1 / 2]Covariance[𝒟]//MatrixFormDefine a mixture distribution of multivariate uniform distributions:
𝒟 = MixtureDistribution[{2, 1}, {UniformDistribution[{{2, 4}, {5, 7}}], UniformDistribution[{{5, 7}, {9, 11}}]}];Cumulative distribution function:
Plot3D[CDF[𝒟, {x, y}]//Evaluate, {x, 1, 9}, {y, 3, 13}, ColorFunction -> "Rainbow", Exclusions -> None]Nonparametric Distributions (3)
Define a mixture with SmoothKernelDistribution:
skd1 = SmoothKernelDistribution[RandomVariate[NormalDistribution[], 10 ^ 3]];
skd2 = SmoothKernelDistribution[RandomVariate[NormalDistribution[2, 1 / 2], 10 ^ 3]];
𝒟 = MixtureDistribution[{1, 2}, {skd1, skd2}];The mixture combines the densities according to their weights:
Plot[{1 / 3PDF[skd1, x], 2 / 3PDF[skd2, x], PDF[𝒟, x]}, {x, -3, 4}, PlotRange -> All, Filling -> Axis, PlotStyle -> {Automatic, Automatic, Thick}, PlotLegends -> {"skd1", "skd2", "𝒟"}]Define a mixture with EmpiricalDistribution:
ed1 = EmpiricalDistribution[RandomVariate[NormalDistribution[], 10]];
ed2 = EmpiricalDistribution[RandomVariate[NormalDistribution[1, 1 / 3], 10]];
𝒟 = MixtureDistribution[{2, 3}, {ed1, ed2}];The mixture combines the cumulative distribution functions according to their weights:
2 / 5CDF[ed1, x] + 3 / 5CDF[ed2, x] == CDF[𝒟, x]Plot the cumulative distribution function:
Plot[CDF[𝒟, x], {x, -2, 2}, Filling -> Axis, Exclusions -> None]Define a mixture with HistogramDistribution:
hd1 = HistogramDistribution[RandomVariate[NormalDistribution[], 10 ^ 3]];
hd2 = HistogramDistribution[RandomVariate[NormalDistribution[2, 1 / 2], 10 ^ 3]];
𝒟 = MixtureDistribution[{4, 6}, {hd1, hd2}];The mixture combines the densities according to their weights:
4 / 10PDF[hd1, x] + 6 / 10PDF[hd2, x] == PDF[𝒟, x]Plot[{4 / 10PDF[hd1, x], 6 / 10PDF[hd2, x], PDF[𝒟, x]}, {x, -3, 5}, Exclusions -> None, PlotRange -> All, Filling -> Axis, PlotStyle -> {Automatic, Automatic, Thick}, PlotLegends -> {"hd1", "hd2", "𝒟"}]Derived Distributions (10)
Define a mixture distribution with components given by MixtureDistribution:
ℳ1 = MixtureDistribution[{1, 2}, {GammaDistribution[2, 3], NormalDistribution[0, 1]}];
ℳ2 = MixtureDistribution[{3, 1}, {CauchyDistribution[0, 1 / 3], BetaDistribution[1 / 2, 1 / 3]}];
ℳ = MixtureDistribution[{2, 5}, {ℳ1, ℳ2}];Plot[PDF[ℳ, x], {x, -2, 2}, Filling -> Axis]The PDF is piecewise continuous:
PDF[ℳ, x]The mean is a convex combination of the means of the components:
Mean[ℳ]Find which components cause the mean of the mixture to be indeterminate:
Map[Mean, Flatten[{ℳ1, ℳ2}[[All, 2]]]]Find a mixture distribution of the OrderDistribution of the minimum and the maximum:
𝒟min = OrderDistribution[{NormalDistribution[], 10}, 1];
𝒟max = OrderDistribution[{NormalDistribution[], 10}, 10];
ℳ = MixtureDistribution[{1, 1}, {𝒟min, 𝒟max}];Compare the probability density functions:
Plot[{PDF[𝒟min, x], PDF[𝒟max, x], PDF[ℳ, x]}//Evaluate, {x, -4, 4}, Filling -> Axis, PlotLegends -> {"𝒟min", "𝒟max", "ℳ"}]The mean of the mixture distribution:
Mean[N[ℳ]]Compare to the average of the means of order distributions:
Mean[{Mean[𝒟min//N], Mean[𝒟max//N]}]Find the mixture distribution of a TruncatedDistribution:
𝒟1 = TruncatedDistribution[{-2, 3}, NormalDistribution[1 / 2, 1]];
𝒟2 = TruncatedDistribution[{1, 4}, NormalDistribution[0, 2]];
ℳ = MixtureDistribution[{3, 1}, {𝒟1, 𝒟2}];The probability density function is not continuous:
Plot[PDF[ℳ, x], {x, -3, 4}, Filling -> Axis]The mean can be computed explicitly:
Mean[ℳ]N[%]Find the probability density function of the mixture distribution with a ProductDistribution:
𝒟1 = BinormalDistribution[0.7];
𝒟2 = ProductDistribution[RayleighDistribution[1 / 2], ExponentialDistribution[1]];
ℳ = MixtureDistribution[{3, 1}, {𝒟1, 𝒟2}];Plot3D[PDF[ℳ, {x, y}], {x, -2, 3}, {y, -1, 2}, PlotRange -> All]Define a mixture distribution with a TransformedDistribution:
𝒯 = TransformedDistribution[u ^ 2, uGammaDistribution[2, 3]];
𝒟 = MixtureDistribution[{2, 3}, {𝒯, GammaDistribution[2, 3]}];Plot[PDF[𝒟, x]//Evaluate, {x, 0, 20}, Filling -> Axis]PDF[𝒟, x]Define a mixture distribution of a MarginalDistribution:
𝒹 = NegativeMultinomialDistribution[10, {1 / 2, 1 / 7}];
ℳ = MixtureDistribution[{2, 1}, {MarginalDistribution[𝒹, 1], MarginalDistribution[𝒹, 2]}];DiscretePlot[PDF[ℳ, x]//Evaluate, {x, 0, 22}]CharacteristicFunction[ℳ, t]Define a mixture with a CensoredDistribution:
𝒞 = CensoredDistribution[{5, 8}, PoissonDistribution[7]];
𝒟 = MixtureDistribution[{1 / 3, 2 / 3}, {𝒞, PoissonDistribution[7]}];DiscretePlot[PDF[𝒟, x]//Evaluate, {x, 0, 10}, ExtentSize -> 1 / 2]PDF[𝒟, x]A mixture with a ParameterMixtureDistribution:
𝒫 = ParameterMixtureDistribution[PoissonDistribution[μ], μGammaDistribution[2, 2 / 3]];
𝒟 = MixtureDistribution[{1, 2}, {𝒫, 𝒹 = BinomialDistribution[5, .7]}];PDFs of scaled mixture components and mixture distribution:
DiscretePlot[Evaluate[First[#]], {x, 0, 7}, ExtentSize -> 1 / 2, PlotLabel -> Last[#], ImageSize -> Small]& /@ {{{2 / 3PDF[𝒹, x], 1 / 3PDF[𝒫, x]}, "scaled 𝒹 and 𝒫"}, {PDF[𝒟, x], "𝒟"}}Define a mixture distribution with a CopulaDistribution:
𝒞 = CopulaDistribution[{"GumbelHougaard", 3}, {UniformDistribution[{0, 1}], UniformDistribution[{0, 1}]}];
𝒟 = MixtureDistribution[{5, 3}, {𝒞, BinormalDistribution[{0.5, 0.5}, {1 / 10, 1 / 10}, 0.4]}];Plot3D[PDF[𝒟, {x, y}]//Evaluate, {x, -0.2, 1.2}, {y, -0.2, 1.2}, PlotRange -> {0, 6}]Mean[𝒟]Variance[𝒟]Mixture of compatible QuantityDistribution evaluates to QuantityDistribution:
d = MixtureDistribution[{4, 1}, {QuantityDistribution[ExponentialDistribution[1], "Meters"], QuantityDistribution[NormalDistribution[2, 1], "Feet"]}]Mean[d]//NPlot the PDF:
Plot[PDF[d, Quantity[z, "Feet"]], {z, 0, 12}, Filling -> Axis, PlotRange -> All, AxesLabel -> {QuantityForm["Feet", "LongForm"]}]Automatic Simplifications (2)
One component mixture simplifies to the input distribution:
MixtureDistribution[{4}, {NormalDistribution[]}]A mixture with zero weights will reduce the number of input distributions:
MixtureDistribution[{1, 0, c}, {NormalDistribution[], ExponentialDistribution[λ], GammaDistribution[2, β]}]A mixture with one zero weight will return unevaluated:
MixtureDistribution[{0}, {BeniniDistribution[a, b, c]}]Applications (7)
Find the percentage of values between
and
:
𝒟 = MixtureDistribution[{3, 2}, {NormalDistribution[1, 1 / 2], NormalDistribution[2, 1 / 6]}];μ = Mean[𝒟];
σ = StandardDeviation[𝒟];
pdf = PDF[𝒟, x];Show[Plot[pdf, {x, -0.5, μ - σ}, Filling -> Axis], Plot[pdf, {x, μ - σ, μ + σ}], Plot[pdf, {x, μ + σ, 2.9}, Filling -> Axis], PlotRange -> All, Ticks -> {Automatic, None}]Probability[μ - σ < x < μ + σ, x𝒟]N[%]Probability[μ - 2σ < x < μ + 2σ, x𝒟]N[%]Package it up as a function using NProbability:
percentage[n_] := NProbability[μ - n σ < x < μ + n σ, x 𝒟]Table[percentage[n], {n, 3}]Determine the maximal variance of a mixture:
𝒟 = MixtureDistribution[{p, 1 - p}, {PoissonDistribution[2], PoissonDistribution[7]}];v = Variance[𝒟]Plot[v, {p, 0, 1}, PlotRange -> {0, 12}]Maximize[{v, 0 ≤ p ≤ 1}, p]The heights of females in the United States follow normal distribution with mean 64 inches and standard deviation of 2 inches, while the heights of males in the United States follow normal distribution with mean 70 inches and standard deviation of 2 inches. If the population ratio of males to females is 1.1, then the heights of the whole population have the following bimodal distribution:
height𝒟 = MixtureDistribution[{0.5238, 1 - 0.5238}, {NormalDistribution[Quantity[70, "Inches"], Quantity[2, "Inches"]], NormalDistribution[Quantity[64, "Inches"], Quantity[2, "Inches"]]}];Plot[PDF[height𝒟, Quantity[x, "Inches"]], {x, 50, 80}, Filling -> Axis, AxesLabel -> {"in"}]Simulate a typical distribution of heights in a town of population 100:
ListPlot[RandomVariate[height𝒟, 100], Filling -> Axis, AxesLabel -> Automatic]Find the probability that a person is at least 73 inches tall:
Probability[x ≥ Quantity[73, "Inches"], xheight𝒟]A binary transmission is sent with 0 coded as a
voltage signal and 1 as a
voltage signal. 1 is sent with probability
but the signal is corrupted by white noise. Find the PDF of the received signal:
𝒟 = MixtureDistribution[{p, 1 - p}, {NormalDistribution[v, 1], NormalDistribution[-v, 1]}];PDF[𝒟, x]Simulate transmission at the receiver for p=0.4 and v=1:
transmission = Block[{p = 0.4, v = 1}, RandomVariate[𝒟, 100]];ListPlot[{transmission, ConstantArray[-1, {100}], ConstantArray[1, {100}]}, Joined -> {False, True, True}, Filling -> {1 -> Axis}]To distinguish between the two signals, the voltage difference must be bigger:
transmission2 = Block[{p = 0.4, v = 5}, RandomVariate[𝒟, 100]];ListPlot[{transmission2, ConstantArray[-5, {100}], ConstantArray[5, {100}]}, Joined -> {False, True, True}, Filling -> {1 -> Axis}]MixtureDistribution can be used to create multimodal models:
ExampleData[{"Statistics", "USEarthquakes"}, "LongDescription"]magnitudes = Select[ExampleData[{"Statistics", "USEarthquakes"}], #[[1]] ≥ 1940&][[All, 7]];The magnitudes of earthquakes in the United States in the selected years have two modes:
h = Histogram[magnitudes, 20, "PDF"]Find an estimated distribution from possible mixtures of two normal distributions:
edist = EstimatedDistribution[magnitudes, MixtureDistribution[{p, 1 - p}, {NormalDistribution[a, b], NormalDistribution[c, d]}]]//QuietCompare the histogram to the PDF of the estimated distribution:
Show[h, Plot[PDF[edist, x], {x, 0, 10}, PlotStyle -> Thick, PlotRange -> All]]Find the probability of an earthquake of magnitude 7 or higher:
Probability[x ≥ 7, xedist]Find the mean earthquake magnitude:
Mean[edist]Simulate magnitudes of the next 30 earthquakes:
ListPlot[RandomVariate[edist, 30], Filling -> Axis]The average city and highway mileage for midsize cars follows a binormal distribution:
midsizeMPG2009 = QuantityArray[{{16, 22}, {18, 26}, {17, 25}, {16, 23}, {16, 23}, {14, 19}, {13, 19}, {10, 14}, {10, 17}, {18, 28}, {18, 27}, {17, 25}, {17, 25}, {17, 26}, {17, 26}, {16, 25}, {17, 25}, {15, 22}, {15, 23}, {11, 17}, {11, 17}, {17, 28}, {16, 24}, {16, 25}, {16, 25}, {17, 26}, {18, 26}, {17, 26}, {17, 25}, {17, 26}, {13, 19}, {15, 24}, {17, 26}, {15, 22}, {22, 33}, {22, 30}, {18, 29}, {17, 26}, {26, 34}, {21, 30}, {13, 20}, {19, 27}, {16, 27}, {21, 30}, {13, 20}, {19, 27}, {16, 27}, {24, 30}, {23, 27}, {23, 29}, {21, 25}, {19, 27}, {10, 15}, {9, 16}, {17, 25}, {20, 29}, {20, 28}, {18, 26}, {24, 33}, {25, 33}, {16, 25}, {15, 23}, {22, 32}, {22, 32}, {20, 28}, {23, 30}, {24, 32}, {19, 27}, {19, 26}, {18, 25}, {17, 24}, {16, 24}, {16, 23}, {16, 24}, {16, 23}, {20, 22}, {17, 25}, {20, 29}, {20, 28}, {18, 26}, {17, 24}, {18, 28}, {20, 29}, {21, 30}, {17, 25}, {18, 25}, {23, 32}, {17, 24}, {16, 22}, {15, 22}, {13, 19}, {13, 20}, {20, 27}, {16, 25}, {23, 32}, {23, 31}, {18, 27}, {19, 26}, {35, 33}, {19, 26}, {24, 30}, {21, 29}, {26, 31}, {27, 33}, {24, 32}, {11, 18}, {24, 30}, {24, 32}, {22, 33}, {17, 26}, {26, 34}, {21, 31}, {21, 31}, {19, 28}, {33, 34}, {48, 45}, {19, 29}, {15, 23}, {15, 22}, {16, 25}}, "Miles" / "Gallons"];edist = EstimatedDistribution[midsizeMPG2009, BinormalDistribution[{μ1, μ2}, {σ1, σ2}, ρ]]city𝒟 = MarginalDistribution[edist, 1];
hwy𝒟 = MarginalDistribution[edist, 2];Show the distribution of city and highway mileage:
Plot[{PDF[city𝒟, Quantity[x, "Miles" / "Gallons"]], PDF[hwy𝒟, Quantity[x, "Miles" / "Gallons"]]}, {x, 10, 40}, Filling -> Axis, PlotLegends -> {"city", "highway"}, AxesLabel -> {"mi/gal"}]Assuming 65% of the driving is done in the city, the mileage follows a MixtureDistribution:
mixedMPG = MixtureDistribution[{.65, .35}, {city𝒟, hwy𝒟}];Plot[PDF[mixedMPG, Quantity[x, "Miles" / "Gallons"]], {x, 10, 40}, Filling -> Axis, AxesLabel -> {"mi/gal"}]Mean[mixedMPG]Gaussian mixture model is commonly used for the purpose of image segmentation. Image is represented as an array of pixels. A pixel is a scalar (or vector) which shows the intensity (or color):
pic = ExampleData[{"TestImage", "Aerial"}]Visualize the distribution of pixel values via Histogram:
pixels = Flatten[ImageData[pic]];
Histogram[pixels]Fit the pixel values to a three-component Gaussian mixture with EstimatedDistribution:
gmm = Quiet@EstimatedDistribution[pixels, MixtureDistribution[{p1, p2, p3}, {NormalDistribution[a1, a2], NormalDistribution[b1, b2], NormalDistribution[c1, c2]}]];Label each pixel with maximum a posterior probability (MAP) estimate:
pxi = Table[PDF[dist, pixels], {dist, Last[gmm]}];
labels = ArrayReshape[Ordering[#, -1]& /@ (Transpose[pxi] / Total[pxi First[gmm]]), ImageDimensions[pic]];Image[0.5 (labels - 1)]Properties & Relations (8)
A mixture with weights w is equivalent to one with weights w/Total[w]:
w = {a, b};
components = {NormalDistribution[Subscript[μ, 1], Subscript[σ, 1]], NormalDistribution[Subscript[μ, 2], Subscript[σ, 2]]};𝒟1 = MixtureDistribution[w, components];
𝒟2 = MixtureDistribution[w / Total[w], components];{PDF[𝒟1, x], PDF[𝒟2, x]}//FullSimplifyPDF[𝒟1, x] - PDF[𝒟2, x]//FullSimplifyThe PDF of a mixture is a convex combination of the PDF of its components:
𝒟 = MixtureDistribution[{a, b}, {NormalDistribution[Subscript[μ, 1], Subscript[σ, 1]], NormalDistribution[Subscript[μ, 2], Subscript[σ, 2]]}];PDF[𝒟, x]% - (a / (a + b)PDF[NormalDistribution[Subscript[μ, 1], Subscript[σ, 1]], x] + b / (a + b)PDF[NormalDistribution[Subscript[μ, 2], Subscript[σ, 2]], x])The CDF of a mixture is a convex combination of the CDF of its components:
𝒟 = MixtureDistribution[{a, b}, {NormalDistribution[Subscript[μ, 1], Subscript[σ, 1]], NormalDistribution[Subscript[μ, 2], Subscript[σ, 2]]}];CDF[𝒟, x]% - (a / (a + b)CDF[NormalDistribution[Subscript[μ, 1], Subscript[σ, 1]], x] + b / (a + b)CDF[NormalDistribution[Subscript[μ, 2], Subscript[σ, 2]], x])The moments of a mixture are a convex combination of the moments of its components:
𝒟 = MixtureDistribution[{a, b}, {NormalDistribution[Subscript[μ, 1], Subscript[σ, 1]], NormalDistribution[Subscript[μ, 2], Subscript[σ, 2]]}];Mean[𝒟]% - (a / (a + b)Mean[NormalDistribution[Subscript[μ, 1], Subscript[σ, 1]]] + b / (a + b)Mean[NormalDistribution[Subscript[μ, 2], Subscript[σ, 2]]])//SimplifyMoment[𝒟, r]//FullSimplify% - (a / (a + b)Moment[NormalDistribution[Subscript[μ, 1], Subscript[σ, 1]], r] + b / (a + b)Moment[NormalDistribution[Subscript[μ, 2], Subscript[σ, 2]], r])//SimplifyA ParameterMixtureDistribution with a discrete weight, assuming a finite number of values, can be represented as a mixture distribution:
𝒟1 = ParameterMixtureDistribution[ErlangDistribution[k + 1, λ], kBinomialDistribution[3, p]];weights = Table[PDF[BinomialDistribution[3, p], k], {k, 0, 3}];
dists = Table[ErlangDistribution[k + 1, λ], {k, 0, 3}];
𝒟2 = MixtureDistribution[weights, dists];PDF[𝒟1, x]//FullSimplifyPDF[𝒟2, x]//FullSimplify% - %%A ParameterMixtureDistribution with a discrete weight, assuming a countable number of values, can be approximated by a mixture distribution:
𝒟1 = ParameterMixtureDistribution[ErlangDistribution[k + 1, λ], kPoissonDistribution[μ]];weights[q_] := Table[PDF[PoissonDistribution[μ], k], {k, 0, Quantile[PoissonDistribution[μ], q]}];
dists[q_] := Table[ErlangDistribution[k + 1, λ], {k, 0, Quantile[PoissonDistribution[μ], q]}];
𝒟2[q_] := MixtureDistribution[weights[q], dists[q]];Compare approximations for different quantiles as cut-offs:
Legended[Block[{μ = 9, λ = 2}, Table[Plot[{PDF[𝒟1, x], PDF[𝒟2[q], x]}//Evaluate, {x, 0, 15}, PlotLabel -> Row[{"q = ", q}]], {q, {0.8, 0.9, 0.95, .99}}]], Placed[LineLegend[97, {"𝒟1", "𝒟2"}, LegendLayout -> "Row"], Below]]Approximating a ParameterMixtureDistribution with a continuous weight by a mixture distribution:
weight𝒟 = WeibullDistribution[1.5, 3];
Plot[PDF[weight𝒟, x], {x, 0, 10}]𝒟1 = ParameterMixtureDistribution[NormalDistribution[0, λ], λweight𝒟];
pdf1 = PDF[𝒟1, x];weights[q_] := Table[PDF[weight𝒟, λ], {λ, Quantile[weight𝒟, q], Quantile[weight𝒟, 1 - q], 0.2}]
dists[q_] := Table[NormalDistribution[0, λ], {λ, Quantile[weight𝒟, q], Quantile[weight𝒟, 1 - q], 0.2}]
𝒟2[q_] := MixtureDistribution[weights[q], dists[q]]Legended[Table[Plot[{pdf1, PDF[𝒟2[q], x]}//Evaluate, {x, -3, 3}, PlotRange -> All, PlotLabel -> Row[{"q = ", q}]], {q, {0.1, 0.05, .01}}], Placed[LineLegend[97, {"𝒟1", "𝒟2"}, LegendLayout -> "Row"], Below]]A KernelMixtureDistribution is a MixtureDistribution derived from data:
data = RandomVariate[NormalDistribution[], 5];𝒟KMD = KernelMixtureDistribution[data, bw = 1 / 3];𝒟MD = MixtureDistribution[ConstantArray[1 / 5, 5], Table[NormalDistribution[i, bw], {i, data}]];Table[Plot[PDF[𝒟, x], {x, -4, 4}, PlotRange -> All, Filling -> Axis, ImageSize -> Small], {𝒟, {𝒟KMD, 𝒟MD}}]Neat Examples (3)
A mixture of two binormal distributions:
𝒟1 = BinormalDistribution[{1, 1}, {1, 1}, 1 / 2];
𝒟2 = BinormalDistribution[{3, 3}, {1, 1}, -1 / 2];
𝒟 = MixtureDistribution[{3 / 5, 2 / 5}, {𝒟1, 𝒟2}];
Plot3D[{3 / 5 PDF[𝒟1, {x, y}], 2 / 5PDF[𝒟2, {x, y}], PDF[𝒟, {x, y}]}, {x, -1, 5}, {y, -1, 5}, MeshFunctions -> {#3&}, MeshShading -> {Automatic, None}, PlotStyle -> Table[Lighter[ColorData[1, i], 0.5], {i, 3}], PlotPoints -> 35]A variety of distributional shapes from Gaussian mixtures:
Gaussian = NormalDistribution[];
SkewedUnimodal = MixtureDistribution[{1 / 5, 1 / 5, 3 / 5}, {NormalDistribution[], NormalDistribution[1 / 2, 2 / 3], NormalDistribution[13 / 12, 5 / 9]}];
StrongSkew = MixtureDistribution[ConstantArray[1 / 8, 8], Table[NormalDistribution[3((2 / 3) ^ i - 1), (2 / 3) ^ i], {i, 0, 7}]];
KurtoticUnimodal = MixtureDistribution[{2 / 3, 1 / 3}, {NormalDistribution[], NormalDistribution[0, 1 / 10]}];
Outlier = MixtureDistribution[{1 / 10, 9 / 10}, {NormalDistribution[], NormalDistribution[0, 1 / 10]}];
Bimodal = MixtureDistribution[{1 / 2, 1 / 2}, {NormalDistribution[-1, 2 / 3], NormalDistribution[1, 2 / 3]}];
SeparatedBimodal = MixtureDistribution[{1 / 2, 1 / 2}, {NormalDistribution[-3 / 2, 1 / 2], NormalDistribution[3 / 2, 1 / 2]}];
SkewedBimodal = MixtureDistribution[{3 / 4, 1 / 4}, {NormalDistribution[], NormalDistribution[3 / 2, 1 / 3]}];
Trimodal = MixtureDistribution[{9 / 20, 9 / 20, 1 / 10}, {NormalDistribution[-6 / 5, 3 / 5], NormalDistribution[6 / 5, 3 / 5], NormalDistribution[0, 1 / 4]}];
Claw = MixtureDistribution[{1 / 2, 1 / 10, 1 / 10, 1 / 10, 1 / 10, 1 / 10}, Join[{NormalDistribution[]}, Table[NormalDistribution[i / 2 - 1, 1 / 10], {i, 0, 4}]]];
DoubleClaw = MixtureDistribution[Join[{49 / 100, 49 / 100}, ConstantArray[1 / 350, 7]], Join[{NormalDistribution[-1, 2 / 3], NormalDistribution[1, 2 / 3]}, Table[NormalDistribution[(i - 3) / 2, 1 / 100], {i, 0, 6}]]];
AsymmetricClaw = MixtureDistribution[Join[{1 / 2}, Table[(2 ^ (1 - i)) / 31, {i, -2, 2}]], Join[{NormalDistribution[]}, Table[NormalDistribution[i + 1 / 2, (2 ^ -i) / 10], {i, -2, 2}]]];
AsymmetricDoubleClaw = MixtureDistribution[{46 / 100, 46 / 100, 1 / 300, 1 / 300, 1 / 300, 7 / 300, 7 / 300, 7 / 300}, Join[Join[Table[NormalDistribution[2i - 1, 2 / 3], {i, 0, 1}], Table[NormalDistribution[-i / 2, 1 / 100], {i, 1, 3}]], Table[NormalDistribution[i / 2, 7 / 100], {i, 1, 3}]]];
SmoothComb = MixtureDistribution[Table[(2 ^ (5 - i)) / 63, {i, 0, 5}], Table[NormalDistribution[(65 - (96(1 / 2) ^ i)) / 21, (32 / 63) / 2 ^ i], {i, 0, 5}]];
DiscreteComb = MixtureDistribution[{2 / 7, 2 / 7, 2 / 7, 1 / 21, 1 / 21, 1 / 21}, Join[Table[NormalDistribution[(12i - 15) / 7, 2 / 7], {i, 0, 2}], Table[NormalDistribution[2i / 7, 1 / 21], {i, 8, 10}]]];
plots = Quiet@Table[Plot[PDF[𝒟, x], {x, -3, 3}, Filling -> Axis, FillingStyle -> Directive[Opacity[0.4], Lighter[ColorData[97, 3], 0.5]], PlotStyle -> ColorData[97, 3], Exclusions -> None, Evaluated -> True, PlotPoints -> 100, PlotRange -> All, AxesOrigin -> {0, 0}, Ticks -> None], {𝒟, {Gaussian, SkewedUnimodal, StrongSkew, KurtoticUnimodal, Outlier, Bimodal, SeparatedBimodal, SkewedBimodal, Trimodal, Claw, DoubleClaw, AsymmetricClaw, AsymmetricDoubleClaw, SmoothComb, DiscreteComb}}];
GraphicsGrid[Partition[plots, 3], ImageSize -> 500]A multivariate Gaussian mixture:
Claw = MixtureDistribution[{1 / 2, 1 / 10, 1 / 10, 1 / 10, 1 / 10, 1 / 10}, Join[{NormalDistribution[]}, Table[NormalDistribution[i / 2 - 1, 1 / 10], {i, 0, 4}]]];
Claw2 = ProductDistribution[{Claw, 2}];Plot3D[PDF[Claw2, {x, y}], {x, -2, 2}, {y, -2, 2}, PlotRange -> All]See Also
KernelMixtureDistribution ParameterMixtureDistribution RandomSample RandomChoice
Function Repository: MixtureCategoricalDistribution
Text
Wolfram Research (2010), MixtureDistribution, Wolfram Language function, https://reference.wolfram.com/language/ref/MixtureDistribution.html (updated 2016).
CMS
Wolfram Language. 2010. "MixtureDistribution." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/MixtureDistribution.html.
APA
Wolfram Language. (2010). MixtureDistribution. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MixtureDistribution.html
BibTeX
@misc{reference.wolfram_2026_mixturedistribution, author="Wolfram Research", title="{MixtureDistribution}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/MixtureDistribution.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_mixturedistribution, organization={Wolfram Research}, title={MixtureDistribution}, year={2016}, url={https://reference.wolfram.com/language/ref/MixtureDistribution.html}, note=[Accessed: 13-June-2026]}