核密度估计(KDE)(二)

核密度估计(KDE)(二)

Author: Rotch
Date: 2025-08-31
Update: 2025-09-04

1. 自适应带宽选择

在前文中,KDE 算法要求各样本点共用同一带宽,即认为各样本点的影响大小、影响范围是一样的. 但在实际生活中,这一假设并不总是成立.

以某一大型区域的便利店服务研究为例:在城市中,人口密集、各类设施丰富,便利店分布较为密集. 但每家便利店主要服务对象仅为周边一小片区域的居民,影响范围小;而在乡村中,人口相对分散,便利店数量较少,一家便利店往往要服务整个村子甚至邻近几个村落的居民,服务范围就大得多. 在这种情况下,位于高密度区域的样本点的影响范围应该更小;位于低密度区域的样本点的影响范围应该更大. 于是我们给出如下自适应修正模型:

对于某一初始带宽 <math xmlns="http://www.w3.org/1998/Math/MathML"> h h </math>h,计算其密度估计函数:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f ^ h ( x ) = 1 n ∑ i = 1 n 1 h K ( x − x ( i ) h ) . \begin{equation} \hat{f}h(x) = \frac{1}{n} \sum\limits{i = 1}^{n} \frac{1}{h} K \left( \frac{x - x^{(i)}}{h} \right). \end{equation} </math>f^h(x)=n1i=1∑nh1K(hx−x(i)).

在此基础上,引入带宽修正公式:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> h i = h F f ^ h ( x ( i ) ) , \begin{equation} h_i = h \sqrt{\frac{F}{\hat{f}_h(x^{(i)})}}, \end{equation} </math>hi=hf^h(x(i))F ,

其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> F = [ ∏ i = 1 n f ^ h ( x ( i ) ) ] 1 / n F = \left[ \prod\limits_{i = 1}^{n} \hat{f}h \left( x^{(i)} \right) \right]^{1 / n} </math>F=[i=1∏nf^h(x(i))]1/n,最终得到修正后的密度估计函数:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f ^ ( x ) = 1 n ∑ i = 1 n 1 h i K ( x − x ( i ) h i ) . \begin{equation} \hat{f}(x) = \frac{1}{n} \sum\limits
{i = 1}^{n} \frac{1}{h_i} K \left( \frac{x - x^{(i)}}{h_i} \right). \end{equation} </math>f^(x)=n1i=1∑nhi1K(hix−x(i)).

对于其它问题,可运用此类思想对带宽进行自适应修正.

2. 多元 KDE 算法

2.1 多元 KDE 算法引入

基于一元 KDE 的基本原理,我们可以将 KDE 推广到 <math xmlns="http://www.w3.org/1998/Math/MathML"> d ( d ∈ N + ) d \space (d \in \mathbb{N}_+) </math>d (d∈N+) 元情况.

<math xmlns="http://www.w3.org/1998/Math/MathML"> Def 2.1 多元核函数: \color{blue}{\textbf{Def 2.1 多元核函数: }} </math>Def 2.1 多元核函数: 一个多元核函数 <math xmlns="http://www.w3.org/1998/Math/MathML"> K : R d → [ 0 , + ∞ ) K: \mathbb{R}^d \to [0, +\infty) </math>K:Rd→[0,+∞) 是一个实值函数,满足以下三条性质:

  1. 非负性 : <math xmlns="http://www.w3.org/1998/Math/MathML"> K ( u ) ≥ 0 K(\boldsymbol{u}) \geq 0 </math>K(u)≥0 对任意的 <math xmlns="http://www.w3.org/1998/Math/MathML"> u ∈ R d \boldsymbol{u} \in \mathbb{R}^d </math>u∈Rd;
  2. 归一性 : <math xmlns="http://www.w3.org/1998/Math/MathML"> ∫ R d K ( u ) d u = 1 \int_{\mathbb{R}^d} K(\boldsymbol{u}) \mathrm{d}\boldsymbol{u} = 1 </math>∫RdK(u)du=1;
  3. 对称性 : <math xmlns="http://www.w3.org/1998/Math/MathML"> K ( − u ) = K ( u ) K(-\boldsymbol{u}) = K(\boldsymbol{u}) </math>K(−u)=K(u) 对任意的 <math xmlns="http://www.w3.org/1998/Math/MathML"> u ∈ R d \boldsymbol{u} \in \mathbb{R}^d </math>u∈Rd.

以下给出了常见的多元核函数及其公式:

