Main Content

内核分布

概述

内核分布是随机变量的概率密度函数(PDF)的非参数表示。当参数分布无法正确描述数据时,或者当您想避免对数据分布做出假设时,您可以使用内核分布。内核分布由平滑函数和带宽值定义,该值控制所得密度曲线的平滑度。

kernel Density Estimator

内核密度估计器是随机变量的估计PDF。对于任何实际价值X,,,,the kernel density estimator's formula is given by

F ^ H (( X = 1 n H 一世 = 1 n k (( X - X 一世 H ,,,,

在哪里X1,,,,X2,…,,Xn是来自未知分布的随机样品,n是样本量, k (( · 一世s the kernel smoothing function, andH是带宽。

kernel Smoothing Function

The kernel smoothing function defines the shape of the curve used to generate the pdf. Similar to a histogram, the kernel distribution builds a function to represent the probability distribution using the sample data. But unlike a histogram, which places the values into discrete bins, a kernel distribution sums the component smoothing functions for each data value to produce a smooth, continuous probability curve. The following plots show a visual comparison of a histogram and a kernel distribution generated from the same sample data.

直方图通过建立垃圾箱并将每个数据值放置在适当的垃圾箱中来表示概率分布。

6mpg=[13;15;23;29;32;34]; figure histogram(SixMPG)

图包含一个轴对象。轴对象包含类型直方图的对象。

由于这种BIN计数方法,直方图产生离散的概率密度函数。这可能不适合某些应用程序,例如从拟合分布中生成随机数。

Alternatively, the kernel distribution builds the pdf by creating an individual probability density curve for each data value, then summing the smooth curves. This approach creates one smooth, continuous probability density function for the data set.

图PDSIX = FITDIST(六mpg,'核心',,,,'Width',4);x = 0:.1:45;ysix = pdf(pdsix,x);情节(x,ysix,'k-',,,,'行宽',,,,2)% Plot each individual pdf and scale its appearance on the plot抓住on为了i = 1:6 pd = makedist('普通的',,,,'mu',六mpg(i),'Sigma',4);y = pdf(pd,x); y = y/6; plot(x,y,'b:'结尾抓住off

图包含一个轴对象。The axes object contains 7 objects of type line.

较小的虚线曲线是样本数据中每个值的概率分布,缩放以适合图。较大的实心曲线是总体内核分布6mpg数据。内核平滑函数是指在此示例中具有正态分布的那些较小组件曲线的形状。

You can choose one of several options for the kernel smoothing function. This plot shows the shapes of the available smoothing functions.

%设置图规格Hname = {'普通的''epanechnikov''盒子''三角形'};颜色= {'r''b''G''m'};lines = {' - ',,,,' - 。',,,,' - ',,,,':'};% Generate a sample of each kernel smoothing function and plotdata = [0];数字为了j = 1:4 pd = fitdist(数据,'kernel',,,,'核心',,,,Hname{j}); x = -3:.1:3; y = pdf(pd,x); plot(x,y,'Color',颜色{j},'LineStyle',行{j})保持on结尾传奇(hname)保留off

图包含一个轴对象。轴对象包含4个类型行的对象。这些对象代表正常的epanechnikov,盒子,三角形。

要了解不同内核平滑函数对所得PDF估计的形状的影响,请比较里程数据的图(MPG) 从Carbig.mat使用每个可用的内核功能。

加载卡比格%设置图规格Hname = {'普通的''epanechnikov''盒子''三角形'};颜色= {'r''b''G''m'};lines = {' - ',,,,' - 。',,,,' - ',,,,':'};%生成内核分布对象和图数字为了j = 1:4 pd = fitdist(mpg,'kernel',,,,'核心',,,,Hname{j}); x = -10:1:60; y = pdf(pd,x); plot(x,y,'Color',颜色{j},'LineStyle',行{j})保持on结尾传奇(hname)保留off

图包含一个轴对象。轴对象包含4个类型行的对象。这些对象代表正常的epanechnikov,盒子,三角形。

每个密度曲线都使用相同的输入数据,但应用了不同的内核平滑函数来生成PDF。密度估计值大致可比较,但是每条曲线的形状略有变化。例如,盒子内核产生的密度曲线不如其他曲线光滑。

带宽

带宽值的选择控制所得概率密度曲线的平滑度。该图显示了密度估计值MPGdata, using a normal kernel smoothing function with three different bandwidths.

%创建内核分销对象加载卡比格pd1 = fitdist(MPG,'kernel'); pd2 = fitdist(MPG,'kernel',,,,'Width',1);pd3 = fitdist(mpg,'kernel',,,,'Width',5);% Compute each pdfX=-10:1:60; y1 = pdf(pd1,x); y2 = pdf(pd2,x); y3 = pdf(pd3,x);%绘制每个PDF情节(x,y1,'Color',,,,'r',,,,'LineStyle',,,,' - ')抓住on情节(x,y2,'Color',,,,'k',,,,'LineStyle',,,,':')图(x,y3,'Color',,,,'b',,,,'LineStyle',,,,' - ')legend({'带宽=默认值',,,,'带宽= 1',,,,'Bandwidth = 5'}) 抓住off

图包含一个轴对象。The axes object contains 3 objects of type line. These objects represent Bandwidth = Default, Bandwidth = 1, Bandwidth = 5.

The default bandwidth, which is theoretically optimal for estimating densities for the normal distribution[1],产生相当光滑的曲线。指定较小的带宽会产生非常粗糙的曲线,但显示数据中可能有两个主要峰。指定较大的带宽会产生与内核函数几乎相同的曲线,并且非常平滑,以至于它掩盖了数据的潜在重要特征。

References

[1] Bowman, A. W., and A. Azzalini.应用平滑技术用于数据分析。New York: Oxford University Press Inc., 1997.

也可以看看

|

Related Topics