Score Matching算法介绍

简介

score matching算法是一种求解概率密度函数的参数的算法。
在很多情况下,概率密度函数可以表示为:
p ( ξ ; θ ) = 1 Z ( θ ) q ( ξ ; θ ) p(\xi;\theta)=\frac{1}{Z(\theta)}q(\xi;\theta) p(ξ;θ)=Z(θ)1q(ξ;θ)
假设我们知道 q q q的解析表达式,但是因为 Z Z Z的计算需要积分计算,并不能简单地计算 Z Z Z
score matching算法通过绕开归一化常数 Z Z Z,求解概率密度函数的参数 θ \theta θ

Score Function

为了去掉 Z Z Z,我们定义分数函数score function ψ ( ξ ; θ ) \psi(\xi;\theta) ψ(ξ;θ):
ψ ( ξ ; θ ) = ( ∂ log ⁡ p ( ξ ; θ ) ∂ ξ 1 ⋮ ∂ log ⁡ p ( ξ ; θ ) ∂ ξ n ) = ( ψ 1 ( ξ ; θ ) ⋮ ψ n ( ξ ; θ ) ) = ∇ ξ log ⁡ p ( ξ ; θ ) \psi(\xi;\theta)=\left (\begin{array}{c} \frac{\partial\log p(\xi;\theta)}{\partial \xi_1} \\ \vdots \\ \frac{\partial\log p(\xi;\theta)}{\partial \xi_n} \\ \end{array}\right)=\left (\begin{array}{c} \psi_1(\xi;\theta) \\ \vdots \\ \psi_n(\xi;\theta) \\ \end{array}\right)=\nabla_\xi \log p(\xi;\theta) ψ(ξ;θ)= ξ1logp(ξ;θ)ξnlogp(ξ;θ) = ψ1(ξ;θ)ψn(ξ;θ) =ξlogp(ξ;θ)
因为 Z ( θ ) Z(\theta) Z(θ) ξ \xi ξ无关,通过score function可以去掉 Z ( θ ) Z(\theta) Z(θ),即score function只依赖 q q q
ψ ( ξ ; θ ) = ∇ ξ log ⁡ q ( ξ ; θ ) \psi(\xi;\theta)=\nabla_\xi\log q(\xi;\theta) ψ(ξ;θ)=ξlogq(ξ;θ)

另外,用 ψ x ( ⋅ ) = ∇ ξ log ⁡ p x ( ⋅ ) \psi_x(\cdot)=\nabla_\xi \log p_x(\cdot) ψx()=ξlogpx()表示观测数据的score function。

求解方法

score matching算法通过最小化模型分数函数 ψ ( ξ ; θ ) \psi(\xi;\theta) ψ(ξ;θ)和数据分数函数 ψ x ( ξ ; θ ) \psi_x(\xi;\theta) ψx(ξ;θ)的平方差的期望来得到参数 θ \theta θ。该期望的定义如下:
J ( θ ) = 1 2 ∫ ξ ∈ R n p x ( ξ ) ∥ ψ ( ξ ; θ ) − ψ x ( ξ ; θ ) ∥ 2 d ξ J(\theta)=\frac{1}{2}\int_{\xi\in \mathbb{R}^n}p_x(\xi)\|\psi(\xi;\theta)-\psi_x(\xi;\theta)\|^2d\xi J(θ)=21ξRnpx(ξ)ψ(ξ;θ)ψx(ξ;θ)2dξ
最小化上面的期望将得到 θ \theta θ的score matching估计量(estimator):
θ ^ = argmin J ( θ ) \hat{\theta}=\text{argmin}J(\theta) θ^=argminJ(θ)
因为score function不含有 Z Z Z,优化 J ( θ ) J(\theta) J(θ)可以去掉对 Z Z Z的计算。但值得注意的是,直接优化 J ( θ ) J(\theta) J(θ)依然很难,因为数据分数函数 ψ x ( ξ ; θ ) \psi_x(\xi;\theta) ψx(ξ;θ)的计算是一个非参数估计问题(non-parametric estimation problem)。

