感觉这个分布的含义很有用啊, 能预测‘最大', 也就是自然灾害, 太牛了.

主要内容

定义

[Gumbel distribution-wiki](Gumbel distribution - Wikipedia)

其分布函数和概率密度函数分别为:

\[F(x; \mu, \beta) = e^{-e^{-(x-\mu)/\beta}}, \quad f(x;\mu,\beta) = \frac{1}{\beta} e^{-[e^{-(x-\mu)/\beta}+(x-\mu) / \beta]}
\]

标准Gumbel分布(即\(\mu=0, \beta=1\)):

\[F(x) = e^{-e^{-x}}, \quad f(x) = e^{-(x+e^{-x})}.
\]

从Gumbel分布中采样, 只需:

\[x = F^{-1}(u) = \mu - \beta \ln (-\ln(u)), \quad u \sim \mathrm{Uniform}(0, 1).
\]

proof:

\[P(F^{-1}(u) \le x) = P(u \le F(x)) = F(x),
\]

故\(F^{-1}(u)\)的分布函数就是\(F(x)\).

\[\mathbb{E} [x] = \mu + \gamma \cdot \beta,
\]

其中 \(\gamma\)是Euler-Mascherorni constant.

Gumbel-Max trick

假设我们有一个离散的分布\([\pi_1, \pi_2, \cdots, \pi_k]\)共\(k\)类, \(\pi_i\)表示为第\(i\)类的概率, 则从该分布中采样\(z\)等价于

\[z = \arg \max_i [g_i + \log \pi_i], \quad g_i \sim \mathrm{Gumbel}(0, 1), \mathrm{i.i.d}.
\]

proof:

\[P(z=i) = P(g_i + \log \pi_i \ge \max \{g_j + \log \pi_j\}_{j\not=i}) = \int_{-\infty}^{+\infty} p(x) P(x+\log \pi_i \ge \{g_j + \log \pi_j\}_{j\not=i}) \mathrm{d}x.
\]

\[P(x+\log \pi_i \ge \{g_j + \log \pi_j\}_{j\not=i}) = \prod_{j\not=i} P(g_j \le x + \log\pi_i - \log \pi_j) = e^{-e^{-x} \cdot \frac{1 - \pi_i}{\pi_i}},
\]

带入计算得:

\[\begin{array}{ll}
P(z=i)
& = \int_{-\infty}^{+\infty} e^{-(x+e^{-x} \cdot \frac{1}{\pi_i})} \mathrm{d}x \\
& = \int_{-\infty}^{+\infty} \pi_i \cdot e^{-[(x-\log\frac{1}{\pi_i})+e^{-(x - \log \frac{1}{\pi_i})}]} \mathrm{d}x \\
& = \pi_i.
\end{array}
\]

Gumbel trick 用于归一化

我们时常会碰到这样的问题:

\[p(x;\theta) = \frac{f(x;\theta)}{Z},
\]

其中\(Z=\sum_{i=1}^K f(x_i;\theta)\) 是归一化常数, 那么怎么计算\(Z\)呢?

构建随机变量\(T\):

\[T = \max_i [\ln f(x_i) + g_i], \quad g_i \sim \mathrm{Gumbel}(-c, 1), \mathrm{i.i.d.}
\]

\[T \sim \mathrm{Gumbel}(-c + \ln Z)
\]

proof:

\[P(T \le t) = P(\max_i [\ln f(x_i) + g_i] \le t) = \prod_{i} P(g_i \le t - \ln f(x_i)) = e^{-e^{-(t+c-\ln Z)}} = F(t;-c+\ln Z ,1).
\]

因为

\[\mathbb{E}[T] = -c + \ln Z + \gamma,
\]

故我们只需估计\(\mathbb{E}[T] \approx \sum_j T_j\) 即可估计\(Z\)

\[Z = \exp (\sum_{j}T_j + c - \gamma).
\]

所以必须要求离散的\(x\)?

代码

[scipy-gumbel](scipy.stats.gumbel_r — SciPy v1.6.3 Reference Guide)

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gumbel_r fig, ax = plt.subplots(1, 1)
# mean, var, skew, kurt = gumbel_r.stats(moments='mvsk')
# print(mean, var, skew, kurt) x = np.linspace(gumbel_r.ppf(0.01), gumbel_r.ppf(0.99), 100)
ax.plot(x, gumbel_r.pdf(x), 'r-', lw=5, alpha=0.6, label="gumbel_r pdf")
r = gumbel_r.rvs(size=1000, loc=0, scale=1)
ax.hist(r, density=True, histtype="stepfilled", alpha=0.2)
ax.legend(loc='best', frameon=False)
plt.show()

