## 信息扩散原理及实现（matlab）

$U= \left\{ u_1, u_2, ..., u_m \right\}$

$f(u_j)=\frac{1}{h\sqrt{2\pi}}e^{-\frac{(x-u_j)^2}{2h^2}}$中， $h$ 为扩散系数，可根据样本中的最大值 $b$ 和最小值 $a$ 及样本点个数 $n$ 来确定。

$s=\max_{1\leq j \leq m} \left\{ f(u_j)\right\}$

$\mu_x(u_j)=\frac{f(u_j)}{s}$

$f_i(u_j)=\frac{1}{h\sqrt{2\pi}}e^{-\frac{(x-u_j)^2}{2h^2}}$

$C_i=\sum_{j=1}^m f_i(u_j)$

$\mu_x(u_j)=\frac{f_i(u_j)}{C_i}$

$\mu_x(u_j)$ 为样本点 $x_i$ 的归一化信息分布。

$q(u_j)=\sum_{i=1}^n \mu_{x_i}(u_j)$

$Q=\sum_{j=1}^m q(u_j)$

$Q$ 事实上就是各 $u_j$ 点上样本点数的总和，从理论上讲，必有 $Q=n$（计算中可能存在一些误差）。
$p(u_j)=\frac{q(u_j)}{Q}$

$P(u_j)=\sum_{k=j}^m p(u_k)$

$P(u_j)$ 即为超越概率估计值。

$X$ $=$ $\left \{\right.$ $-2.5875,$ $-2.5621,$ $-1.1896,$ $-1.1882,$ $-1.2074,$ $-1.7865,$ $-1.0498,$ $-2.0894,$ $-1.6859,$ $-1.3128,$ $-1.1729,$ $-1.9419,$ $-1.6125,$ $-1.9118,$ $-2.5795,$ $-1.2603$ $\left.\right \}$

$h = 2.6851 * \frac{-1.0498 + 2.5875}{16 - 1} = 0.2753$为扩散系统，使用正态扩散方法进行估计
matlab代码如下：

x = [-2.5875, -2.5621, -1.1896, -1.1882, -1.2074, -1.7865, -1.0498, -2.0894, -1.6859, -1.3128, -1.1729, -1.9419, -1.6125, -1.9118, -2.5795, -1.2603];
u = [-3, -2.5, -2, -1.5, -1, -0.5, 0];

xlength = length(x);
ulength = length(u);
maxX = max(x);
minX = min(x);

if xlength == 5
h = 0.8146 * (maxX - minX);
elseif xlength == 6
h = 0.5690 * (maxX - minX);
elseif xlength == 7
h = 0.4560 * (maxX - minX);
elseif xlength == 8
h = 0.3860 * (maxX - minX);
elseif xlength == 9
h = 0.3362 * (maxX - minX);
elseif xlength == 10
h = 0.2986 * (maxX - minX);
elseif xlength > 10
h = 2.6851 * (maxX - minX) / (xlength - 1);
else
h = 0;
end

f = zeros(xlength, ulength);
C = zeros(xlength, 1);
q = zeros(ulength, 1);
for i = 1 : xlength
for j = 1 : ulength
f(i, j) = 1.0 / (h * sqrt(2 * pi)) * exp(-(x(i) - u(j)) ^ 2 / (2 * h ^ 2));
C(i) = C(i) + f(i, j);
end
end

for i = 1 : xlength
for j = 1 : ulength
f(i, j) = f(i, j) / C(i);
q(j) = q(j) + f(i, j);
end
end
Q = sum(q);
p = q ./ Q;
P = zeros(ulength, 1);
for i = 1 : ulength
for j = i : ulength
P(i) = P(i) + p(j);
end
end


u -3 -2.5 -2 -1.5 -1 -0.5 0
p 0.0419 0.1583 0.2251 0.3114 0.2674 0.0157 4.9511e-05
P 1 0.9581 0.7999 0.5748 0.2634 0.0157 4.9511e-05