> For the complete documentation index, see [llms.txt](https://yeasy.gitbook.io/llm_internals/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yeasy.gitbook.io/llm_internals/di-si-bu-fen-mo-xing-yu-qian-yan-pian/appendix/a1_math_basics.md).

# A.1 数学基础速查

## 线性代数基础

**矩阵乘法**：$$C = AB$$，其中 $$C\_{ij} = \sum\_k A\_{ik} B\_{kj}$$。复杂度为 $$O(M \times N \times K)$$。

**点积**：$$a \cdot b = \sum\_i a\_i b\_i = |a||b|\cos\theta$$，衡量两个向量的方向一致性。

**转置**：$$(AB)^T = B^T A^T$$。

## Softmax 函数

$$\[\text{softmax}(z)]*i = \frac{e^{z\_i}}{\sum*{j=1}^{K} e^{z\_j}}$$

将实数向量转换为概率分布（非负且和为 1）。具有平移不变性：对任意标量 $$c$$，$$\text{softmax}(z + c\mathbf{1}) = \text{softmax}(z)$$。

## 交叉熵

$$H(p, q) = -\sum\_x p(x) \log q(x)$$

当 $$p$$ 为独热分布时，$$H(p, q) = -\log q(x\_{\text{true}})$$。

## 概率与统计

**期望**：$$E\[X] = \sum\_x x \cdot P(x)$$

**方差**：$$\text{Var}(X) = E\[(X - E\[X])^2] = E\[X^2] - (E\[X])^2$$

**独立随机变量之和的方差**：$$\text{Var}(\sum\_i X\_i) = \sum\_i \text{Var}(X\_i)$$

## 导数与链式法则

**链式法则**：$$\frac{\partial L}{\partial x} = \frac{\partial L}{\partial y} \cdot \frac{\partial y}{\partial x}$$

**Softmax 的导数**：$$\frac{\partial \text{softmax}(z)\_i}{\partial z\_j} = \text{softmax}(z)*i (\delta*{ij} - \text{softmax}(z)\_j)$$