Gumbel distribution的更多相关文章

  1. Gumbel-Softmax Trick和Gumbel分布

      之前看MADDPG论文的时候,作者提到在离散的信息交流环境中,使用了Gumbel-Softmax estimator.于是去搜了一下,发现该技巧应用甚广,如深度学习中的各种GAN.强化学习中的A2 ...

  2. (数据科学学习手札03)Python与R在随机数生成上的异同

    随机数的使用是很多算法的关键步骤,例如蒙特卡洛法.遗传算法中的轮盘赌法的过程,因此对于任意一种语言,掌握其各类型随机数生成的方法至关重要,Python与R在随机数底层生成上都依靠梅森旋转(twiste ...

  3. Python中生成随机数

    目录 1. random模块 1.1 设置随机种子 1.2 random模块中的方法 1.3 使用:生成整形随机数 1.3 使用:生成序列随机数 1.4 使用:生成随机实值分布 2. numpy.ra ...

  4. Categorical Reparameterization with Gumbel-Softmax

    目录 概 主要内容 Gumbel distribution Jang E., Gu S. and Poole B. Categorical reparameterization with gumbel ...

  5. 齐夫定律, Zipf's law,Zipfian distribution

    齐夫定律(英语:Zipf's law,IPA英语发音:/ˈzɪf/)是由哈佛大学的语言学家乔治·金斯利·齐夫(George Kingsley Zipf)于1949年发表的实验定律. 它可以表述为: 在 ...

  6. CloudSim4.0报错NoClassDefFoundError,Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.distribution.UniformRealDistribution

    今天下载了CloudSim 4.0的代码,运行其中自带的示例程序,结果有一部分运行错误: 原因是找不到org.apache.commons.math3.distribution.UniformReal ...

  7. Wishart distribution

    Introduction In statistics, the Wishart distribution is generalization to multiple dimensions of the ...

  8. distribution 中一直在运行 waitfor delay @strdelaytime 语句

    Replication 自动创建来一个 Job:Replication monitoring refresher for distribution,这个Agent执行一个sp: dbo.sp_repl ...

  9. Distribution2:Distribution Writer

    Distribution Writer 调用Statement Delivery 存储过程,将Publication的改变同步到Subscriber中.查看Publication Properties ...

随机推荐

  1. 备忘录:关于.net程序连接Oracle数据库

    目录 关于使用MSSM访问Oracle数据库 关于. net 程序中连接Oracle数据库 志铭-2021年12月7日 21:22:15 关于使用MSSM访问Oracle数据库 安装访问接口组件:Or ...

  2. day14搭建博客系统项目

    day14搭建博客系统项目 1.下载代码包 [root@web02 opt]# git clone https://gitee.com/lylinux/DjangoBlog.git 2.使用pid安装 ...

  3. 什么是 IP 地址 – 定义和解释

    IP 地址定义 IP 地址是一个唯一地址,用于标识互联网或本地网络上的设备.IP 代表"互联网协议",它是控制通过互联网或本地网络发送的数据格式的一组规则. 本质上,IP 地址是允 ...

  4. 【leetcode】170. Two Sum III - Data structure design 两数之和之三 - 数据结构设计

    Design and implement a TwoSum class. It should support the following operations:  add and find. add  ...

  5. JavaIO——内存操作流、打印流

    我们之前所做的都是对文件进行IO处理,实则我们也可以对内存进行IO处理.我们将发生在内存中的IO处理称为内存流. 内存操作流也可分为两类:字节内存流和字符内存流. (1)ByteArrayInputS ...

  6. How does “void *” differ in C and C++?

    C allows a void* pointer to be assigned to any pointer type without a cast, whereas C++ does not; th ...

  7. 【编程思想】【设计模式】【行为模式Behavioral】状态模式State

    Python版 https://github.com/faif/python-patterns/blob/master/behavioral/state.py #!/usr/bin/env pytho ...

  8. Nginx 1.9.7.2 + PHP 5.6.18(FastCGI)在CentOS Linux下的编译安装

    本文参考张宴的Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)[原创]完成.所有操作命令都在CentOS 6.x 64位操作系统下实践 ...

  9. List如何一边遍历,一边删除?

    1.新手常犯的错误 可能很多新手(包括当年的我,哈哈)第一时间想到的写法是下面这样的: public static void main(String[] args) { List<String& ...

  10. JS中操作JSON总结

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...