# pdf 函数

分布在某点处的密度，或离散分布取某值的概率。

## 怎么写

### pdf(distribution, x)

密度；对离散分布，则是取某个整数的概率。

**distribution**

一个分布，例如 normal_distribution(0, 1)。接受一个表达式。

**x**

该点，或该值。接受一个表达式。

### pdf(process, y)

随机过程在某一时刻的密度。

**process**

某一时刻的过程，写作 construct(p, t)，或对已存储的过程 p 写作 p(t)。接受一个表达式。

**y**

过程在该时刻的取值。接受一个表达式。

## 示例

- $\displaystyle f_{X}(x),\ X \sim \mathcal{N}(0, 1) = \frac{\sqrt{2}}{2 \sqrt{\pi} e^{\frac{x^{2}}{2}}}$

  `pdf(normal_distribution(0, 1), x)`

  在求解器中，`pdf(normal_distribution(0, 1), x)` 的结果是 `(1/2)sqrt(2)*e^(-x^2/2)/sqrt(pi)`。

  [在求解器中打开](https://zh.hilberon.com/?q=pdf%28normal_distribution%280%2C%201%29%2C%20x%29)
- $\displaystyle f_{X}(2),\ X \sim \mathrm{B}\left(5, \frac{1}{3}\right) = \frac{80}{243}$

  `pdf(binomial_distribution(5, 1/3), 2)`

  在求解器中，`pdf(binomial_distribution(5, 1/3), 2)` 的结果是 `80/243`。

  [在求解器中打开](https://zh.hilberon.com/?q=pdf%28binomial_distribution%285%2C%201%2F3%29%2C%202%29)
- $\displaystyle \operatorname{pdf}(\operatorname{construct}(\operatorname{OU}(\mu, \sigma, \theta, x_{0}), t), y) = \begin{cases} \frac{\sqrt{2}}{2 e^{\frac{\left(y-\left(\frac{x_{0}-\mu}{e^{t \theta}}+\mu\right)\right)^{2}}{2 \left(\frac{\sigma^{2}}{2 \theta}-\frac{\sigma^{2}}{2 \theta e^{2 t \theta}}\right)}} \sqrt{\pi \left(\frac{\sigma^{2}}{2 \theta}-\frac{\sigma^{2}}{2 \theta e^{2 t \theta}}\right)}} & \text{if } \theta \neq 0 \end{cases}$

  `pdf(construct(ornstein_uhlenbeck_process(mu, sigma, theta, x0), t), y)`

  在求解器中，`pdf(construct(ornstein_uhlenbeck_process(mu, sigma, theta, x0), t), y)` 的结果是 `(1/2)sqrt(2)*e^((-1/2)*(y - (e^(-t*theta)*(x0 - mu) + mu))^2/((1/2)sigma^2/theta - (1/2)sigma^2*e^(-2t*theta)/theta))/sqrt(pi*((1/2)sigma^2/theta - (1/2)sigma^2*e^(-2t*theta)/theta)) if theta != 0`。

  [在求解器中打开](https://zh.hilberon.com/?q=pdf%28construct%28ornstein_uhlenbeck_process%28mu%2C%20sigma%2C%20theta%2C%20x0%29%2C%20t%29%2C%20y%29)

## 示例中用到的函数

- [normal_distribution](https://zh.hilberon.com/library/normal_distribution)

  均值为 mu、标准差为 sigma 的正态分布。
- [binomial_distribution](https://zh.hilberon.com/library/binomial_distribution)

  n 次独立试验中成功的次数，每次试验成功的概率为 p。
- [construct](https://zh.hilberon.com/library/construct)

  把本身是计算得到的头部作用于参数，例如 f'(0) 或 (x => body)(a)。
- [ornstein_uhlenbeck_process](https://zh.hilberon.com/library/ornstein_uhlenbeck_process)

  以速率 theta 被拉向 mu、噪声为 sigma、从 x0 开始的随机过程。

## 相关函数

- [poisson_distribution](https://zh.hilberon.com/library/poisson_distribution)

  在一段时间内以平均速率 lambda 发生的事件的次数。
- [probability](https://zh.hilberon.com/library/probability)

  带分布的变量满足某个条件的概率。
- [quantile](https://zh.hilberon.com/library/quantile)

  列表中至少有占比 q 的数据不超过的最小值，或分布中变量以概率 q 不超过的值。
- [mode](https://zh.hilberon.com/library/mode)

  列表中出现的频率最高的值；若有多个值频率相同，则返回由它们组成的列表。
- [standard_deviation](https://zh.hilberon.com/library/standard_deviation)

  一组数的样本标准差，或分布的标准差。
- [median](https://zh.hilberon.com/library/median)

  一组数的中间值，或两个中间值的平均数。

---
Source: https://zh.hilberon.com/library/pdf
