# 概率论08 随机变量的函数

### 随机变量的函数

$$P(1) = 0.5$$

$$P(-1) = 0.5$$

$$P(10) = 0.5$$

$$P(-10) = 0.5$$

Y实际上是随机变量X的一个函数。X的1对应Y的10，X的-1对应Y的-10。即[$Y = 10X$]

### 获得新概率分布的基本方法

1. 通过[$Y=g(X_1, X_2, ..., X_n)$]，找到对应[$\{ Y \le y \}$]的[$(x_1, x_2, ..., x_n)$]区间I。

2. 在区间I上，积分[$f(x_1, x_2, ..., x_n)$]，获得[$P(Y \le y)$]

3. 通过微分，获得密度函数。

$$f(x) = \frac{1}{\sqrt{2\pi}}e^{-x^2/2}$$

$$F(y) = P(Y \le y) = P(X^2 \le y) = P(-\sqrt{y} \le X \le \sqrt{y})$$

$$F(y) = \int_{-\sqrt{y}}^{\sqrt{y}}\frac{1}{\sqrt{2\pi}}e^{-x^2/2}dx = 2 \int_{0}^{\sqrt{y}}\frac{1}{\sqrt{2\pi}}e^{-x^2/2}dx$$

$$f(y) = \frac{1}{\sqrt{2\pi}}y^{-1/2}e^{-y/2}, 0 \le y \le \infty$$

import numpy as np
import matplotlib.pyplot as plt

pi = np.pi

x = np.linspace(-10, 10, 200)
y = np.linspace(0.1, 10, 100)

fx = 1/np.sqrt(2*pi)*np.exp(-x**2/2)
fy = 1/np.sqrt(2*pi)*(y**(-1/2))*np.exp(-y/2)

plt.plot(x, fx, color = "red", label="X distribution")
plt.plot(y, fy, label="Y distribution")

plt.title("Y = X*X")
plt.xlabel("RV")
plt.ylabel("pdf")

plt.legend()

plt.show()

$$f(x_1, x_2) = \frac{1}{2 \pi} \exp \left( -\frac{1}{2} \left( x_1^2 + x_2^2 \right) \right)$$

$$F_Y(y) = \int_{-\infty}^{\infty} \int_{-\infty}^{y - x_1} f(x_1, x_2) dx_2dx_1$$

$$F_Y(y) = \int_{-\infty}^{\infty} \int_{-\infty}^{y} f(x_1, v - x_1)dvdx_1 = \int_{-\infty}^{y} \int_{-\infty}^{\infty}f(x_1, v - x_1)dvdx_1$$

$$f_Y(y) = \int_{-\infty}^{\infty} f(x_1, y - x_1) dx_1 = \int_{-\infty}^{\infty} \frac{1}{2 \pi} \exp \left( -\frac{1}{2} \left( x_1^2 + (y - x_1)^2 \right) \right) dx_1$$

# By Vamei

import numpy as np
import scipy.integrate
import matplotlib.pyplot as plt
pi = np.pi

'''
core of the integral
'''
def int_core(y):
f = lambda x: 1.0/(2*pi)*np.exp(-0.5*(x**2 + (y-x)**2))
return f

'''
calculate f(y)
'''
def density(y):
return rlt[0]

# get distribution
y  = np.linspace(-10, 10, 100)
fy = map(density, y)

plt.plot(y, fy)
plt.title("PDF of X1+X2")
plt.ylabel("f(y)")
plt.xlabel("y")
plt.show()

(我们也可以利用解析的方法，推导出f(y)满足分布[$N(0, \sqrt{2})$]。如果有微积分基础，可以将此作为练习。)

### 单变量函数的通用公式

(通用公式实际上是从基本方法推导出的数学表达式)

$$f_Y(y) = f_X(g^{-1}(y)) \cdot \frac{d}{dy}g^{-1}(y)$$

$$f_Y(y) = f_X((y-1)/5) \cdot (1/5) = \frac{1}{5\sqrt{2\pi}}e^{-(y-1)^2/(2 \times 25)}$$

### 多变量函数的通用公式

$$X = h_1(U, V)$$

$$Y = h_2(U, V)$$

$$f_{UV}(u, v) = f_{XY}(h_1(u, v), h_2(u, v))|J|$$

J表示雅可比变换(Jacobian tranformation)，表示如下

$$J = \left| \begin{array}{cc} \frac{\partial x}{\partial u} & \frac{\partial x}{\partial v} \\ \frac{\partial y}{\partial u} & \frac{\partial y}{\partial v} \end{array} \right| =\frac{\partial x}{\partial u}\frac{\partial y}{\partial v}-\frac{\partial x}{\partial v}\frac{\partial y}{\partial u}$$

$$f_XY(x, y) = f(x)f(y) = e^{-x}e^{-y}$$

$$X = U - V$$ $$Y = V$$

$$f(u, v) = e^{-(u-v)}e^{-v} = e^{-u}, u \ge 0, v \ge 0$$

247 篇文章57 人订阅

0 条评论

## 相关文章

9510

94660

36490

25980

668200

### 条件随机场CRF(一)从随机场到线性链条件随机场

条件随机场(Conditional Random Fields, 以下简称CRF)是给定一组输入序列条件下另一组输出序列的条件概率分布模型，在自然语言处...

19220

37990

63500

44550

32170