《学做网站论坛》视频下载,唯品会 一家专门做特卖的网站手机版,外网下载,升学历有哪几种报名方式0. 引言
前几天分几篇博文精细地讲述了《von Mises-Fisher 分布》, 以及相应的 PyTorch 实现《von Mises-Fisher Distribution (代码解析)》, 其中以 Uniform 分布为例简要介绍了 torch.distributions 包的用法. 本以为已经可以了, 但这两天看到论文 The Power Spherical dist…0. 引言
前几天分几篇博文精细地讲述了《von Mises-Fisher 分布》, 以及相应的 PyTorch 实现《von Mises-Fisher Distribution (代码解析)》, 其中以 Uniform 分布为例简要介绍了 torch.distributions 包的用法. 本以为已经可以了, 但这两天看到论文 The Power Spherical distribution 的代码, 又被其实现分布的方式所吸引.
Power Spherical 分布与 von Mises Fisher 分布类似, 只不过将后者概率密度函数中的指数函数换成了多项式函数: f p ( x ; μ , κ ) ∝ e x p ( κ μ ⊺ x ) ⇓ f p ( x ; μ , κ ) ∝ ( 1 μ ⊺ x ) κ \begin{aligned} f_p(\bm{x}; \bm{\mu}, \kappa) \propto exp(\kappa \bm{\mu}^\intercal \bm{x}) \\ \Downarrow\\ f_p(\bm{x}; \bm{\mu}, \kappa) \propto (1\bm{\mu}^\intercal \bm{x})^\kappa \\ \end{aligned} fp(x;μ,κ)fp(x;μ,κ)∝exp(κμ⊺x)⇓∝(1μ⊺x)κ 采样框架基本一致, 且这么做可以使边缘 t t t 的线性变换 t 1 2 ∼ B e t a ( p − 1 2 κ , p − 1 2 ) \frac{t1}{2} \sim Beta(\frac{p-1}{2}\kappa, \frac{p-1}{2}) 2t1∼Beta(2p−1κ,2p−1), 从而避免了接受-拒绝采样过程.
当然, 按照之前的 VonMisesFisher 的写法, 这个 t 的采样大概是这样:
z beta.sample(sample_shape)
t 2 * z - 1但现在我遇到了这种写法:
class MarginalTDistribution(tds.TransformedDistribution):arg_constraints {dim: constraints.positive_integer,scale: constraints.positive,}has_rsample Truedef __init__(self, dim, scale, validate_argsNone):self.dim dimself.scale scalesuper().__init__(tds.Beta( # 用 Beta 分布转换, z 服从 Beta(ακ,β)(dim - 1) / 2 scale, (dim - 1) / 2, validate_argsvalidate_args),transformstds.AffineTransform(loc-1, scale2), # t2z-1 是想要的边缘分布随机数)然后就可以进行对 t t t 的采样了.
上述代码的解构图; 浅蓝色代表抽象基类, 绿色代表实类; 虚线代表继承, 实线代表参数输入 我们可以看到其基本架构, 本文将详细解析其内部的具体细节.