但是可以证明 J ( θ ) J(\theta) J(θ)可以重写成没有数据分数函数的形式:
J ( θ ) = ∫ ξ ∈ R n p x ( ξ ) ∑ i = 1 n [ ∂ i ψ i ( ξ ; θ ) + 1 2 ψ i ( ξ ; θ ) 2 ] d ξ + c o n s t J(\theta)=\int_{\xi\in \mathbb{R}^n}p_x(\xi)\sum_{i=1}^n[\partial_i\psi_i(\xi;\theta)+\frac{1}{2}\psi_i(\xi;\theta)^2]d\xi+const J(θ)=ξRnpx(ξ)i=1n[iψi(ξ;θ)+21ψi(ξ;θ)2]dξ+const
下面是论文中给出的完整定理。
在这里插入图片描述
现实中,假设我们有 T T T个观测值 x ( 1 ) , … , x ( T ) x(1),\ldots,x(T) x(1),,x(T)。根据大数定理,期望可以用平均数表示, J J J则表示成
J ~ ( θ ) = 1 T ∑ t = 1 T ∑ i = 1 n [ ∂ i ψ i ( x ( t ) ; θ ) + 1 2 ψ i ( x ( t ) ; θ ) 2 ] d ξ + c o n s t \tilde{J}(\theta)=\frac{1}{T}\sum_{t=1}^T\sum_{i=1}^n[\partial_i\psi_i(x(t);\theta)+\frac{1}{2}\psi_i(x(t);\theta)^2]d\xi+const J~(θ)=T1t=1Ti=1n[iψi(x(t);θ)+21ψi(x(t);θ)2]dξ+const
可以证明,如果 θ ^ \hat{\theta} θ^ J ~ \tilde{J} J~的全局最优解,那么估计量 θ ^ \hat{\theta} θ^将具有一致性(consistent)。
具有一致性的估计量是渐进无偏(asymptotic unbiasedness)的。

emm

从统计学的角度理解score matching。score matching就是要从观测数据估计出总体的未知参数。 θ ^ \hat{\theta} θ^是估计量, θ \theta θ是被估计量。估计量需要具有一些性质才是好的估计量。这里 θ ^ \hat{\theta} θ^在一定条件下具有一致性(consistent)。

参考

[1]: Estimation of Non-Normalized Statistical Models by Score Matching

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于方向的轨迹匹配算法是一种常用的轨迹匹配算法,它可以用于将一条轨迹与另一条轨迹进行匹配。具体步骤如下: 1. 将两条轨迹分别按照时间戳排序,得到按时间先后顺序排列的轨迹点序列。 2. 对于每个轨迹点,计算它与另一条轨迹的所有点之间的方向差,即方向偏移量。 3. 根据方向偏移量进行轨迹点匹配,选择方向偏移量最小的点作为匹配点。 4. 将匹配点对应的两个轨迹点从序列中删除,继续寻找下一个匹配点,直到所有轨迹点都匹配完成。 5. 根据匹配得分,评估两条轨迹的匹配程度。 需要注意的是,基于方向的轨迹匹配算法对轨迹点的方向信息要求较高,一般要求轨迹点的速度和方向信息精度较高。 基于方向的轨迹匹配算法可以应用于许多应用场景,如轨迹相似性比较、轨迹跟踪等。但是,它也存在一些限制,如需要轨迹点的速度和方向信息较为精确,因此在具体应用中需要根据实际情况进行选择。 以下是基于方向的轨迹匹配算法的Python代码实现,供您参考: ```python import numpy as np def direction_based_matching(traj1, traj2): """ 基于方向的轨迹匹配算法 :param traj1: 第一条轨迹,格式为[(lat1, lon1, speed1, direction1), (lat2, lon2, speed2, direction2), ...] :param traj2: 第二条轨迹,格式为[(lat1, lon1, speed1, direction1), (lat2, lon2, speed2, direction2), ...] :return: 匹配得分 """ # 轨迹点按时间戳排序 traj1 = sorted(traj1, key=lambda x: x[2]) traj2 = sorted(traj2, key=lambda x: x[2]) # 初始化匹配得分和轨迹点列表 score = 0 match_list = [] # 遍历第一条轨迹的每个点 for p1 in traj1: # 初始化方向偏移量和距离 min_offset = np.inf min_dist = np.inf # 遍历第二条轨迹的每个点 for p2 in traj2: # 计算方向偏移量 offset = abs(p1[3] - p2[3]) # 如果方向偏移量大于180度,则取相反方向 if offset > 180: offset = 360 - offset # 如果方向偏移量大于最小方向偏移量,则跳过 if offset > min_offset: continue # 计算距离 dist = np.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) # 如果距离大于最小距离,则跳过 if dist > min_dist: continue # 更新最小方向偏移量和最小距离 min_offset = offset min_dist = dist # 记录匹配点 match_point = (traj1.index(p1), traj2.index(p2)) # 将匹配点添加到匹配列表中 match_list.append(match_point) # 更新匹配得分 score += min_offset / (min_dist + 1e-6) # 计算平均匹配得分 score /= len(traj1) return score ``` 该算法的输入是两条轨迹,格式为[(纬度1, 经度1, 速度1, 方向1), (纬度2, 经度2, 速度2, 方向2), ...]。输出是两条轨迹的匹配得分,得分越高表示匹配程度越好。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值