(一)连续随机量的生成-基于分布函数

连续随机量的生成-基于分布函数

  • [1. 概率积分变换方法(分布函数)](#1. 概率积分变换方法(分布函数))
  • [2. Python编程实现指数分布的采样](#2. Python编程实现指数分布的采样)

1. 概率积分变换方法(分布函数)

Consider drawing a random quantity X X X from a continuous probability distribution with the distribution function F F F. We know F F F is a continues nondecreasing function if F F F has an inverse F − 1 F^{-1} F−1, then Z = F − 1 ( U ) Z=F^{-1}(U) Z=F−1(U), where U U U is a random quantity drawn from U ( 0 , 1 ) U(0,1) U(0,1), is a random quantity as desired. Indeed,
P ( X ⩽ z ) = P ( F − 1 ( U ) ⩽ z ) = P ( U ⩽ F ( z ) ) = F ( z ) , ∀ z ∈ R P(X \leqslant z)=P\left(F^{-1}(U) \leqslant z\right)=P(U \leqslant F(z))=F(z), \forall z \in \mathbb{R} P(X⩽z)=P(F−1(U)⩽z)=P(U⩽F(z))=F(z),∀z∈R

Example : Exponential distribution Exp ⁡ ( 1 ) \operatorname{Exp} (1) Exp(1).

Exp (1) has a probability density function: f ( z ) = { e − z , z ⩾ 0 , 0 , z < 0. f(z)= \begin{cases}e^{-z}, & z \geqslant 0, \\ 0, & z<0 .\end{cases} f(z)={e−z,0,z⩾0,z<0.

Its distribution function is F ( z ) = { 1 − e − z , z ⩾ 0 , 0 , z < 0. F(z)= \begin{cases}1-e^{-z}, & z \geqslant 0, \\ 0, & z<0 .\end{cases} F(z)={1−e−z,0,z⩾0,z<0.

We only need to concentrate on F ( z ) F(z) F(z) on [ 0 , ∞ ) [0, \infty) [0,∞), and have
F − 1 ( z ) = − log ⁡ ( 1 − z ) . F^{-1}(z)=-\log (1-z). F−1(z)=−log(1−z).

So F − 1 ( U ) = − log ⁡ ( 1 − U ) F^{-1}(U)=-\log (1-U) F−1(U)=−log(1−U) has a probability distribution Exp ( 1 ) (1) (1). Because 1 − U ∼ U ( 0 , 1 ) 1-U \sim U(0,1) 1−U∼U(0,1), we have − log ⁡ U ∼ Exp ⁡ ( 1 ) -\log U \sim \operatorname{Exp}(1) −logU∼Exp(1).

For a distribution function which does not have an inverse, we define a generalized inverse as the following:
F − ( z ) = inf ⁡ { x ∈ R : F ( x ) ⩾ z } . F^{-}(z)=\inf \{x \in \mathbb{R}: F(x) \geqslant z\} . F−(z)=inf{x∈R:F(x)⩾z}.

2. Python编程实现指数分布的采样

Assignment: Sample a random quantity Z ∼ Exp ⁡ ( λ ) Z \sim \operatorname{Exp}(\lambda) Z∼Exp(λ) for some λ > 0 \lambda>0 λ>0.

python 复制代码
import numpy as np
import matplotlib.pyplot as plt

# Parameter for the exponential distribution
lambda_value = 0.5

# Generate random quantity using CDF method
u = np.random.rand(1000)  # Uniform random numbers between 0 and 1
Z = -np.log(1 - u) / lambda_value

# Plot histogram
plt.hist(Z, bins=30, density=True, alpha=0.6, color='b', label='Sampled Data')
plt.xlabel('Value')
plt.ylabel('Density')
plt.title('Histogram of Exponential Distribution (Generated using CDF)')
plt.legend()
plt.grid(True)
plt.show()
相关推荐
xxie1237943 小时前
return与print
开发语言·python
秋93 小时前
从 Python 后端工程师转型 AI Engineer(AI 工程化)的完整补课清单(2026实战版)
开发语言·人工智能·python
慕木沐4 小时前
Google ADK Java 1.0版本 核心机制与实战 Demo
java·开发语言·python
Tbisnic4 小时前
AI大模型学习第十一天:技术选型、安全防护与金融实战
python·学习·ai·大模型·提示词工程
hboot5 小时前
AI工程师第一课 - Python
前端·后端·python
许彰午5 小时前
30_Java Stream流操作全解
java·windows·python
秋96 小时前
3年经验Python后端转AI Engineer:3个月实战转型计划(2026版)
开发语言·人工智能·python
2601_956319886 小时前
期货夜盘无人值守监控什么:断线、无成交与拒单信号
python·区块链
CTA终结者6 小时前
期货量化目标仓和净持仓对不齐:天勤 TargetPosTask 与 pos 偏差排查
python·区块链
科技林总7 小时前
解决vllm服务漏扫问题
python·安全