KernelMixtureDistribution[{x1,x2,…}]
データ値 xiに基づいたカーネル混合分布を表す.
KernelMixtureDistribution[{{x1,y1,…},{x2,y2,…},…}]
データ値{xi,yi,…}に基づいた多変量カーネル混合分布を表す.
KernelMixtureDistribution[…,bw]
帯域幅が bw のカーネル混合分布を表す.
KernelMixtureDistribution[…,bw,ker]
帯域幅が bw,平滑化カーネルが ker のカーネル混合分布を表す.
KernelMixtureDistribution
KernelMixtureDistribution[{x1,x2,…}]
データ値 xiに基づいたカーネル混合分布を表す.
KernelMixtureDistribution[{{x1,y1,…},{x2,y2,…},…}]
データ値{xi,yi,…}に基づいた多変量カーネル混合分布を表す.
KernelMixtureDistribution[…,bw]
帯域幅が bw のカーネル混合分布を表す.
KernelMixtureDistribution[…,bw,ker]
帯域幅が bw,平滑化カーネルが ker のカーネル混合分布を表す.
詳細とオプション
- KernelMixtureDistributionは他の確率分布と同じように使えるDataDistributionオブジェクトを返す.
- 値
についてのKernelMixtureDistributionの確率密度関数は,平滑化カーネル
,帯域幅母数
では
で与えられる. - 使用可能な帯域幅指定 bw
-
h 使用する帯域幅 {"Standardized",h} 標準偏差の単位による帯域幅 {"Adaptive",h,s} 初期帯域幅 h,感度 s の適応的帯域幅 Automatic 自動計算された帯域幅 "name" 名前付き帯域幅選択法を使う {bwx,bwy,…} x, y 等に別々の帯域幅指定 - 多変量密度については,h は正定値対称行列でもよい.
- 適応的帯域幅については,感度 s は0から1までの実数あるいはAutomaticでなければならない.Automaticの場合,s は
に設定される.ただし,
はデータの次元である. - 使用可能な名前付き帯域幅選択法
-
"LeastSquaresCrossValidation" 最小二乗交差検定法を使う "Oversmooth" 標準Gaussianの1.08倍広い "Scott" Scottの規則を使った帯域幅選択 "SheatherJones" Sheather–Jonesプラグイン推定器を使う "Silverman" Silvermanの規則を使った帯域幅の決定 "StandardDeviation" 帯域幅として標準偏差を使う "StandardGaussian" 標準正規データの最適帯域幅 - デフォルトで"Silverman"メソッドが使われる.
- 帯域幅の自動計算では,定配列が単位分散を持つものとみなされる.
- 次のカーネル指定 ker が使える.
-
"Biweight" 

"Cosine" 

"Epanechnikov" 

"Gaussian" 

"Rectangular" 

"SemiCircle" 

"Triangular" 

"Triweight" 

func 