核函数 <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 元核公式
<math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 元高斯核 <math xmlns="http://www.w3.org/1998/Math/MathML"> K ( u ) = 1 ( 2 π ) d / 2 exp ⁡ ( − 1 2 u T u ) K(\boldsymbol{u}) = \frac{1}{(2 \pi)^{d / 2}} \exp(-\frac{1}{2} \boldsymbol{u}^\mathrm{T}\boldsymbol{u}) </math>K(u)=(2π)d/21exp(−21uTu)
<math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 元 Epanechnikov 核 <math xmlns="http://www.w3.org/1998/Math/MathML"> K ( u ) = { d + 2 2 V d ( 1 − u T u ) , if ∣ u ∣ < 1 0 , otherwise K(\boldsymbol{u}) = \begin{cases} \frac{d + 2}{2 V_d}(1 - \boldsymbol{u}^\mathrm{T}\boldsymbol{u}), & \text{if } \vert \boldsymbol{u} \vert < 1 \\ 0, & \text{otherwise}\end{cases} </math>K(u)={2Vdd+2(1−uTu),0,if ∣u∣<1otherwise
<math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 元均匀核 <math xmlns="http://www.w3.org/1998/Math/MathML"> K ( u ) = { 1 V d , if ∣ u ∣ < 1 0 , otherwise K(\boldsymbol{u}) = \begin{cases} \frac{1}{V_d}, & \text{if } \vert \boldsymbol{u} \vert < 1 \\ 0, & \text{otherwise}\end{cases} </math>K(u)={Vd1,0,if ∣u∣<1otherwise

其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> V d = π d / 2 Γ ( d 2 + 1 ) V_d = \frac{\pi^{d/2}}{\Gamma(\frac{d}{2} + 1)} </math>Vd=Γ(2d+1)πd/2 是 <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 维单位球体积.

根据一元 KDE 的基本思想,我们很容易得到下述公式:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> p ( x ) ≈ 1 n h d V d ⋅ ∑ i = 1 n 1 ( 1 h ∣ x − x ( i ) ∣ ≤ 1 ) = 1 n ⋅ ∑ i = 1 n det ⁡ H 1 2 ⋅ K [ H − 1 2 ( x − x ( i ) ) ] = p ^ ( x ) , \begin{align} p(\boldsymbol{x}) &\approx \frac{1}{n h^d V_d} \cdot \sum\limits_{i = 1}^{n} \mathbb{1} \left( \frac{1}{h} \vert \boldsymbol{x} - \boldsymbol{x}^{(i)} \vert \leq 1 \right) \nonumber \\ &= \frac{1}{n} \cdot \sum\limits_{i = 1}^{n} \det \boldsymbol{H}^{\frac{1}{2}} \cdot K \left[ \boldsymbol{H}^{-\frac{1}{2}} \left(\boldsymbol{x} - \boldsymbol{x}^{(i)} \right) \right] = \hat{p}(\boldsymbol{x}), \end{align} </math>p(x)≈nhdVd1⋅i=1∑n1(h1∣x−x(i)∣≤1)=n1⋅i=1∑ndetH21⋅K[H−21(x−x(i))]=p^(x),

其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> H = h 2 I d \boldsymbol{H} = h^2 \boldsymbol{I}d </math>H=h2Id, <math xmlns="http://www.w3.org/1998/Math/MathML"> I d \boldsymbol{I}d </math>Id 是 <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 阶单位矩阵, <math xmlns="http://www.w3.org/1998/Math/MathML"> K ( u ) = 1 V d 1 ( ∥ u ∥ 2 ≤ 1 ) K(\boldsymbol{u}) = \frac{1}{V_d} \mathbb{1} \left( \parallel \boldsymbol{u} \parallel_2 \leq 1 \right) </math>K(u)=Vd11(∥u∥2≤1) 是 <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 元均匀核. 容易验证:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∫ R d p ^ ( x ) d x = 1 n ∑ i = 1 n ∫ R d det ⁡ H 1 2 ⋅ K [ H − 1 2 ( x − x ( i ) ) ] d x = 1. \begin{equation} \int
\mathbb{R^d} \hat{p}(\boldsymbol{x}) \mathrm{d}\boldsymbol{x} = \frac{1}{n} \sum\limits
{i = 1}^{n} \int_\mathbb{R^d} \det \boldsymbol{H}^{\frac{1}{2}} \cdot K \left[ \boldsymbol{H}^{-\frac{1}{2}} \left(\boldsymbol{x} - \boldsymbol{x}^{(i)} \right) \right] \mathrm{d}\boldsymbol{x} = 1. \end{equation} </math>∫Rdp^(x)dx=n1i=1∑n∫RddetH21⋅K[H−21(x−x(i))]dx=1.

若将上式中的 <math xmlns="http://www.w3.org/1998/Math/MathML"> K ( x ) K(x) </math>K(x) 替换为其它核函数,得到的 <math xmlns="http://www.w3.org/1998/Math/MathML"> p ^ ( x ) \hat{p}(\boldsymbol{x}) </math>p^(x) 仍为概率密度函数. 下面我们将对 <math xmlns="http://www.w3.org/1998/Math/MathML"> H \boldsymbol{H} </math>H 进行进一步的讨论:

首先,样本的不同维度的数据规模不同,适用的带宽也不同,因此,我们可以对 <math xmlns="http://www.w3.org/1998/Math/MathML"> H \boldsymbol{H} </math>H 进行扩展:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> H = d i a g ( h 1 2 , h 2 2 , ... , h d 2 ) . \begin{equation} \boldsymbol{H} = \mathrm{diag}(h_1^2, h_2^2, \dots, h_d^2). \end{equation} </math>H=diag(h12,h22,...,hd2).

这样的 <math xmlns="http://www.w3.org/1998/Math/MathML"> H \boldsymbol{H} </math>H 是十分容易参与计算的,其几何意义也十分明显:样本点的各维度彼此独立,各自享用自己的带宽. 如果各维度并不彼此独立,则可考虑使用样本的协方差矩阵构建带宽矩阵:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> H C o v = Σ + ε I . \begin{equation} \boldsymbol{H}_{\mathrm{Cov}} = \boldsymbol{\Sigma} + \varepsilon \boldsymbol{I}. \end{equation} </math>HCov=Σ+εI.

其中参数 <math xmlns="http://www.w3.org/1998/Math/MathML"> ε > 0 \varepsilon > 0 </math>ε>0 起微小扰动作用,避免协方差矩阵 <math xmlns="http://www.w3.org/1998/Math/MathML"> Σ \boldsymbol{\Sigma} </math>Σ 半正定.

2.2 多元 KDE 算法

<math xmlns="http://www.w3.org/1998/Math/MathML"> Algorithm: Multivariate Kernel Density Estimation \color{blue}{\textbf{Algorithm: Multivariate Kernel Density Estimation}} </math>Algorithm: Multivariate Kernel Density Estimation 设 <math xmlns="http://www.w3.org/1998/Math/MathML"> S = ( x ( 1 ) , x ( 2 ) , . . . , x ( n ) ) \mathcal{S} = (\boldsymbol{x}^{(1)}, \boldsymbol{x}^{(2)}, ..., \boldsymbol{x}^{(n)}) </math>S=(x(1),x(2),...,x(n)) 是从总体中抽取的一组独立同分布(i.i.d.)样本数据, <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( i ) ∈ R d \boldsymbol{x}^{(i)} \in \mathbb{R}^d </math>x(i)∈Rd, <math xmlns="http://www.w3.org/1998/Math/MathML"> K ( x ) K(\boldsymbol{x}) </math>K(x) 是给定的 <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 元核函数, <math xmlns="http://www.w3.org/1998/Math/MathML"> H ∈ S P D ( R , d ) \boldsymbol{H} \in \mathrm{SPD}(\mathbb{R}, d) </math>H∈SPD(R,d) 为给定( <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 阶实正定)带宽矩阵,则核密度估计给出的概率密度估计函数为:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f ^ H ( x ) = 1 n det ⁡ H 1 / 2 ∑ i = 1 n K ( H − 1 / 2 ( x − x ( i ) ) ) = 1 n ∑ i = 1 n K H ( x − x ( i ) ) . \begin{equation} \hat{f}{\boldsymbol{H}}(\boldsymbol{x}) = \frac{1}{n \det \boldsymbol{H}^{1/2}} \sum\limits{i = 1}^{n} K \left( \boldsymbol{H}^{-1/2} (\boldsymbol{x} - \boldsymbol{x}^{(i)}) \right) = \frac{1}{n} \sum\limits_{i = 1}^{n} K_{\boldsymbol{H}}(\boldsymbol{x} - \boldsymbol{x}^{(i)}). \end{equation} </math>f^H(x)=ndetH1/21i=1∑nK(H−1/2(x−x(i)))=n1i=1∑nKH(x−x(i)).

在这里,我们继续引入积核(Product Kernel)的概念:

<math xmlns="http://www.w3.org/1998/Math/MathML"> Def 2.2 积核: \color{blue}{\textbf{Def 2.2 积核: }} </math>Def 2.2 积核: 设 <math xmlns="http://www.w3.org/1998/Math/MathML"> K 1 , K 2 , ... , K d K_1, K_2, \dots, K_d </math>K1,K2,...,Kd 是 <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 个一元核函数,定义多元核函数 <math xmlns="http://www.w3.org/1998/Math/MathML"> K : R d → [ 0 , + ∞ ) K: \mathbb{R}^d \to [0, +\infty) </math>K:Rd→[0,+∞) 满足:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> K ( u ) = ∏ k = 1 d K k ( u k ) , \begin{equation} K(\boldsymbol{u}) = \prod_{k=1}^{d} K_k(u_k), \end{equation} </math>K(u)=k=1∏dKk(uk),

其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> u = ( u 1 , u 2 , ... , u d ) T ∈ R d \boldsymbol{u} = (u_1, u_2, \dots, u_d)^\mathrm{T} \in \mathbb{R}^d </math>u=(u1,u2,...,ud)T∈Rd,则称 <math xmlns="http://www.w3.org/1998/Math/MathML"> K K </math>K 为基于 <math xmlns="http://www.w3.org/1998/Math/MathML"> K 1 , K 2 , ... , K d K_1, K_2, \dots, K_d </math>K1,K2,...,Kd 的积核.

显然, <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 元 Gauss 核是 <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 个一元 Gauss 核函数的积核. 使用积核的一个好处是其支持并行计算;此外,在需要调整带宽、增加估计点时,积核方法的计算复用性显著高于非积核方法.

我们接下来讨论多元 KDE 算法的渐进性质,将原来的三条假设推广至多元:

  1. 假设 <math xmlns="http://www.w3.org/1998/Math/MathML"> f ∈ C 2 ( R d ) f \in C^2(\mathbb{R^d}) </math>f∈C2(Rd) 且其二阶导数 <math xmlns="http://www.w3.org/1998/Math/MathML"> ∇ 2 f \nabla^2f </math>∇2f 平方可积,记为 <math xmlns="http://www.w3.org/1998/Math/MathML"> R ( ∇ 2 f ) = ∫ R d [ ∇ 2 f ( x ) ] 2 d x R(\nabla^2 f) = \int_{\mathbb{R}^d} \left [ \nabla^2f(\boldsymbol{x}) \right]^2 \mathrm{d}\boldsymbol{x} </math>R(∇2f)=∫Rd[∇2f(x)]2dx;

  2. 假设核函数 <math xmlns="http://www.w3.org/1998/Math/MathML"> K K </math>K 二阶矩存在且平方可积,分别记为 <math xmlns="http://www.w3.org/1998/Math/MathML"> μ 2 ( K ) = ∫ R d u u T K ( u ) d u \mu_2(K) = \int_{\mathbb{R}^d} \boldsymbol{u} \boldsymbol{u}^\mathrm{T} K(\boldsymbol{u}) \mathrm{d}\boldsymbol{u} </math>μ2(K)=∫RduuTK(u)du, <math xmlns="http://www.w3.org/1998/Math/MathML"> R ( K ) = ∫ R d K 2 ( u ) d u R(K) = \int_{\mathbb{R}^d} K^2(\boldsymbol{u}) \mathrm{d}\boldsymbol{u} </math>R(K)=∫RdK2(u)du;

  3. 记 <math xmlns="http://www.w3.org/1998/Math/MathML"> H = H n \boldsymbol{H} = \boldsymbol{H}_n </math>H=Hn,假设 <math xmlns="http://www.w3.org/1998/Math/MathML"> n → ∞ n \rightarrow \infty </math>n→∞ 且 <math xmlns="http://www.w3.org/1998/Math/MathML"> H → 0 + \boldsymbol{H} \rightarrow 0^+ </math>H→0+ 时满足 <math xmlns="http://www.w3.org/1998/Math/MathML"> n det ⁡ H 1 / 2 → + ∞ n\det \boldsymbol{H}^{1/2} \rightarrow +\infty </math>ndetH1/2→+∞.

利用多元 Taylor 定理及一元 KDE 渐进性质的分析思路,我们可以得到(不做证明):
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> B i a s [ f ^ ( x ) ] = 1 2 μ 2 ( K ) [ v e c ( H [ f ( x ) ] ) ] T ⋅ v e c ( H ) + o ( ∣ v e c ( H ) ∣ ) , V a r [ f ^ ( x ) ] = R ( K ) n det ⁡ H 1 / 2 f ( x ) + o [ 1 n det ⁡ H 1 / 2 ] . \begin{align} \mathrm{Bias}\left[\hat{f}(\boldsymbol{x})\right] &= \frac{1}{2} \mu_2(K) \left[ \mathrm{vec} \left (\mathrm{H} [f(\boldsymbol{x})] \right) \right]^\mathrm{T} \cdot \mathrm{vec}(\boldsymbol{H}) + o\left( \vert \mathrm{vec}(\boldsymbol{H}) \vert \right), \\ \mathrm{Var}\left[\hat{f}(\boldsymbol{x})\right] &= \frac{R(K)}{n \det\boldsymbol{H}^{1/2}}f(\boldsymbol{x}) + o\left[ \frac{1}{n\det\boldsymbol{H}^{1/2}} \right]. \end{align} </math>Bias[f^(x)]Var[f^(x)]=21μ2(K)[vec(H[f(x)])]T⋅vec(H)+o(∣vec(H)∣),=ndetH1/2R(K)f(x)+o[ndetH1/21].

其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> v e c ( ⋅ ) \mathrm{vec}(\cdot) </math>vec(⋅) 表示将目标 <math xmlns="http://www.w3.org/1998/Math/MathML"> n × m n \times m </math>n×m 矩阵转换为 <math xmlns="http://www.w3.org/1998/Math/MathML"> n m nm </math>nm 阶向量, <math xmlns="http://www.w3.org/1998/Math/MathML"> H ( ⋅ ) \mathrm{H}(\cdot) </math>H(⋅) 表示 Hessian 矩阵.

2.3 带宽选择

带宽选择的基本方法已经在前文叙述,以下仅给出多元情况下的带宽选择公式. 首先我们推广 <math xmlns="http://www.w3.org/1998/Math/MathML"> M S E \mathrm{MSE} </math>MSE 和 <math xmlns="http://www.w3.org/1998/Math/MathML"> M I S E \mathrm{MISE} </math>MISE:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> M S E [ f ^ ( x ) ] = E [ ( f ^ ( x ) − f ( x ) ) 2 ] , M I S E [ f ^ ( x ) ] = ∫ R d M S E [ f ^ ( x ) ] d x \begin{align} \mathrm{MSE} \left[ \hat{f}(\boldsymbol{x}) \right] &= \mathbb{E}\left[ \left( \hat{f}(\boldsymbol{x}) - f(\boldsymbol{x}) \right)^2 \right], \\ \mathrm{MISE} \left[ \hat{f}(\boldsymbol{x}) \right] &= \int_{\mathbb{R}^d} \mathrm{MSE} \left[ \hat{f}(\boldsymbol{x}) \right] \mathrm{d}\boldsymbol{x} \end{align} </math>MSE[f^(x)]MISE[f^(x)]=E[(f^(x)−f(x))2],=∫RdMSE[f^(x)]dx

它们的渐进形式为:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> A M S E [ f ^ ( x ) ] = R ( K ) n det ⁡ H 1 / 2 f ( x ) + 1 4 μ 2 2 ( K ) t r 2 ( H H [ f ( x ) ] ) , A M I S E [ f ^ ( x ) ] = ∫ R A M S E ( x ) d x = 1 4 μ 2 2 ( K ) R [ t r ( H H [ f ( x ) ] ) ] + R ( K ) n det ⁡ H 1 / 2 . \begin{align} \mathrm{AMSE} \left[ \hat{f}(\boldsymbol{x}) \right] &= \frac{R(K)}{n \det\boldsymbol{H}^{1/2}}f(\boldsymbol{x}) + \frac{1}{4} \mu_2^2(K) \mathrm{tr}^2(\boldsymbol{H} \mathrm{H}[f(\boldsymbol{x})]), \\ \mathrm{AMISE} \left[ \hat{f}(\boldsymbol{x}) \right] &= \int_{\mathbb{R}} \mathrm{AMSE}(\boldsymbol{x}) \mathrm{d}\boldsymbol{x} = \frac{1}{4} \mu_2^2(K) R\left[ \mathrm{tr}(\boldsymbol{H} \mathrm{H}[f(\boldsymbol{x})]) \right] + \frac{R(K)}{n \det\boldsymbol{H}^{1/2}}. \end{align} </math>AMSE[f^(x)]AMISE[f^(x)]=ndetH1/2R(K)f(x)+41μ22(K)tr2(HH[f(x)]),=∫RAMSE(x)dx=41μ22(K)R[tr(HH[f(x)])]+ndetH1/2R(K).

其中用到了一个定理:

<math xmlns="http://www.w3.org/1998/Math/MathML"> Thm 2.4: \color{blue}{\textbf{Thm 2.4: }} </math>Thm 2.4: <math xmlns="http://www.w3.org/1998/Math/MathML"> A , B ∈ R n × n A, B \in \mathbb{R}^{n \times n} </math>A,B∈Rn×n, <math xmlns="http://www.w3.org/1998/Math/MathML"> v e c ( A ) T v e c ( B ) = t r ( A T B ) \mathrm{vec}(A)^{\mathrm{T}} \mathrm{vec}(B) = \mathrm{tr}\left( A^{\mathrm{T}} B \right) </math>vec(A)Tvec(B)=tr(ATB).

<math xmlns="http://www.w3.org/1998/Math/MathML"> Proof: \color{brown}{\textbf{Proof: }} </math>Proof: 设 <math xmlns="http://www.w3.org/1998/Math/MathML"> A = [ a i j ] A = \left[ a_{ij} \right] </math>A=[aij], <math xmlns="http://www.w3.org/1998/Math/MathML"> B = [ b i j ] B = \left[ b_{ij} \right] </math>B=[bij], <math xmlns="http://www.w3.org/1998/Math/MathML"> C = A T B = [ c i j ] C = A^\mathrm{T}B = \left[ c_{ij} \right] </math>C=ATB=[cij]有:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> c i j = ∑ k = 1 n a k i b k j . \begin{equation} c_{ij} = \sum\limits_{k = 1}^{n} a_{ki} b_{kj}. \end{equation} </math>cij=k=1∑nakibkj.

于是:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> t r C = ∑ i = 1 n c i i = ∑ i = 1 n ∑ k = 1 n a k i b k i = v e c ( A ) T v e c ( B ) . □ \begin{equation} \mathrm{tr} C = \sum\limits_{i = 1}^{n} c_{ii} = \sum\limits_{i = 1}^{n} \sum\limits_{k = 1}^{n} a_{ki} b_{ki} = \mathrm{vec}(A)^{\mathrm{T}} \mathrm{vec}(B). \square \end{equation} </math>trC=i=1∑ncii=i=1∑nk=1∑nakibki=vec(A)Tvec(B).□

于是,渐进意义下的最优带宽为:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> H a s y m − o p t = arg ⁡ min ⁡ H ∈ S P D ( R , d ) A M I S E [ f ^ ( x ) ] \begin{equation} \boldsymbol{H}{\mathrm{asym-opt}} = \arg \mathop{\min}\limits{\boldsymbol{H} \in \mathrm{SPD}(\mathbb{R}, d)} \mathrm{AMISE}\left[ \hat{f}(\boldsymbol{x}) \right] \end{equation} </math>Hasym−opt=argH∈SPD(R,d)minAMISE[f^(x)]

与一元 KDE 不同,通过上式无法求出 <math xmlns="http://www.w3.org/1998/Math/MathML"> H a s y m − o p t \boldsymbol{H}_{\mathrm{asym-opt}} </math>Hasym−opt 的表达式. 但是特别地,若 <math xmlns="http://www.w3.org/1998/Math/MathML"> H = h 2 I d \boldsymbol{H} = h^2 \boldsymbol{I}_d </math>H=h2Id,则:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> R ( t r ( H H [ f ( x ) ] ) ) = h 4 R ( t r ( H [ f ( x ) ] ) \begin{equation} R\left(\mathrm{tr}(\boldsymbol{H} \mathrm{H}[f(\boldsymbol{x})])\right) = h^4 R\left(\mathrm{tr}(\mathrm{H}[f(\boldsymbol{x})]\right) \end{equation} </math>R(tr(HH[f(x)]))=h4R(tr(H[f(x)])

将 <math xmlns="http://www.w3.org/1998/Math/MathML"> ( 29 ) (29) </math>(29) 带入 <math xmlns="http://www.w3.org/1998/Math/MathML"> ( 25 ) (25) </math>(25),对 <math xmlns="http://www.w3.org/1998/Math/MathML"> A M I S E [ f ^ ( x ) ] \mathrm{AMISE} \left[ \hat{f}(\boldsymbol{x}) \right] </math>AMISE[f^(x)] 关于 <math xmlns="http://www.w3.org/1998/Math/MathML"> h h </math>h 求导,得:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∇ h A M I S E [ f ^ ( x ) ] = h 3 μ 2 2 ( K ) R ( t r ( H [ f ( x ) ] ) − d R ( K ) n h d + 1 . \begin{equation} \nabla_h \mathrm{AMISE} \left[ \hat{f}(\boldsymbol{x}) \right] = h^3 \mu_2^2(K) R\left(\mathrm{tr}(\mathrm{H}[f(\boldsymbol{x})]\right) - \frac{dR(K)}{nh^{d + 1}}. \end{equation} </math>∇hAMISE[f^(x)]=h3μ22(K)R(tr(H[f(x)])−nhd+1dR(K).

令 <math xmlns="http://www.w3.org/1998/Math/MathML"> ∇ h A M I S E [ f ^ ( x ) ] = 0 \nabla_h \mathrm{AMISE} \left[ \hat{f}(\boldsymbol{x}) \right] = 0 </math>∇hAMISE[f^(x)]=0,有:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> h a s y m − o p t = ( d R ( K ) μ 2 2 ( K ) R ( t r ( H [ f ( x ) ] ) n ) 1 / ( d + 4 ) . \begin{equation} h_{\mathrm{asym-opt}} = \left( \frac{dR(K)}{\mu_2^2(K) R\left(\mathrm{tr}(\mathrm{H}[f(\boldsymbol{x})]\right) n} \right)^{1 / (d + 4)}. \end{equation} </math>hasym−opt=(μ22(K)R(tr(H[f(x)])ndR(K))1/(d+4).

尽管 <math xmlns="http://www.w3.org/1998/Math/MathML"> ( 34 ) (34) </math>(34) 依赖于大量化简,但其揭示了一个重要的规律:当 <math xmlns="http://www.w3.org/1998/Math/MathML"> d d </math>d 增大时,最优带宽 <math xmlns="http://www.w3.org/1998/Math/MathML"> h a s y m − o p t h_{\mathrm{asym-opt}} </math>hasym−opt 也会增大. 此外,我们发现 <math xmlns="http://www.w3.org/1998/Math/MathML"> ( 34 ) (34) </math>(34) 的计算也面临着和一元 KDE 同样的问题:起计算依赖于关于真实密度函数 <math xmlns="http://www.w3.org/1998/Math/MathML"> f f </math>f 的泛函. 我们首先采取和 Silverman 方法 一致的思想,用正态分布函数来近似 <math xmlns="http://www.w3.org/1998/Math/MathML"> f f </math>f,得到(不作具体计算):
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> H N S = ( 4 p + 2 ) 2 / ( p + 4 ) n − 2 / ( p + 4 ) ⋅ Σ \begin{equation} \boldsymbol{H}_{\mathrm{NS}} = \left( \frac{4}{p + 2} \right)^{2 / (p + 4)} n^{-2 / (p + 4)} \cdot \boldsymbol{\Sigma} \end{equation} </math>HNS=(p+24)2/(p+4)n−2/(p+4)⋅Σ

在前文中,我们还提到了插入法. 对于多元 KDE,其插入法推导思路与一元 KDE 无异,但各阶段最优带宽 <math xmlns="http://www.w3.org/1998/Math/MathML"> G \boldsymbol{G} </math>G 没有明确的公式,不适合实际计算,这里不再展开. 接下来我们讨论交叉验证法,交叉验证法可以很好地适应多元情况.

留一交叉验证法可以表述为:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> L O O C V ( H ) = ∫ R f ^ H 2 ( x ) d x − 2 n ∑ j = 1 n f ^ H , − j ( x ( j ) ) , H L O O C V = arg ⁡ min ⁡ H ∈ S P D ( R , d ) L O O C V ( H ) . \begin{align} \mathrm{LOOCV}(\boldsymbol{H}) &= \int_{\mathbb{R}} \hat{f}{\boldsymbol{H}}^2 (\boldsymbol{x}) \mathrm{d}\boldsymbol{x} - \frac{2}{n} \sum\limits{j = 1}^{n} \hat{f}{\boldsymbol{H}, -j}(\boldsymbol{x}^{(j)}), \\ \boldsymbol{H}{\mathrm{LOOCV}} &= \arg \mathop{\min}\limits_{\boldsymbol{H} \in \mathrm{SPD}(\mathbb{R}, d)} \mathrm{LOOCV}\left( \boldsymbol{H} \right). \end{align} </math>LOOCV(H)HLOOCV=∫Rf^H2(x)dx−n2j=1∑nf^H,−j(x(j)),=argH∈SPD(R,d)minLOOCV(H).

有偏交叉验证法可以表述为:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> R ( ∇ 2 f ) ~ = R ( ∇ 2 f ^ ) − 1 n det ⁡ H 5 / 2 R ( ∇ 2 K ) , B C V ( H ) = 1 4 det ⁡ H 2 μ 2 2 ( K ) R ( ∇ 2 f ) ~ + R ( K ) n det ⁡ H 1 / 2 , H B C V = arg ⁡ min ⁡ H ∈ S P D ( R , d ) B C V ( H ) . \begin{align} \widetilde{R(\nabla^2 f)} &= R(\nabla^2 \hat{f}) - \frac{1}{n \det\boldsymbol{H}^{5 / 2}} R(\nabla^2 K), \\ \mathrm{BCV}(\boldsymbol{H}) &= \frac{1}{4}\det\boldsymbol{H}^2 \mu_2^2(K) \widetilde{R(\nabla^2 f)} + \frac{R(K)}{n \det\boldsymbol{H}^{1 / 2}}, \\ \boldsymbol{H}{\mathrm{BCV}} &= \arg \mathop{\min}\limits{\boldsymbol{H} \in \mathrm{SPD}(\mathbb{R}, d)} \mathrm{BCV}\left( \boldsymbol{H} \right). \end{align} </math>R(∇2f) BCV(H)HBCV=R(∇2f^)−ndetH5/21R(∇2K),=41detH2μ22(K)R(∇2f) +ndetH1/2R(K),=argH∈SPD(R,d)minBCV(H).

2.4 多元 KDE 算法下的导数估计

设 <math xmlns="http://www.w3.org/1998/Math/MathML"> f : R d → R f: \mathbb{R}^d \rightarrow \mathbb{R} </math>f:Rd→R 是通过 KDE 算法生成的概率密度函数,我们想讨论其导数. 对于一阶和二阶导数,我们分别有:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∇ f ( x ) = [ ∂ ∂ x k f ( x ) ] k = 1 , 2 , ... , d T ∈ R d , ∇ 2 f ( x ) = H [ f ( x ) ] = [ ∂ 2 ∂ x k ∂ x l f ( x ) ] k , l = 1 , 2 , ... , d T ∈ R d × d . \begin{align} \nabla f(\boldsymbol{x}) &= \left[ \frac{\partial}{\partial x_k} f(\boldsymbol{x}) \right]^\mathrm{T}{k = 1, 2, \dots, d} \in \mathbb{R}^d, \\ \nabla^2 f(\boldsymbol{x}) = \mathrm{H}[f(\boldsymbol{x})] &= \left[ \frac{\partial^2}{\partial x_k \partial x_l} f(\boldsymbol{x}) \right]^\mathrm{T}{k, l = 1, 2, \dots, d} \in \mathbb{R}^{d \times d}. \end{align} </math>∇f(x)∇2f(x)=H[f(x)]=[∂xk∂f(x)]k=1,2,...,dT∈Rd,=[∂xk∂xl∂2f(x)]k,l=1,2,...,dT∈Rd×d.

需要指出的是, <math xmlns="http://www.w3.org/1998/Math/MathML"> ( 29 ) (29) </math>(29) 式是矩阵形式,显然不利于推广到高维,我们利用 Kronecker 积将其转换为向量形式:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∇ ⊗ ∇ f ( x ) = [ ∇ ( ∂ ∂ x k f ( x ) ) ] k = 1 , 2 , ... , d T = [ [ ∂ 2 ∂ x k ∂ x l f ( x ) ] l = 1 , 2 , ... , d T ] k = 1 , 2 , ... , d T ∈ R d 2 . \begin{align} \nabla \otimes \nabla f(\boldsymbol{x}) &= \left[ \nabla \left( \frac{\partial}{\partial x_k} f(\boldsymbol{x}) \right) \right]^\mathrm{T}{k = 1, 2, \dots, d} \nonumber \\ &= \left[ \left[ \frac{\partial^2}{\partial x_k \partial x_l} f(\boldsymbol{x}) \right]^\mathrm{T}{l = 1, 2, \dots, d} \right]^\mathrm{T}_{k = 1, 2, \dots, d} \in \mathbb{R}^{d^2}. \end{align} </math>∇⊗∇f(x)=[∇(∂xk∂f(x))]k=1,2,...,dT=[[∂xk∂xl∂2f(x)]l=1,2,...,dT]k=1,2,...,dT∈Rd2.

我们将上述符号记为 <math xmlns="http://www.w3.org/1998/Math/MathML"> ∇ ⊗ 2 f ( x ) \nabla^{\otimes 2} f(\boldsymbol{x}) </math>∇⊗2f(x). 一般地,我们给出 <math xmlns="http://www.w3.org/1998/Math/MathML"> f ( x ) f(\boldsymbol{x}) </math>f(x) 的 <math xmlns="http://www.w3.org/1998/Math/MathML"> r r </math>r 阶导数:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∇ ⊗ r f ( x ) = [ ∂ r f ( x ) ∂ x 1 ... ∂ x 1 , ... , ∂ r f ( x ) ∂ x 1 ... ∂ x d , ... , ∂ r f ( x ) ∂ x d ... ∂ x d ] T ∈ R d r . \begin{equation} \nabla^{\otimes r} f(\boldsymbol{x}) = \left[ \frac{\partial^r f(\boldsymbol{x})}{\partial x_1 \dots \partial x_1}, \dots, \frac{\partial^r f(\boldsymbol{x})}{\partial x_1 \dots \partial x_d}, \dots, \frac{\partial^r f(\boldsymbol{x})}{\partial x_d \dots \partial x_d} \right]^\mathrm{T} \in \mathbb{R}^{d^r}. \end{equation} </math>∇⊗rf(x)=[∂x1...∂x1∂rf(x),...,∂x1...∂xd∂rf(x),...,∂xd...∂xd∂rf(x)]T∈Rdr.

<math xmlns="http://www.w3.org/1998/Math/MathML"> Lem 2.3 多元 Taylor 定理: \color{blue}{\textbf{Lem 2.3 多元 Taylor 定理: }} </math>Lem 2.3 多元 Taylor 定理: 设 <math xmlns="http://www.w3.org/1998/Math/MathML"> f : R p → R f: \mathbb{R}^p \to \mathbb{R} </math>f:Rp→R, <math xmlns="http://www.w3.org/1998/Math/MathML"> x ∈ R p \boldsymbol{x} \in \mathbb{R}^p </math>x∈Rp。若 <math xmlns="http://www.w3.org/1998/Math/MathML"> f ∈ C r [ B ( x , δ ) ] f \in C^r[B(\boldsymbol{x}, \delta)] </math>f∈Cr[B(x,δ)],则对任意 <math xmlns="http://www.w3.org/1998/Math/MathML"> ∣ h ∣ < δ \vert \boldsymbol{h} \vert < \delta </math>∣h∣<δ,有:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f ( x + h ) = ∑ s = 0 r 1 s ! [ ∇ ⊗ s f ( x ) ] T h ⊗ s + o ( ∣ h ∣ r ) . \begin{equation} f(\boldsymbol{x} + \boldsymbol{h}) = \sum\limits_{s = 0}^r \frac{1}{s!} \left[ \nabla^{\otimes s}f(\boldsymbol{x}) \right]^{\mathrm{T}} \boldsymbol{h}^{\otimes s} + o\left( \vert \boldsymbol{h} \vert^r \right). \end{equation} </math>f(x+h)=s=0∑rs!1[∇⊗sf(x)]Th⊗s+o(∣h∣r).

证明略. 下面给出 <math xmlns="http://www.w3.org/1998/Math/MathML"> f f </math>f 的导数估计量:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∇ ^ ⊗ r f = 1 n ∑ i = 1 n ( ∇ ⊗ r K H ) ( x − x ( i ) ) . \begin{equation} \hat{\nabla}^{\otimes r}f = \frac{1}{n} \sum_{i = 1}^n \left( \nabla^{\otimes r} K_{\boldsymbol{H}} \right)(\boldsymbol{x} - \boldsymbol{x}^{(i)}). \end{equation} </math>∇^⊗rf=n1i=1∑n(∇⊗rKH)(x−x(i)).

其中:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∇ ⊗ r K H = ∣ H ∣ − 1 / 2 ( H − 1 / 2 ) ⊗ r ( ∇ ⊗ r K ) ( H − 1 / 2 ( x − x ( i ) ) ) . \begin{equation} \nabla^{\otimes r} K_{\boldsymbol{H}} = \vert \boldsymbol{H} \vert^{-1/2} \left( \boldsymbol{H}^{-1/2} \right)^{\otimes r} \left( \nabla^{\otimes r}K \right)\left( \boldsymbol{H}^{-1/2}(\boldsymbol{x} - \boldsymbol{x^{(i)}}) \right). \end{equation} </math>∇⊗rKH=∣H∣−1/2(H−1/2)⊗r(∇⊗rK)(H−1/2(x−x(i))).

特别地,取 <math xmlns="http://www.w3.org/1998/Math/MathML"> r = 1 r = 1 </math>r=1 时,有:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∇ ^ f ( x ) = H − 1 / 2 n det ⁡ H 1 / 2 ∑ i = 1 n ( ∇ K ) ( H − 1 / 2 ( x − x ( i ) ) ) . \begin{equation} \hat{\nabla} f(\boldsymbol{x}) = \frac{\boldsymbol{H}^{-1/2}}{n \det \boldsymbol{H}^{1/2}} \sum\limits_{i = 1}^n (\nabla K)\left( \boldsymbol{H}^{-1/2} \left( \boldsymbol{x} - \boldsymbol{x^{(i)}} \right) \right). \end{equation} </math>∇^f(x)=ndetH1/2H−1/2i=1∑n(∇K)(H−1/2(x−x(i))).

若定义缩放一阶梯度核函数:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ( ∇ K ) H ( u ) = 1 det ⁡ H 1 / 2 ( ∇ K ) ( H − 1 / 2 ( u ) ) , \begin{equation} (\nabla K)_{\boldsymbol{H}}(\boldsymbol{u}) = \frac{1}{\det \boldsymbol{H}^{1/2}} (\nabla K)\left( \boldsymbol{H}^{-1/2} \left( \boldsymbol{u} \right) \right), \end{equation} </math>(∇K)H(u)=detH1/21(∇K)(H−1/2(u)),

则一阶导数估计量可写作:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∇ ^ f ( x ) = 1 n H − 1 / 2 ∑ i = 1 n ( ∇ K ) H ( x − x ( i ) ) . \begin{equation} \hat{\nabla} f(\boldsymbol{x}) = \frac{1}{n} \boldsymbol{H}^{-1/2} \sum\limits_{i = 1}^n (\nabla K)_{\boldsymbol{H}} \left( \boldsymbol{x} - \boldsymbol{x^{(i)}} \right). \end{equation} </math>∇^f(x)=n1H−1/2i=1∑n(∇K)H(x−x(i)).

对于 <math xmlns="http://www.w3.org/1998/Math/MathML"> r > 1 r > 1 </math>r>1 的讨论我们不多赘述,可根据实际情况进行讨论. 注意到 <math xmlns="http://www.w3.org/1998/Math/MathML"> H − 1 / 2 \boldsymbol{H}^{-1/2} </math>H−1/2 的存在,这说明了 <math xmlns="http://www.w3.org/1998/Math/MathML"> ( 37 ) (37) </math>(37) 的带宽选择不同于 <math xmlns="http://www.w3.org/1998/Math/MathML"> ( 8 ) (8) </math>(8) 的带宽选择,我们给出 <math xmlns="http://www.w3.org/1998/Math/MathML"> r r </math>r 阶导数下 <math xmlns="http://www.w3.org/1998/Math/MathML"> H N S , r \boldsymbol{H}{\mathrm{NS}, r} </math>HNS,r 的表达式(对 <math xmlns="http://www.w3.org/1998/Math/MathML"> A M S E \mathrm{AMSE} </math>AMSE 的推广、Silverman 方法的应用不作叙述):
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> H N S , r = ( 4 p + 2 r + 2 ) 2 / ( p + 2 r + 4 ) n − 2 / ( p + 2 r + 4 ) Σ . \begin{equation} \boldsymbol{H}
{\mathrm{NS},r} = \left(\frac{4}{p + 2r + 2}\right)^{2 / (p + 2r + 4)} n^{-2 / (p + 2r + 4)} \boldsymbol{\Sigma}. \end{equation} </math>HNS,r=(p+2r+24)2/(p+2r+4)n−2/(p+2r+4)Σ.

当 <math xmlns="http://www.w3.org/1998/Math/MathML"> r = 0 r = 0 </math>r=0 时, <math xmlns="http://www.w3.org/1998/Math/MathML"> H N S , 0 \boldsymbol{H}{\mathrm{NS}, 0} </math>HNS,0 退化为 <math xmlns="http://www.w3.org/1998/Math/MathML"> H N S \boldsymbol{H}{\mathrm{NS}} </math>HNS. 随着 <math xmlns="http://www.w3.org/1998/Math/MathML"> r r </math>r 的增大, <math xmlns="http://www.w3.org/1998/Math/MathML"> H N S , r \boldsymbol{H}_{\mathrm{NS},r} </math>HNS,r 也会增大,这表明若使用密度估计的最优带宽来估计导数的最优带宽,会导致导数估计出现"欠平滑"现象.

3. 线特征的核密度估计(KDE-Linear, KDE-L)

线特征(如道路、河流、轨迹、等高线等)是地理信息科学(Geographic Information Science, GIS)、计算机视觉、模式识别等领域中常见的空间数据类型. 与点特征的核密度估计(KDE)不同,线特征的核密度估计需考虑线的连续性、长度、方向等几何属性,核心是通过"核函数"将线特征的空间分布"平滑化",最终生成反映线特征空间集聚程度的密度表面,用于识别线特征的密集区域(如城市路网密集区)或稀疏区域.

在这种意义下,我们不再需要保障最终的密度估计函数 <math xmlns="http://www.w3.org/1998/Math/MathML"> f ^ \hat{f} </math>f^ 满足 <math xmlns="http://www.w3.org/1998/Math/MathML"> ∫ R d f ^ ( x ) d x = 1 \int_{\mathbb{R}^d} \hat{f}(\boldsymbol{x}) \mathrm{d}\boldsymbol{x} = 1 </math>∫Rdf^(x)dx=1,而仅使用 <math xmlns="http://www.w3.org/1998/Math/MathML"> f ^ ( x ) \hat{f}(\boldsymbol{x}) </math>f^(x) 的大小来判断 <math xmlns="http://www.w3.org/1998/Math/MathML"> x \boldsymbol{x} </math>x 处的密度高低.

设 <math xmlns="http://www.w3.org/1998/Math/MathML"> l l </math>l 是一个线特征,为确定 <math xmlns="http://www.w3.org/1998/Math/MathML"> l l </math>l 的概率影响,我们可以采取采样点的方法. 作划分 <math xmlns="http://www.w3.org/1998/Math/MathML"> T : t 0 , t 1 , t 2 , ... , t n T: t_0, t_1, t_2, \dots, t_n </math>T:t0,t1,t2,...,tn,其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> t 0 t_0 </math>t0 是 <math xmlns="http://www.w3.org/1998/Math/MathML"> l l </math>l 的起点, <math xmlns="http://www.w3.org/1998/Math/MathML"> t n t_n </math>tn 是 <math xmlns="http://www.w3.org/1998/Math/MathML"> l l </math>l 的终点, <math xmlns="http://www.w3.org/1998/Math/MathML"> t 0 , t 1 , ... , t n t_0, t_1, \dots, t_n </math>t0,t1,...,tn 依次位于 <math xmlns="http://www.w3.org/1998/Math/MathML"> l l </math>l 上, <math xmlns="http://www.w3.org/1998/Math/MathML"> t i − 1 , t i ‾ \overline{t_{i - 1}, t_i} </math>ti−1,ti 表示 <math xmlns="http://www.w3.org/1998/Math/MathML"> t i − 1 t_{i - 1} </math>ti−1 和 <math xmlns="http://www.w3.org/1998/Math/MathML"> t i t_i </math>ti 点之间的线段, <math xmlns="http://www.w3.org/1998/Math/MathML"> ∥ T ∥ = max ⁡ i = 1 , 2 , ... , n ∣ t i − 1 , t i ‾ ∣ \parallel T \parallel = \max\limits_{i = 1, 2, \dots, n} \vert \overline{t_{i - 1}, t_i} \vert </math>∥T∥=i=1,2,...,nmax∣ti−1,ti∣. 任取 <math xmlns="http://www.w3.org/1998/Math/MathML"> s i ∈ t i − 1 , t i ‾ s_i \in \overline{t_{i - 1}, t_i} </math>si∈ti−1,ti,考虑使用 <math xmlns="http://www.w3.org/1998/Math/MathML"> S = { s 1 , s 2 , ... , s n } \mathcal{S} = \{ s_1, s_2, \dots, s_n \} </math>S={s1,s2,...,sn} 来估计 <math xmlns="http://www.w3.org/1998/Math/MathML"> l l </math>l 的概率影响,对于任意点 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f ^ T ( x ) = 1 n h ∑ i = 1 n K ( x − s i h ) = ∑ i = 1 n 1 n h K ( x − s i h ) ≈ ∑ i = 1 n ∣ t i − 1 , t i ‾ ∣ ∣ t 0 , t n ‾ ∣ ⋅ 1 h K ( x − s i h ) . \begin{align} \hat{f}T(x) &= \frac{1}{nh} \sum\limits{i = 1}^{n} K\left( \frac{x - s_i}{h} \right) \nonumber \\ &= \sum\limits_{i = 1}^{n} \frac{1}{nh} K\left( \frac{x - s_i}{h} \right) \nonumber \\ &\approx \sum\limits_{i = 1}^{n} \frac{\vert \overline{t_{i - 1}, t_i} \vert}{\vert \overline{t_0, t_n} \vert} \cdot \frac{1}{h} K\left( \frac{x - s_i}{h} \right). \end{align} </math>f^T(x)=nh1i=1∑nK(hx−si)=i=1∑nnh1K(hx−si)≈i=1∑n∣t0,tn∣∣ti−1,ti∣⋅h1K(hx−si).

其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> K ( ⋅ ) K(\cdot) </math>K(⋅) 是选定核函数. 随着划分 <math xmlns="http://www.w3.org/1998/Math/MathML"> T T </math>T 越来越精细, <math xmlns="http://www.w3.org/1998/Math/MathML"> f ^ T ( x ) \hat{f}T(x) </math>f^T(x) 越接近真实的密度影响:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f ^ ∗ ( x ) = lim ⁡ ∥ T ∥ → 0 + f ^ T ( x ) = 1 h ∣ t 0 , t n ‾ ∣ ∫ l K ( x − s h ) d s . \begin{equation} \hat{f}
*(x) = \lim\limits_{\parallel T \parallel \rightarrow 0^+} \hat{f}T(x) = \frac{1}{h\vert \overline{t_0, t_n} \vert} \int{l} K\left( \frac{x - s}{h} \right) \mathrm{d}s. \end{equation} </math>f^∗(x)=∥T∥→0+limf^T(x)=h∣t0,tn∣1∫lK(hx−s)ds.

忽略掉系数 <math xmlns="http://www.w3.org/1998/Math/MathML"> ( ∣ t 0 , t n ‾ ∣ ) − 1 (\vert \overline{t_0, t_n} \vert)^{-1} </math>(∣t0,tn∣)−1,得到:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f ^ ( x ) = 1 h ∫ l K ( x − s h ) d s . \begin{equation} \hat{f}(x) = \frac{1}{h} \int_{l} K\left( \frac{x - s}{h} \right) \mathrm{d}s. \end{equation} </math>f^(x)=h1∫lK(hx−s)ds.

值得指出的是,忽略掉系数 <math xmlns="http://www.w3.org/1998/Math/MathML"> ( ∣ t 0 , t n ‾ ∣ ) − 1 (\vert \overline{t_0, t_n} \vert)^{-1} </math>(∣t0,tn∣)−1 是有意义的:一方面,由于不需要进行归一化,忽略该系数不会产生错误;另一方面,由于不同线特征的长度可能不同,若保留该系数,则较长的线特征产生的影响更广,导致其影响强度降低,使得不同线特征之间影响不匹配.

对于带宽 <math xmlns="http://www.w3.org/1998/Math/MathML"> h h </math>h 的选择,经验法(即:前文所提的直观法)是尤为重要的. 这是因为此类问题通常关注可视化的结果,得到如道路路网密度图等图像,因此视觉上的最优性是选取带宽的第一要素;对于部分问题,还要兼顾其计算复杂性和精度. 此外,自适应的带宽选择方法也会被使用.

4. 网络核密度估计(Network KDE, NKDE)

4.1 网络密度核估计算法

网络核密度估计是传统核密度估计在网络空间中的拓展,核心是解决"空间点事件在网络结构(如道路、河流、管线等线性网络)上的密度分布估计"问题,而非传统 KDE 针对的二维/三维欧氏空间.

在现实场景中,许多事件(如交通事故、店铺分布、犯罪案件)的发生和扩散严格依赖于网络(例如交通事故仅会沿道路分布,而非在道路外的区域),传统 KDE 直接用欧氏距离计算密度会忽略网络拓扑结构(如道路的连通性、弯曲度),导致估计结果失真;而 NKDE 通过将 "欧氏距离" 替换为 "网络距离",并结合网络拓扑特性调整核函数,实现对网络上点事件密度的精准刻画. 同样地,网络和密度估计也不需要进行归一化.

设 <math xmlns="http://www.w3.org/1998/Math/MathML"> G = ( V , E ) G = (V, E) </math>G=(V,E) 是有向连通图,其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> V V </math>V 是顶点集, <math xmlns="http://www.w3.org/1998/Math/MathML"> E E </math>E 是边集. 我们用 <math xmlns="http://www.w3.org/1998/Math/MathML"> d + ( v ) d_+(v) </math>d+(v) 表示顶点 <math xmlns="http://www.w3.org/1998/Math/MathML"> v v </math>v 的出度, <math xmlns="http://www.w3.org/1998/Math/MathML"> o u t ( v ) \mathrm{out}(v) </math>out(v) 表示离开顶点 <math xmlns="http://www.w3.org/1998/Math/MathML"> v v </math>v 的边的集合. 显然满足: <math xmlns="http://www.w3.org/1998/Math/MathML"> ∣ o u t ( v ) ∣ = d + ( v ) \vert \mathrm{out}(v) \vert = d_+(v) </math>∣out(v)∣=d+(v).

下面,我们来定义网络:记 <math xmlns="http://www.w3.org/1998/Math/MathML"> N = ( G , ω ) \mathcal{N} = (G, \omega) </math>N=(G,ω) 称为一个网络 ,其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> G = ( V , E ) G = (V, E) </math>G=(V,E) 是有向连通图, <math xmlns="http://www.w3.org/1998/Math/MathML"> ω \omega </math>ω 是定义在 <math xmlns="http://www.w3.org/1998/Math/MathML"> E E </math>E 上的函数,用于指明 <math xmlns="http://www.w3.org/1998/Math/MathML"> E E </math>E 中边 <math xmlns="http://www.w3.org/1998/Math/MathML"> e e </math>e 的权重(对应现实意义中的:道路权重、河流流量、管道大小等). 称 <math xmlns="http://www.w3.org/1998/Math/MathML"> x ∈ ⋃ E x \in \bigcup E </math>x∈⋃E 为 <math xmlns="http://www.w3.org/1998/Math/MathML"> N \mathcal{N} </math>N 中的点,对于 <math xmlns="http://www.w3.org/1998/Math/MathML"> N \mathcal{N} </math>N 中的任一点 <math xmlns="http://www.w3.org/1998/Math/MathML"> x 1 , x 2 x_1, x_2 </math>x1,x2,记 <math xmlns="http://www.w3.org/1998/Math/MathML"> x 1 x_1 </math>x1 到 <math xmlns="http://www.w3.org/1998/Math/MathML"> x 2 x_2 </math>x2 的最短路径长度为 <math xmlns="http://www.w3.org/1998/Math/MathML"> d m ( x 1 , x 2 ) \mathrm{dm}(x_1, x_2) </math>dm(x1,x2),经过的顶点的全体构成的集合为 <math xmlns="http://www.w3.org/1998/Math/MathML"> V m ( x 1 , x 2 ) \mathrm{Vm}(x_1, x_2) </math>Vm(x1,x2).

设 <math xmlns="http://www.w3.org/1998/Math/MathML"> S = ( x ( 1 ) , x ( 2 ) , . . . , x ( n ) ) \mathcal{S} = (x^{(1)}, x^{(2)}, ..., x^{(n)}) </math>S=(x(1),x(2),...,x(n)) 是 <math xmlns="http://www.w3.org/1998/Math/MathML"> N \mathcal{N} </math>N 中的样本, <math xmlns="http://www.w3.org/1998/Math/MathML"> K K </math>K 是取定一元核函数. 对于任意样本点 <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( i ) x^{(i)} </math>x(i),不妨设 <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( i ) ∈ e i x^{(i)} \in e_i </math>x(i)∈ei,对于 <math xmlns="http://www.w3.org/1998/Math/MathML"> e i e_i </math>ei 上任意点 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x, <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( i ) x^{(i)} </math>x(i) 在 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 处的影响为:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f i ( x ) = K h ( d m ( x ( i ) , x ) ) , x ∈ e i . \begin{equation} f_i(x) = K_h \left( \mathrm{dm}(x^{(i)}, x) \right), \quad x \in e_i. \end{equation} </math>fi(x)=Kh(dm(x(i),x)),x∈ei.

此时的影响衰减函数即为一元 KDE 的影响衰减函数. 下面考虑 <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( i ) x^{(i)} </math>x(i) 对位于其它边上的点的影响:设 <math xmlns="http://www.w3.org/1998/Math/MathML"> e j e_j </math>ej 的起点通过顶点 <math xmlns="http://www.w3.org/1998/Math/MathML"> v v </math>v 连接到 <math xmlns="http://www.w3.org/1998/Math/MathML"> e i e_i </math>ei, <math xmlns="http://www.w3.org/1998/Math/MathML"> x ∈ e j x \in e_j </math>x∈ej,则可以给出 <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( i ) x^{(i)} </math>x(i) 在 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 处的影响:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f i ( x ) = 1 d + ( v ) K h ( d m ( x ( i ) , x ) ) , x ∈ e j . \begin{equation} f_i(x) = \frac{1}{d_+(v)}K_h \left( \mathrm{dm}(x^{(i)}, x) \right), \quad x \in e_j. \end{equation} </math>fi(x)=d+(v)1Kh(dm(x(i),x)),x∈ej.

其直观的实际意义是: <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( j ) x^{(j)} </math>x(j) 的影响随着 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 移动到 <math xmlns="http://www.w3.org/1998/Math/MathML"> e j e_j </math>ej 的终点 <math xmlns="http://www.w3.org/1998/Math/MathML"> v v </math>v 处而发生了分裂,平均分为 <math xmlns="http://www.w3.org/1998/Math/MathML"> d + d_+ </math>d+ 份,沿着 <math xmlns="http://www.w3.org/1998/Math/MathML"> o u t ( v ) \mathrm{out}(v) </math>out(v) 中的每条边继续延申. 如果考虑到 <math xmlns="http://www.w3.org/1998/Math/MathML"> ω \omega </math>ω 的作用(即:影响的分裂不是均分,而是依权重分裂),则有:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f i ( x ) = ω ( e j ) ∑ e ∈ o u t ( v ) ω ( e ) K h ( d m ( x ( i ) , x ) ) , x ∈ e j . \begin{equation} f_i(x) = \frac{\omega(e_j)}{\sum\limits_{e \in \mathrm{out}(v)} \omega(e)} K_h \left( \mathrm{dm}(x^{(i)}, x) \right), \quad x \in e_j. \end{equation} </math>fi(x)=e∈out(v)∑ω(e)ω(ej)Kh(dm(x(i),x)),x∈ej.

据此,对于一般 <math xmlns="http://www.w3.org/1998/Math/MathML"> N \mathcal{N} </math>N 中的点 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x, <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( i ) x^{(i)} </math>x(i) 对 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 的影响为:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f i ( x ) = ∏ v ∈ V m ( x ( i ) , x ) ( ω ( e v ) ∑ e ∈ o u t ( v ) ω ( e ) ) K h ( d m ( x ( i ) , x ) ) , x ∈ ⋃ E . \begin{equation} f_i(x) = \prod_{v \in \mathrm{Vm}(x^{(i)}, x)} \left( \frac{\omega(e_v)}{\sum\limits_{e \in \mathrm{out}(v)} \omega(e)} \right) K_h\left( \mathrm{dm}(x^{(i)}, x) \right), \quad x \in \bigcup E. \end{equation} </math>fi(x)=v∈Vm(x(i),x)∏ e∈out(v)∑ω(e)ω(ev) Kh(dm(x(i),x)),x∈⋃E.

(说明:上式实际表示的是 <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( i ) x^{(i)} </math>x(i) 对其下游点的影响,若要表示对上游点的影响,只需将 <math xmlns="http://www.w3.org/1998/Math/MathML"> V m ( x ( i ) , x ) \mathrm{Vm}(x^{(i)}, x) </math>Vm(x(i),x) 改为 <math xmlns="http://www.w3.org/1998/Math/MathML"> V m ( x , x ( i ) ) \mathrm{Vm}(x, x^{(i)}) </math>Vm(x,x(i)),下同)

其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> e v e_v </math>ev 表示从 <math xmlns="http://www.w3.org/1998/Math/MathML"> x ( i ) x^{(i)} </math>x(i) 到 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 的最短路径中以 <math xmlns="http://www.w3.org/1998/Math/MathML"> v ( v ∈ V m ( x ( i ) , x ) ) v \space \left(v \in \mathrm{\mathrm{Vm}(x^{(i)}, x)} \right) </math>v (v∈Vm(x(i),x)) 为起点的边. 尽管这一式子十分复杂,在实际应用中(无论是选取有紧支集的核函数还是 Gauss 核函数),只需考虑带宽范围内的点即可.

最后,基于全部的样本,我们可以给出 <math xmlns="http://www.w3.org/1998/Math/MathML"> N \mathcal{N} </math>N 上的样本密度估计函数:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f ( x ) = 1 n ∑ i = 1 n f i ( x ) . \begin{equation} f(x) = \frac{1}{n} \sum\limits_{i = 1}^{n} f_i(x). \end{equation} </math>f(x)=n1i=1∑nfi(x).

4.2 基于线特征的网络核密度估计算法

在某些应用网络密度核估计算法的场景中,样本点不再是点特征,而是线特征,如:出租车的载客点分布(说明:实际应用中,无法获取出租车载客点的实际位置,而是通过连续采样,粗略地认为载客点位于某两采样点间. 而这两个采样点间的道路即为一个线特征). 下面我们将 NKDE 推广至线特征:

先给出线性事件 的定义:记 <math xmlns="http://www.w3.org/1998/Math/MathML"> l = ( s , t , p ) \mathscr{l} = ( s, t, p ) </math>l=(s,t,p),其中 <math xmlns="http://www.w3.org/1998/Math/MathML"> s ∈ e s , t ∈ e t , ∃ e s , e p ∈ E s \in e_s, \space t \in e_t, \space \exist e_s, e_p \in E </math>s∈es, t∈et, ∃es,ep∈E, <math xmlns="http://www.w3.org/1998/Math/MathML"> p p </math>p 是线性事件的其它额外信息(如起止时间、ID 编号等),不在数学讨论范围中.

设 <math xmlns="http://www.w3.org/1998/Math/MathML"> S l i n e a r = ( l ( 1 ) , l ( 2 ) , . . . , l ( n ) ) \mathcal{S_\mathrm{linear}} = (\mathscr{l}^{(1)}, \mathscr{l}^{(2)}, ..., \mathscr{l}^{(n)}) </math>Slinear=(l(1),l(2),...,l(n)) 是网络 <math xmlns="http://www.w3.org/1998/Math/MathML"> N \mathcal{N} </math>N 中的线特征样本,每个特征的原始影响衰减函数为:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f o r i g i n , i ( x ) = 1 h ∫ l ( i ) K ( d m ( s , x ) h ) d s . \begin{equation} f_{\mathrm{origin}, i}(x) = \frac{1}{h} \int_{\mathscr{l}^{(i)}} K\left( \frac{\mathrm{dm}(s, x)}{h} \right) \mathrm{d}s. \end{equation} </math>forigin,i(x)=h1∫l(i)K(hdm(s,x))ds.

联合上述分析,得到受网络约束的影响衰减函数:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f i ( x ) = ∏ v ∈ V m ( s , x ) , s ∈ l ( i ) ( ω ( e v ) ∑ e ∈ o u t ( v ) ω ( e ) ) f o r i g i n , i ( x ) . \begin{equation} f_i(x) = \prod_{v \in \mathrm{Vm}(s, x), s \in \mathscr{l}^{(i)}} \left( \frac{\omega(e_v)}{\sum\limits_{e \in \mathrm{out}(v)} \omega(e)} \right) f_{\mathrm{origin}, i}(x). \end{equation} </math>fi(x)=v∈Vm(s,x),s∈l(i)∏ e∈out(v)∑ω(e)ω(ev) forigin,i(x).

最后,基于全部的样本,我们可以给出 <math xmlns="http://www.w3.org/1998/Math/MathML"> N \mathcal{N} </math>N 上的线特征样本密度估计函数:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> f ( x ) = 1 n ∑ i = 1 n f i ( x ) . \begin{equation} f(x) = \frac{1}{n} \sum\limits_{i = 1}^{n} f_i(x). \end{equation} </math>f(x)=n1i=1∑nfi(x).

最后,我们指出本节所述仅是一种推广的思想,对于实际问题需要进行具体分析,调整式子,从而给出更优的解答. 例如,在前文所述出租车载客点分布的问题中,我们有时需要分别讨论道路两侧的载客点. 这就需要我们在求平均值时只考虑"同向"线性事件的影响,而忽略"反向"线性事件的影响.

相关推荐
only-qi7 小时前
leetcode110. 平衡二叉树
数据结构·算法
要做朋鱼燕7 小时前
【C++】Vector核心实现:类设计到迭代器陷阱
开发语言·c++·笔记·算法·职场和发展
Go_Zezhou7 小时前
在线性代数里聊聊word embedding
线性代数·算法·机器学习·nlp
Christo38 小时前
TFS-2005《A Possibilistic Fuzzy c-Means Clustering Algorithm》
人工智能·算法·机器学习
hansang_IR8 小时前
【题解】洛谷P1776 宝物筛选 [单调队列优化多重背包]
c++·算法·动态规划·题解·背包·多重背包·单调队列
jndingxin8 小时前
c++多线程(1)------创建和管理线程td::thread
开发语言·c++·算法
SuperCandyXu8 小时前
洛谷 P3128 [USACO15DEC] Max Flow P -普及+/提高
c++·算法·图论·洛谷
你说今年的枫叶好像不够红啊8 小时前
LeetCode[两数之和] java版
数据结构·算法·leetcode
YC汐宇8 小时前
数据结构:顺序栈与链栈的原理、实现及应用
数据结构·算法·链表