> For the complete documentation index, see [llms.txt](https://ypw.gitbook.io/nnplayground/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ypw.gitbook.io/nnplayground/regularization.md).

# 正则化函数

带有正则化参数意味着每一次权重更新的时候都会添加一个衰减项，此处看代码更加直观： `link->weight -= learningRate * (link->accErrorDer + regularizationRate * regulDer) / link->numAccumulatedDers;`

这里的`regularizationRate * regulDer`就是正则率乘以正则化函数的导数。

## L1

L1可以将权值一直衰减到0，因此它能将权值矩阵变稀疏。

$$\displaystyle{f(x) = abs(x)}$$

$$\displaystyle{f'(x) = sign(x)}$$

## L2

L2对大的数衰减大，对小的数衰减小，因此它不是那么容易将权重衰减到0，但是它可以获得一个比较均匀的权值矩阵。

$$\displaystyle{f(x) = \frac12 x^2}$$

$$\displaystyle{f'(x) = x}$$