- KernelMixtureDistributionが真の密度推定を生成するためには,関数 fn は有効な一変量確率密度関数でなければならない.
- デフォルトで"Gaussian"カーネルが使われる.
- 多変量密度については,カーネル関数 ker は積およびラジアルタイプとしてそれぞれ{"Product",ker}と{"Radial",ker}を使って指定することができる.積タイプのカーネルはタイプの指定がない場合に使われる.
- 密度推定に使われる精度は bw とデータで与えられる最低精度である.
- 使用可能なオプション
-
MaxMixtureKernels Automatic 使用するカーネルの最大数 - KernelMixtureDistributionはMean,CDF,RandomVariate等の関数で使うことができる.
例題
すべて開く すべて閉じる例 (3)
BlockRandom[SeedRandom[1];data = RandomVariate[NormalDistribution[], 10 ^ 4]];𝒟 = KernelMixtureDistribution[data];Table[Plot[f[𝒟, x], {x, -4, 4}, Filling -> Axis, PlotLabel -> f], {f, {PDF, CDF}}]Moment[𝒟, 2]Quantile[𝒟, .8]BlockRandom[SeedRandom[1];data = RandomVariate[BinormalDistribution[.75], 10 ^ 3];];𝒟 = KernelMixtureDistribution[data];Table[ContourPlot[f[𝒟, {x, y}], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, PlotLabel -> f], {f, {PDF, CDF}}]Covariance[𝒟]//MatrixFormMoment[𝒟, {1, 2}]data = {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3]};𝒟 = KernelMixtureDistribution[data, h];PDF[𝒟, x]//ExpandVariance[𝒟]Skewness[𝒟]スコープ (47)
基本的な用法 (8)
data = RandomVariate[NormalDistribution[], 100];𝒟 = KernelMixtureDistribution[data];Show[Histogram[data, Automatic, "PDF"], Plot[PDF[𝒟, x], {x, -4, 4}, PlotStyle -> Thick]]Probability[x > 2, x𝒟]data = RandomVariate[GammaDistribution[1, Quantity[2, "s"]], 10 ^ 3]𝒟 = KernelMixtureDistribution[data]#[𝒟]& /@ {Mean, Variance, Skewness, Kurtosis}data = RandomVariate[NormalDistribution[], 50];bw = {.1, .2, .3, .5};Table[Plot[PDF[KernelMixtureDistribution[data, i], x]//Evaluate, {x, -4, 4}, PlotRange -> {0, 2}, PlotLabel -> Row[{"band width = ", i}], Filling -> 0], {i, bw}]//Quietdata = RandomVariate[𝒹 = MixtureDistribution[{2, 1}, {NormalDistribution[], NormalDistribution[2, 1 / 2]}], 10^4];𝒟 = KernelMixtureDistribution[data, {"Adaptive", Automatic, Automatic}];Plot[{PDF[𝒹, x], PDF[𝒟, x]}, {x, -4, 4}, PlotLegends -> {"𝒹", "𝒟"}]data = ExampleData[{"Statistics", "OldFaithful"}][[All, 1]];𝒟 = KernelMixtureDistribution[data, "LeastSquaresCrossValidation"];Plot[PDF[𝒟, x], {x, 1, 6}]est = EstimatedDistribution[data, MixtureDistribution[{1 / 3, 2 / 3}, {NormalDistribution[μ1, σ1], NormalDistribution[μ2, σ2]}], {{μ1, 2.0}, {σ1, .25}, {μ2, 4.3}, {σ2, .5}}];Plot[{PDF[𝒟, x], PDF[est, x]}, {x, 1, 6}, PlotLegends -> {"𝒟", "est"}]data = RandomVariate[MultinormalDistribution[{0, 0, 0, 0}, IdentityMatrix[4]], 25];𝒟 = KernelMixtureDistribution[data];Table[Plot[PDF[MarginalDistribution[𝒟, i], x]//Evaluate, {x, -4, 4}, PlotRange -> All, Filling -> Axis, PlotLabel -> i, Axes -> {True, False}], {i, 4}]data2 = RandomVariate[𝒟, 10^4];Table[Histogram[data2[[All, i]], 30, PlotRange -> {{-4, 4}, All}, Axes -> {True, False}], {i, 4}]data = {χ[1], χ[2], χ[3]};𝒟 = KernelMixtureDistribution[data, h, PDF[StudentTDistribution[ν], #]&];PDF[𝒟, x]//FullSimplifyProbability[x > 0, x𝒟]//FullSimplify多変量の推定に積タイプかラジアルタイプのカーネルを指定する:
data = RandomVariate[BinormalDistribution[2 / 5], 250];𝓀ℯ𝓇𝓃ℯℓ = PDF[LaplaceDistribution[0, 1], #]&;𝒟 = Table[KernelMixtureDistribution[data, {{1, .25}, {.25, 1}}, 𝒦], {𝒦, {{"Radial", 𝓀ℯ𝓇𝓃ℯℓ}, {"Product", 𝓀ℯ𝓇𝓃ℯℓ}}}];Table[Plot3D[PDF[i, {x, y}], {x, -5, 5}, {y, -5, 5}, PlotRange -> All, Exclusions -> None, MeshFunctions -> (#3&)], {i, 𝒟}]分布特性 (10)
𝒟 = KernelMixtureDistribution[RandomVariate[NormalDistribution[], 10^3]];Table[Plot[f[𝒟, x]//Evaluate, {x, -4, 4}, Frame -> True, Filling -> Axis, PlotLabel -> f], {f, {PDF, CDF, HazardFunction, SurvivalFunction}}]PDF[𝒟, x][[1 ;; 3]]CDF[𝒟, x][[1 ;; 3]]𝒟 = KernelMixtureDistribution[RandomVariate[NormalDistribution[], 1000], {"Adaptive", Automatic, .5}, "Biweight"];{Mean[𝒟], Variance[𝒟], Skewness[𝒟], Kurtosis[𝒟]}Table[Moment[𝒟, k], {k, 4}]Table[CentralMoment[𝒟, k], {k, 4}]Table[Cumulant[𝒟, k], {k, 4}]Table[FactorialMoment[𝒟, k], {k, 4}]𝒟 = KernelMixtureDistribution[Range[5], h, "Epanechnikov"];{Mean[𝒟], Variance[𝒟], Skewness[𝒟], Kurtosis[𝒟]}𝒟 = KernelMixtureDistribution[Range[3], {"Adaptive", h, 1 / 4}];Variance[𝒟]//Simplify𝒟 = KernelMixtureDistribution[RandomVariate[NormalDistribution[], 15]];Plot[Quantile[𝒟, p], {p, 0, 1}, Filling -> Axis, Exclusions -> None]Quartiles[𝒟]InterquartileRange[𝒟]Quantile[𝒟, {0.05, 0.95}]Median[𝒟]𝒟 = KernelMixtureDistribution[RandomVariate[NormalDistribution[], 1000]];RandomVariate[𝒟, 10]KernelMixtureDistributionと比較する:
Show[Histogram[RandomVariate[𝒟, 10^4], Automatic, "ProbabilityDensity"],
Plot[PDF[𝒟, x], {x, -4, 4}, Exclusions -> False, PlotStyle -> Thick]]𝒟 = KernelMixtureDistribution[RandomVariate[NormalDistribution[], 10 ^ 3]];Probability[x < 3, x𝒟]Expectation[x^2, x𝒟]𝒟 = KernelMixtureDistribution[Range[5], h];MomentGeneratingFunction[𝒟, t]CharacteristicFunction[𝒟, t]𝒟 = KernelMixtureDistribution[RandomVariate[BinormalDistribution[.75], 100]];Table[DiscretePlot3D[f[𝒟, {x, y}]//Evaluate, {x, -4, 4, .5}, {y, -4, 4, .5}, PlotLabel -> f, ExtentSize -> 1 / 2], {f, {PDF, CDF, HazardFunction, SurvivalFunction}}]𝒟 = KernelMixtureDistribution[RandomReal[BinormalDistribution[.75], 1000]];{Mean[𝒟], Variance[𝒟]}Covariance[𝒟]//MatrixFormCorrelation[𝒟]//MatrixFormMoment[𝒟, {1, 2}]CentralMoment[𝒟, {1, 2}]Cumulant[𝒟, {1, 2}]FactorialMoment[𝒟, {1, 2}]𝒟 = KernelMixtureDistribution[RandomReal[BinormalDistribution[.5], 10 ^ 4]];ListPlot[RandomVariate[𝒟, 10^4], PlotStyle -> PointSize[Tiny], PlotRange -> {{-4, 4}, {-4, 4}}]帯域幅の選択 (19)
data1 = RandomVariate[𝒹 = NormalDistribution[], 10];
data2 = RandomVariate[𝒹, 10 ^ 4];𝒟1 = KernelMixtureDistribution[data1];
𝒟2 = KernelMixtureDistribution[data2];Table[Plot[{PDF[𝒟, x], PDF[𝒹, x]}, {x, -4, 4}, Filling -> Axis, Exclusions -> None], {𝒟, {𝒟1, 𝒟2}}]data = RandomVariate[NormalDistribution[], 10 ^ 3];𝒟1 = KernelMixtureDistribution[data, 0.1];
𝒟2 = KernelMixtureDistribution[data, 1.0];Table[Plot[PDF[𝒟, x], {x, -4, 4}, Filling -> Axis, Exclusions -> None], {𝒟, {𝒟1, 𝒟2}}]data = Range[5];𝒟 = KernelMixtureDistribution[data, h];PDF[𝒟, x]//ExpandCDF[𝒟, x]//Expanddata = RandomVariate[NormalDistribution[], 10 ^ 3];𝒟1 = KernelMixtureDistribution[data, {"Standardized", 1 / 2}];
𝒟2 = KernelMixtureDistribution[data, {"Standardized", 1 / 8}];Table[Plot[PDF[𝒟, x], {x, -4, 4}, PlotRange -> {0, .4}, Filling -> Axis, Exclusions -> None, PlotLabel -> Row[{"Bandwidth = ", 𝒟["Bandwidth"]}]], {𝒟, {𝒟1, 𝒟2}}]data = RandomVariate[NormalDistribution[], 10 ^ 3];Table[Plot[PDF[KernelMixtureDistribution[data, {"Adaptive", Automatic, s}], x]//Evaluate, {x, -4, 4}, PlotLabel -> Row[{"s = ", s}]], {s, {0, .25, .75, 1}}]//Quiet感度をAutomaticに設定すると
が使われる.ただし,
はデータの次元である:
data = RandomVariate[NormalDistribution[], 10^3];p = 1;𝒟1 = KernelMixtureDistribution[data, {"Adaptive", Automatic, (1/2 p)}];
𝒟2 = KernelMixtureDistribution[data, {"Adaptive", Automatic, Automatic}];Table[Plot[PDF[𝒟, x], {x, -4, 4}, Filling -> Axis, Exclusions -> None], {𝒟, {𝒟1, 𝒟2}}]data = RandomVariate[NormalDistribution[], 10 ^ 3];𝒟1 = KernelMixtureDistribution[data, {"Adaptive", 1, .5}];
𝒟2 = KernelMixtureDistribution[data, {"Adaptive", 0.1, .5}];Table[Plot[PDF[𝒟, x], {x, -4, 4}, Filling -> Axis, Exclusions -> None], {𝒟, {𝒟1, 𝒟2}}]data = RandomVariate[NormalDistribution[], 100];Table[Plot[PDF[KernelMixtureDistribution[data, name], x]//Evaluate, {x, -4, 4}, Filling -> Axis, Exclusions -> None, PlotLabel -> name], {name, {"LeastSquaresCrossValidation", "Oversmooth", "Scott", "SheatherJones", "StandardDeviation", "StandardGaussian"}}]data = RandomVariate[NormalDistribution[], 10 ^ 3];𝒟1 = KernelMixtureDistribution[data, "Silverman"];
𝒟2 = KernelMixtureDistribution[data, Automatic];Table[Plot[PDF[𝒟, x], {x, -4, 4}, Filling -> Axis, Exclusions -> None], {𝒟, {𝒟1, 𝒟2}}]p = 2;n = 2;data = Array[x, {n, p}];スカラー h を与えると事実上 h IdentityMatrix[p]が使われる:
PDF[KernelMixtureDistribution[data, h], {y1, y2}]PDF[KernelMixtureDistribution[data, h * IdentityMatrix[p]], {y1, y2}]対角要素 d を指定すると事実上DiagonalMatrix[d]が使われる:
d = Array[h, p]PDF[KernelMixtureDistribution[data, d], {y1, y2}]PDF[KernelMixtureDistribution[data, DiagonalMatrix[d]], {y1, y2}]𝒟 = KernelMixtureDistribution[data, {{d1, od}, {od, d2}}]デフォルトで各次元に別々に帯域幅を選ぶのにはSilvermanメソッドが使われる:
data = RandomVariate[BinormalDistribution[.75], 25];Table[Plot3D[PDF[KernelMixtureDistribution[data, name], {x, y}]//Evaluate, {x, -3, 3}, {y, -3, 3}, PlotRange -> All, PlotLabel -> name, Exclusions -> None], {name, {Automatic, "Silverman"}}]別々に対角の帯域幅要素を選ぶためには,どの自動メソッドを使ってもよい:
data = RandomVariate[BinormalDistribution[.75], 25];Table[Plot3D[PDF[KernelMixtureDistribution[data, name], {x, y}]//Evaluate, {x, -3, 3}, {y, -3, 3}, PlotRange -> All, PlotLabel -> name, Exclusions -> None], {name, {"LeastSquaresCrossValidation", "Oversmooth", "Scott", "SheatherJones", "StandardDeviation", "StandardGaussian"}}]data = RandomVariate[NormalDistribution[], {1000, 3}];適応的帯域幅,過剰平滑化帯域幅,一定の帯域幅をそれぞれの次元に用いる:
𝒟 = KernelMixtureDistribution[data, {{"Adaptive", .05, 1}, "Silverman", 10}];Table[Plot[PDF[MarginalDistribution[𝒟, i], x]//Evaluate, {x, -4, 4}, Filling -> Axis, Exclusions -> None, PlotLabel -> i], {i, {1, 2, 3}}]//Quietdata = RandomVariate[BinormalDistribution[.75], 25];ℬs = {.25, .5, 1.0};Table[Plot3D[PDF[KernelMixtureDistribution[data, bw], {x, y}]//Evaluate, {x, -3, 3}, {y, -3, 3}, PlotRange -> All, PlotLabel -> Row[{"bandwidth = ", bw * IdentityMatrix[2]}], Exclusions -> None], {bw, ℬs}]非零の対角から外れた要素を使うために,完全に指定された帯域幅行列を使う:
bw = {{1 / 2, 1 / 4}, {1 / 4, 1 / 2}};𝒟 = KernelMixtureDistribution[RandomVariate[NormalDistribution[], {100, 2}], bw];ContourPlot[PDF[𝒟, {x, y}], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 50, PlotRange -> All]𝒟 = Hold[KernelMixtureDistribution[{{0, 0}}, h]];Table[ContourPlot[PDF[𝒟 /. h -> i//ReleaseHold, {x, y}]//Evaluate, {x, -2, 2}, {y, -2, 2}, PlotRange -> All, PlotLabel -> i, Frame -> None], {i, {.25, .5, .75, 1.}}]Table[ContourPlot[PDF[𝒟 /. h -> i//ReleaseHold, {x, y}]//Evaluate, {x, -2, 2}, {y, -2, 2}, PlotRange -> All, PlotLabel -> i, Frame -> None], {i, {{.5, .5}, {.5, .75}, {.75, .75}, {.75, .5}}}]Table[ContourPlot[PDF[𝒟 /. h -> i//ReleaseHold, {x, y}]//Evaluate, {x, -2, 2}, {y, -2, 2}, PlotRange -> All, PlotLabel -> i, Frame -> None], {i, {{{.75, 0}, {0, .5}}, {{.75, .25}, {.25, .5}}, {{.5, .25}, {.25, .75}}, {{.5, -.25}, {-.25, .75}}}}]いくつかの名前付き帯域幅メソッドは経験的アプローチに従っている:
n = 10;data = RandomVariate[NormalDistribution[], n];iqr = (Quantile[data, .75] - Quantile[data, .25]);sd = StandardDeviation[data];silverman = .9 Min[(iqr/1.34), sd] n^-1 / 5;stdGauss = (2^2 / 5/3^1 / 5) Min[(iqr/1.34), sd] n^-1 / 5;overSmooth = 1.08 stdGauss;scott = sd * n^-1 / 5;pdf1 = Table[Plot[PDF[KernelMixtureDistribution[data, i], x]//Evaluate, {x, -4, 4}, Ticks -> None], {i, {silverman, stdGauss, overSmooth, scott}}];
pdf2 = Table[Plot[PDF[KernelMixtureDistribution[data, i], x]//Evaluate, {x, -4, 4}, Ticks -> None], {i, {"Silverman", "StandardGaussian", "Oversmooth", "Scott"}}];MapThread[Show[#1, #2, PlotLabel -> #3]&, {pdf1, pdf2, {"Silverman", "StandardGaussian", "Oversmooth", "Scott"}}]data = RandomVariate[NormalDistribution[], 25];Rk[h_, data_] := With[{n = Length[data]}, 1 / (h Sqrt[π]) (Exp[-((Subtract@@@Subsets[data, {2}]) ^ 2 / (4 h ^ 2))].ConstantArray[1 / n ^ 2, Total[Range[1, n - 1]]] + 1 / (2 n))]Ro[h_, data_] := Total[1 / ((Length[data] - 1) h Sqrt[2 π])Table[Plus@@Exp[-(data[[i]] - Delete[data, {i}]) ^ 2 / (2 h ^ 2)], {i, Length[data]}]]LSCV[h_, data_] := With[{n = Length[data]}, Rk[h, data] - (2/n) Ro[h, data]]帯域幅は
に対する最小二乗交差確認関数を最小化することで求まる:
bw = FindMinimum[LSCV[h, data], {h}][[2]]Show[Plot[LSCV[h, data], {h, 0.01, 2}], Graphics[Arrow[{{h /. bw, 0}, {h /. bw, LSCV[h /. bw, data]}}]]]Sheather-Jones法はプラグイン推定器を使って帯域幅について解く:
ϕIV[xsq_] := Total[(3 + xsq (-6 + xsq))E^-xsq / 2]ϕVI[xsq_] := Total[(-15 + xsq (45 + xsq (-15 + xsq)))E^-xsq / 2]SheatherJonesBW[data_] := Block[{n = Length[data], λ, a, b, δ2, α2, h},
λ = Min[(Quantile[data, .75] - Quantile[data, .25]) / 1.34, StandardDeviation[data]];
a = (92/100) λ n^-1 / 7;
b = (912 /1000)λ n^-1 / 9;
δ2 = Flatten[Table[(data - i)^2, {i, data}]];
α2 = (1357/1000) ((b^7 n (n - 1)ϕIV[δ2 / a^2]/-a^5 n (n - 1) ϕVI[δ2 / b^2]))^1 / 7 h^5 / 7;
FindRoot[((α2^5 n (n - 1)/ϕIV[δ2 / α2^2]))^1 / 5 - h (n Sqrt[2])^1 / 5 == 0, {h, λ}]
]data = RandomVariate[NormalDistribution[], 15];sjbw = SheatherJonesBW[data]Plot[{PDF[KernelMixtureDistribution[data, h /. sjbw], x], PDF[KernelMixtureDistribution[data, "SheatherJones"], x]}//Evaluate, {x, -3, 3}]カーネル関数 (10)
data = RandomVariate[NormalDistribution[], 100];Table[Plot[PDF[ KernelMixtureDistribution[data, Automatic, i], x]//Evaluate, {x, -4, 4}, Filling -> Axis, Ticks -> None, PlotLabel -> i, Exclusions -> None], {i, {"Biweight", "Cosine", "Epanechnikov", "Gaussian", "Rectangular", "SemiCircle", "Triangular", "Triweight"}}]data = RandomVariate[NormalDistribution[], 10];𝒟1 = KernelMixtureDistribution[data, Automatic];
𝒟2 = KernelMixtureDistribution[data, Automatic, (1/π (1 + #1^2))&];Table[Plot[PDF[𝒟, x]//Evaluate, {x, -4, 4}, Filling -> Axis, Exclusions -> None], {𝒟, {𝒟1, 𝒟2}}]data = RandomVariate[NormalDistribution[], 10];𝒟1 = KernelMixtureDistribution[data, Automatic];
𝒟2 = KernelMixtureDistribution[data, Automatic, "Gaussian"];Table[Plot[PDF[𝒟, x]//Evaluate, {x, -4, 4}, Filling -> Axis, Exclusions -> None, PlotRange -> All], {𝒟, {𝒟1, 𝒟2}}]これはNormalDistribution[0,1]の確率密度関数を使うことに等しい:
𝒟3 = KernelMixtureDistribution[data, Automatic, PDF[NormalDistribution[], #]&];Plot[PDF[𝒟3, x], {x, -4, 4}, Filling -> Axis, Exclusions -> None, PlotRange -> All]kernels = {"Biweight", "Cosine", "Epanechnikov", "Gaussian", "Rectangular", "SemiCircle", "Triangular", "Custom"};dists = Table[KernelMixtureDistribution[{0}, 1, i], {i, (kernels /. {"Custom" -> (PDF[CauchyDistribution[0, 1], #]&)})}];Table[Plot[PDF[dists[[i]], x], {x, -3, 3}, PlotRange -> All, PlotLabel -> kernels[[i]], Filling -> Axis, Ticks -> None], {i, Length[kernels]}]多変量データにいくつかのカーネル関数の中から任意のものを指定する:
data = RandomVariate[BinormalDistribution[.75], 100];Table[Plot3D[PDF[ KernelMixtureDistribution[data, Automatic, i], {x, y}]//Evaluate, {x, -4, 4}, {y, -4, 4}, Ticks -> None, PlotLabel -> i, Exclusions -> None, PlotRange -> All, MeshFunctions -> (#3&)], {i, {"Biweight", "Cosine", "Epanechnikov", "Gaussian", "Rectangular", "SemiCircle", "Triangular", "Triweight"}}]kernels = {"Gaussian", "Epanechnikov", "Biweight", "Triweight", "Cosine", "Triangular", "SemiCircle", "Custom"};dists = Table[KernelMixtureDistribution[{{0, 0}}, Automatic, i], {i, (kernels /. {"Custom" -> (PDF[CauchyDistribution[0, 1], #]&)})}];Table[Plot3D[PDF[dists[[i]], {x, y}]//Evaluate, {x, -2, 2}, {y, -2, 2}, PlotRange -> All, Exclusions -> None, PlotPoints -> 35, PlotLabel -> kernels[[i]], Filling -> Axis, Ticks -> None, Mesh -> None], {i, Length[kernels]}]多変量データについて積タイプとラジアルタイプのカーネル関数のどちらかを選ぶ:
data = {{0, 0}};kerns = {{"Product", "Biweight"}, {"Radial", "Biweight"}};Table[Plot3D[PDF[ KernelMixtureDistribution[data, 1, i], {x, y}]//Evaluate, {x, -1.5, 1.5}, {y, -1.5, 1.5}, Ticks -> None, PlotLabel -> i, Exclusions -> None, PlotRange -> All, PlotPoints -> 100, MeshFunctions -> (#3 &), Boxed -> False], {i, kerns}]biweight = ProbabilityDistribution[(15/16) (1 - x^2)^2, {x, -1, 1}];product[h_] := PDF[ProductDistribution[biweight, biweight], MatrixPower[h, -(1/2)].{x, y}] / Sqrt[Det[h]]ContourPlot[product[IdentityMatrix[2]]//Evaluate, {x, -1.5, 1.5}, {y, -1.5, 1.5}, PlotRange -> All]radial[h_] := PDF[biweight, Norm[MatrixPower[h, -(1/2)].{x, y}]] / (Sqrt[Det[h]])ContourPlot[radial[IdentityMatrix[2]]//Evaluate, {x, -1.5, 1.5}, {y, -1.5, 1.5}, PlotRange -> All]帯域幅はラジアルタイプのカーネルと積タイプのカーネルの両方に同じような影響を与える:
kernel = PDF[LaplaceDistribution[0, 1], #]&;compare[bw_] := Table[Plot3D[PDF[KernelMixtureDistribution[{{0, 0}}, bw, k], {x, y}]//Evaluate, {x, -3, 3}, {y, -3, 3}, PlotRange -> All, PlotPoints -> 50, MeshFunctions -> (#3&), Axes -> False, PlotLabel -> Row[{k[[1]], ": ", bw}]], {k, {{"Product", kernel}, {"Radial", kernel}}}]bw = {.95 IdentityMatrix[2], DiagonalMatrix[{.95, .5}], {{.95, .5}, {.5, .95}}};compare[bw[[1]]]compare[bw[[2]]]compare[bw[[3]]]epanechnikov = (3 (5 - x^2) Boole[Abs[x] < Sqrt[5]]/20 Sqrt[5]);
biweight = (15/16) (1 - x^2)^2 Boole[Abs[x] < 1];
triweight = (35/32) (1 - x^2)^3 Boole[Abs[x] < 1];
cosine = (1/4) π Boole[Abs[x] < 1] Cos[(π x/2)];
semicircle = Piecewise[{{(2*Sqrt[1 - x^2])/Pi, -1 < x < 1}}, 0];
gaussian = (E^-(x^2/2)/Sqrt[2 π]);
rectangular = Piecewise[{{1/2, -1 <= x <= 1}}, 0];
triangular = Piecewise[{{1 + x, -1 <= x <= 0}, {1 - x, Inequality[0, Less, x, LessEqual, 1]}}, 0];eff[kernel_] := (3/ 5 Sqrt[5])(Subsuperscript[∫, -∞, ∞]x^2 kernelⅆx)^-1 / 2(Subsuperscript[∫, -∞, ∞]kernel^2ⅆx)^-1.Table[{kern, eff[ToExpression[kern]]}, {kern, {"epanechnikov", "biweight", "triweight", "cosine", "semicircle", "gaussian", "rectangular", "triangular"}}]//TableFormオプション (7)
MaxMixtureKernels (7)
デフォルトで,カーネルはサンプル数300未満の各データ点に置かれている:
data = RandomVariate[NormalDistribution[1, 2], 20];𝒟 = KernelMixtureDistribution[data, MaxMixtureKernels -> Automatic];Plot[PDF[𝒟, x]//Evaluate, {x, -10, 10}, PlotRange -> All]サンプルサイズが大きい場合はデフォルトで等間隔で置かれた最大で300個のカーネルが使われる:
data = RandomVariate[NormalDistribution[], 10 ^ 4];dist = KernelMixtureDistribution[data, MaxMixtureKernels -> Automatic];Plot[PDF[dist, x]//Evaluate, {x, -4, 4}, PlotRange -> All]//Quietdata = RandomVariate[NormalDistribution[], 15];dist = KernelMixtureDistribution[data, MaxMixtureKernels -> 5];Plot[PDF[dist, x], {x, -4, 4}, Filling -> Axis]カーネルの数が多い程もとになっている分布がうまく推定できる:
data = RandomVariate[NormalDistribution[], 10 ^ 4];estimates = Table[KernelMixtureDistribution[data, MaxMixtureKernels -> i], {i, {10, 15, 25, 100}}];Table[Plot[{PDF[i, x], PDF[NormalDistribution[], x]}, {x, -4, 4}, Filling -> Axis, PlotRange -> All], {i, estimates}]data = {-2, 0, 2};𝒟 = KernelMixtureDistribution[data, .25, MaxMixtureKernels -> All];Plot[PDF[𝒟, x], {x, -4, 4}, Filling -> Axis, Frame -> True, PlotRange -> All]Table[Plot[PDF[KernelMixtureDistribution[data, bw, MaxMixtureKernels -> All], x]//Evaluate, {x, -4, 4}, Filling -> Axis, PlotRange -> {0, .6}, PlotLabel -> Row[{"bandwidth = ", bw}]], {bw, {0.25, 0.5, 0.75, 1.0}}]二変量データについて各次元で使用されるカーネルの数を指定する:
data = RandomVariate[BinormalDistribution[.8], 200];estimates = Table[KernelMixtureDistribution[data, .15, MaxMixtureKernels -> i], {i, {10, 100}}];Table[DensityPlot[Evaluate[PDF[i, {x, y}]], {x, -4, 4}, {y, -4, 4}, PlotPoints -> 80, PlotRange -> All, ColorFunction -> "TemperatureMap"], {i, estimates}]//Quietdata = RandomVariate[BinormalDistribution[.8], 1000];最大でそれぞれ5個と50個あるいは50個と5個のカーネルを指定する:
estimates = Table[KernelMixtureDistribution[data, MaxMixtureKernels -> i], {i, {{5, 50}, {50, 5}}}];Table[Plot3D[PDF[i, {x, y}]//Evaluate, {x, -4, 4}, {y, -4, 4}, PlotPoints -> 50, PlotRange -> All], {i, estimates}]//Quietアプリケーション (6)
𝒹 = 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}]]];data = RandomVariate[𝒹, 10 ^ 5];高解像度が望ましい場合は適応的帯域幅と多くの混合カーネルを使う:
𝒟 = KernelMixtureDistribution[data, {"Adaptive", Automatic, .25}, MaxMixtureKernels -> 500];Plot[{PDF[𝒹, x], PDF[𝒟, x]}//Evaluate, {x, -4, 4}, Filling -> {1 -> 0}, PlotLegends -> {"𝒹", "𝒟"}]//Quiet{Mean[𝒹], Variance[𝒹], Skewness[𝒹], Kurtosis[𝒹]}//N{Mean[𝒟], Variance[𝒟], Skewness[𝒟], Kurtosis[𝒟]}//NNASDAQのApple株の日ごとの点変化の分布を推定する:
nasdaq = FinancialData["NASDAQ:AAPL", All, "Value"];
data = Log[Ratios[nasdaq]];𝒟 = KernelMixtureDistribution[data, MaxMixtureKernels -> 3000];裾部が重いデータの場合は,より滑らかな推定を得るためにMaxMixtureKernelsオプションを大きくする:
Plot[PDF[𝒟, x]//Evaluate, {x, -.2, .2}, PlotRange -> All]//QuietProbability[x ≥ Log[1.1], x𝒟]ExampleData[{"Statistics", "BuffaloSnow"}, "Description"]snow = QuantityArray[ExampleData[{"Statistics", "BuffaloSnow"}], "Inches"];Subscript[𝒟, BSnow] = KernelMixtureDistribution[snow];Plot[PDF[Subscript[𝒟, BSnow], Quantity[x, "Inches"]]//Evaluate, {x, 0, 150}, Filling -> Axis, AxesLabel -> {"in"}]Table[Plot[PDF[KernelMixtureDistribution[snow, bw], Quantity[x, "Inches"]]//Evaluate, {x, 10, 150}, PlotRange -> {0, .025}, Filling -> Axis, Ticks -> {{0, 50, 100, 150}}, AxesLabel -> {"in"}, PlotLabel -> Row[{"Bandwidth: ", bw}]], {bw, Quantity[{4, 8, 12, 20}, "Inches"]}]偽造紙幣を見分けるのに最も役に立つ測定法を6つの中から選ぶ:
sbn = ExampleData[{"Statistics", "SwissBankNotes"}];ExampleData[{"Statistics", "SwissBankNotes"}, "ColumnDescriptions"]c = QuantityArray[Transpose[Pick[sbn[[All, 1 ;; -2]], sbn[[All, -1]], 1]], "Milimeters"];
nc = QuantityArray[Transpose[Pick[sbn[[All, 1 ;; -2]], sbn[[All, -1]], 0]], "Milimeters"];Subscript[𝒟, c] = Table[KernelMixtureDistribution[i], {i, c}];
Subscript[𝒟, nc] = Table[KernelMixtureDistribution[i], {i, nc}];測定法6が2種類の紙幣を見分けるのに最も適しているようである:
Table[Plot[{PDF[Subscript[𝒟, c][[i]], Quantity[x, "Millimeters"]], PDF[Subscript[𝒟, nc][[i]], Quantity[x, "Millimeters"]]}//Evaluate, {x, Min[QuantityMagnitude[{c[[i]], nc[[i]]}]], Max[QuantityMagnitude[{c[[i]], nc[[i]]}]]}, Filling -> Axis, PlotLabel -> Row[{"Measure ", i}], ImageSize -> 150, PlotRange -> All], {i, Length[c]}]140.5mmで切り捨て,測定法6を分類器として使って,見分け損ないの確率を求める:
cutoff = Quantity[140.5, "Millimeters"];Probability[x ≤ cutoff, xSubscript[𝒟, nc][[6]]] + Probability[x ≥ cutoff, xSubscript[𝒟, c][[6]]]data = RandomVariate[𝒹 = NormalDistribution[], n = 45];𝒟 = KernelMixtureDistribution[data, h];Plot[(fn = Total[((PDF[𝒟, #] - PDF[𝒹, #])^2/n)& /@ data]), {h, .01, 6}, PlotRange -> {0, .1}]minMSE = FindMinimum[fn, h]Plot[Evaluate[PDF[KernelMixtureDistribution[data, h /. Last[minMSE]], x]], {x, -5, 5}]KernelMixtureDistributionを使って楕円分布を作ることができる.楕円分布は多変量正規分布を一般化したものである:
ellipticalDistribution[marginal_, μ_, Σ_ ? SymmetricMatrixQ] /; PositiveDefiniteMatrixQ[Σ] && Length[μ] == Length[Σ] := KernelMixtureDistribution[{μ}, MatrixPower[Σ, 1 / 2], {"Radial", PDF[marginal, #]&}]Σ = {{1, 1 / 2}, {1 / 2, 1}};
μ = {0, 0};周辺分布にNormalDistribution[0,1]を使うとMultinormalDistribution[μ,Σ]が与えられる:
𝒟MN = ellipticalDistribution[NormalDistribution[], μ, Σ]MomentGeneratingFunction[𝒟MN, {t1, t2}]MomentGeneratingFunction[MultinormalDistribution[{0, 0}, {{1, 1 / 2}, {1 / 2, 1}}], {t1, t2}]//FullSimplify𝒟L = ellipticalDistribution[LaplaceDistribution[0, 1], μ, Σ];Plot3D[Evaluate@PDF[𝒟L, {x, y}], {x, -4, 4}, {y, -4, 4}, PlotRange -> All, PlotPoints -> 35, Mesh -> None]𝒟T = ellipticalDistribution[StudentTDistribution[3], μ, Σ];Plot3D[Evaluate@PDF[𝒟T, {x, y}], {x, -4, 4}, {y, -4, 4}, PlotRange -> All, PlotPoints -> 35, Mesh -> None]特性と関係 (9)
data = RandomVariate[NormalDistribution[], 100];dist = KernelMixtureDistribution[data];NIntegrate[PDF[dist, x], {x, -∞, ∞}]data = Range[-2, 2];dist = KernelMixtureDistribution[data, h, 𝒦[#]&, MaxMixtureKernels -> All];PDF[dist, x]//ExpandKernelMixtureDistributionはもとになっている分布の一定推定器である:
data = Table[RandomVariate[NormalDistribution[], 10^i], {i, Range[4]}];𝒟l = Table[KernelMixtureDistribution[i], {i, data}];Table[Plot[{PDF[𝒟l[[i]], x], PDF[NormalDistribution[], x]}, {x, -5, 5}, PlotRange -> All, Axes -> {True, False}, PlotLabel -> Row[{"n=", Superscript[10, i]}]], {i, Range[4]}]実際に使われているカーネル数がサンプルサイズより大きいことはない:
data = Table[RandomVariate[NormalDistribution[], j], {j, {3, 5, 10, 25, 50, 100, 150, 250}}];dists = Table[KernelMixtureDistribution[i, MaxMixtureKernels -> 10000], {i, data}];Table[Length[PDF[i, x]], {i, dists}]帯域幅が無限大に近付くにつれ,推定量がカーネルの形に近付く:
data = {-.5, 0, .5};𝒦 = {"Gaussian", "Epanechnikov", "Biweight", "Triweight", "Rectangular", "Triangular", "Cosine", "SemiCircle"};Table[Plot[Evaluate@PDF[KernelMixtureDistribution[data, {"Standardized", 200}, i], x], {x, -250, 250}, PlotRange -> All, Exclusions -> None, Ticks -> None, PlotLabel -> i], {i, 𝒦}]KernelMixtureDistributionの線形補間はSmoothKernelDistributionである:
data = {-1.5, -1.0, -.2, -.1, 0., 1.5};fn = PDF[KernelMixtureDistribution[data], #]&;pts = fn /@ Range[-4, 4, .1];{ListLinePlot[Transpose[{Range[-4, 4, .1], pts}]], Plot[Evaluate@PDF[SmoothKernelDistribution[data], x], {x, -4, 4}]}KernelMixtureDistributionは結果としてカーネルのMixtureDistributionになる:
data = Range[5];𝒟 = KernelMixtureDistribution[data, h = 1, "Gaussian", MaxMixtureKernels -> All];PDF[𝒟, x]//SimplifyPDF[MixtureDistribution[ConstantArray[h, Length[data]], Table[NormalDistribution[i, h], {i, data}]], x]//Simplify% == %%KernelMixtureDistributionは,入力がTimeSeriesあるいはEventSeriesのときにのみ,値に使うことができる:
ts = TemporalData[TimeSeries, {{{1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1,
0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0,
0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0,
1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1}}, {{0, 99, 1}}, 1, {"Continuous", 1}, {"Discrete", 1}, 1,
{ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 10.1];KernelMixtureDistribution[ts]KernelMixtureDistribution[ts["Values"]]% == %%KernelMixtureDistributionは,入力がTemporalDataのときは,すべての値に同時に働く:
td = TemporalData[«4»];KernelMixtureDistribution[td]KernelMixtureDistribution[td["ValueList"]//Flatten]%% == %考えられる問題 (5)
data = {-1.5, -1.0, -.2, -.1, 0., 1.5};𝒟 = KernelMixtureDistribution[data, Automatic, Cos[#]&];Plot[PDF[𝒟, x], {x, -4, 4}, Filling -> Axis]data = RandomVariate[NormalDistribution[], 10 ^ 6];𝒟1 = KernelMixtureDistribution[data, {"Adaptive", Automatic, 1}];Plot[PDF[𝒟1, x]//Evaluate, {x, -4, 4}, PlotRange -> All]//Quiet初期帯域幅を大きくする,MaxMixtureKernels,感度を下げる,等を試す:
𝒟2 = KernelMixtureDistribution[data, {"Adaptive", 1.5, 1}];Plot[PDF[𝒟2, x]//Evaluate, {x, -4, 4}, PlotRange -> All]//Quiet記号データの場合,カーネルは各データ点に置かれなければならない:
data = Array[x, 10];𝒟 = KernelMixtureDistribution[data, MaxMixtureKernels -> 5]MaxMixtureKernelsをAllかAutomaticに設定する:
𝒟 = KernelMixtureDistribution[data, MaxMixtureKernels -> Automatic]PDF[𝒟, x]//Expand記号データは"SheatherJones"と"LeastSquaresCrossValidation"のメソッドでは使えない:
data = Array[x, 3]KernelMixtureDistribution[data, "SheatherJones"]validBWs = {"Silverman", Automatic, h, {"Adaptive", h, 1 / 2}, {"Standardized", 1}, .3};Table[Head[KernelMixtureDistribution[data, i]], {i, validBWs}]カーネル関数の中には境界がありプロットで除外部分が出ることがある:
data = RandomVariate[NormalDistribution[], 1000];𝒟 = KernelMixtureDistribution[data, Automatic, "Biweight"];ExclusionsオプションをNoneに設定することで大きいギャップができずプロットにかかる時間も短縮することができる:
{Timing[Plot[PDF[𝒟, x], {x, -4, 4}]], Timing[Plot[PDF[𝒟, x], {x, -4, 4}, Exclusions -> None]]}おもしろい例題 (2)
KernelMixtureDistributionを使ってガウスぼかしを二値化画像に適用する:
img = Binarize[Import["ExampleData/spikey.tiff"]]data = Position[Reverse /@ Transpose@ImageData[img], 1];dist = KernelMixtureDistribution[N@data, {2, 2}];DensityPlot[Evaluate@PDF[dist, {x, y}], {x, 0, 120}, {y, 0, 120}, Evaluated -> True, PlotRange -> All, PlotPoints -> 100, ColorFunction -> "SolarColors", Frame -> False]//Quietdata = Flatten[Table[Subscript[t, Sequence@@{i, j, k}], {i, 3}, {j, 3}, {k, 3}], 1]dist = KernelMixtureDistribution[data, {Subscript[h, 1], Subscript[h, 2], Subscript[h, 3]}, k[#]&];PDF[dist, {x, y, z}]//TraditionalForm関連するガイド
-
▪
- ノンパラメトリック統計分布 ▪
- 確率変数 ▪
- 表形式モデリング
テキスト
Wolfram Research (2010), KernelMixtureDistribution, Wolfram言語関数, https://reference.wolfram.com/language/ref/KernelMixtureDistribution.html (2016年に更新).
CMS
Wolfram Language. 2010. "KernelMixtureDistribution." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/KernelMixtureDistribution.html.
APA
Wolfram Language. (2010). KernelMixtureDistribution. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/KernelMixtureDistribution.html
BibTeX
@misc{reference.wolfram_2026_kernelmixturedistribution, author="Wolfram Research", title="{KernelMixtureDistribution}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/KernelMixtureDistribution.html}", note=[Accessed: 26-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_kernelmixturedistribution, organization={Wolfram Research}, title={KernelMixtureDistribution}, year={2016}, url={https://reference.wolfram.com/language/ref/KernelMixtureDistribution.html}, note=[Accessed: 26-November-2026]}