KaTeX – The fastest math typesetting library for the web.

博客内容需要使用到数学公式(想必从机器学习的内容里就能看出来),所以就找到了 Katex 这个开源的项目,从而让博客支持了数学公式,省得每次都要花时间转图片。

官方:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>

使用BootCDN的:

<link href="https://cdn.bootcss.com/KaTeX/0.11.1/katex.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/KaTeX/0.11.1/katex.min.js"></script>
<script src="https://cdn.bootcss.com/KaTeX/0.11.1/contrib/auto-render.min.js"></script>

测试一下:
线性回归成本函数:

J(θ)=J(θ0,θ1)=12mi=1m(h(x(i))y(i))2J(\theta) = J(\theta_0, \theta_1) = \frac{1}{2m}\sum_{i=1}^m(h(x^{(i)}) - y^{(i)})^2

Sigmoid函数:g(z)=11+ezg (z) = \frac {1}{1 + e^{-z}}
SVM成本函数:

J(θ)=C[i=1my(i)cost1(θTx(i))+(1y(i))cost0(θTx(i))]+12j=1nθj2J(\theta) = C \left[ \sum_{i=1}^m y^{(i)} cost_1(\theta^T x^{(i)}) + (1 - y^{(i)}) cost_0(\theta^T x^{(i)}) \right] + \frac{1}{2} \sum_{j=1}^n \theta_j^2

K-mean成本函数:J=1mi=1mx(i)uc(i)2J = \frac{1}{m} \sum_{i=1}^m \| x^{(i)} - u_{c^{(i)}} \|^2