Skip to content

Commit c80ce4e

Browse files
feat: refactor component path and repenish calculus (#54)
1 parent 8e6da57 commit c80ce4e

File tree

26 files changed

+366
-159
lines changed

26 files changed

+366
-159
lines changed

blog/2024-10/_partials/algorithmanddatastructure/algorithm-datastructure-part-2.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
import DocusaurusLink from "@docusaurus/Link";
55

6-
import { Collapse } from "@site/src/components/Collapse";
76
import Flex from "@site/src/components/Flex";
87
import Image, { Center } from "@site/src/components/Image";
98
import Steps from "@site/src/components/Steps";
109
import Tabs from "@site/src/components/Tabs";
1110
import { Link, Text } from "@site/src/components/Typography";
11+
import { Collapse } from "@site/src/components/collapse";
1212

1313
import MorrisTraversalInOrderContent from "../../_contents/morris-traversal/inorder-traversal.mdx";
1414
import MorrisTraversalPostOrderContent from "../../_contents/morris-traversal/postorder-traversal.mdx";

blog/2024-12/_partials/juc/process-and-thread.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Steps from "@site/src/components/Steps";
22
import { Link, Text } from "@site/src/components/Typography";
3-
import TermPreview from "@site/src/components/terms/TermPreview";
3+
import TermPreview from "@site/src/components/terminology/TermPreview";
44

55
1. 进程是操作系统**资源分配**的最小单位,**程序运行**的最小单元。线程是操作系统**调度任务**的最小单元。协程是协作式任务的最小单元,由应用程序定义,**类似一个代码块**
66
2. 进程间切换的上下文开销大,线程间切换的上下文开销小,协程间切换的上下文开销最小。

blog/2024-12/_partials/juc/threadlocal.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Collapse } from "@site/src/components/Collapse";
1+
import { Collapse } from "@site/src/components/collapse";
22

33
import Thread from "../../_contents/juc/threadlocal/thread.mdx";
44
import ThreadLocal from "../../_contents/juc/threadlocal/threadlocal.mdx";

blog/2024-12/juc.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ unlisted: true
1010

1111
<!-- truncate -->
1212

13-
import { Collapses } from "@site/src/components/Collapse";
13+
import { Collapses } from "@site/src/components/collapse";
1414

1515
import AQS from "./_partials/juc/AQS.mdx";
1616
import Deadlock from "./_partials/juc/deadlock.mdx";

blog/2025-01/ratelimiter.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ tags: [Web Backend]
99

1010
<!--truncate-->
1111

12-
import { Collapse } from "@site/src/components/Collapse";
1312
import { Center } from "@site/src/components/Image";
1413
import Steps from "@site/src/components/Steps";
1514
import { Text } from "@site/src/components/Typography";
15+
import { Collapse } from "@site/src/components/collapse";
1616

1717
import Mermaid from "@theme/Mermaid";
1818

blog/2025-01/spiffe.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SPIFFE(Secure Production Identity Framework for Everyone),发音:_/ˈsp
99

1010
<!-- truncate -->
1111

12-
import { Collapse } from "@site/src/components/Collapse";
12+
import { Collapse } from "@site/src/components/collapse";
1313

1414
## 概览
1515

blog/2025-04/_partials/calculus.mdx

Lines changed: 157 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Collapse } from "@site/src/components/collapse";
2+
13
#### 导数和微分
24

35
> 通常定义导数为在函数的点的切线的斜率,微分描述在函数上的点附近的变化率
@@ -9,13 +11,13 @@
911
则 f 在 x 处的导数 $f'(x)$ 被定义为:
1012

1113
$$
12-
f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}
14+
f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h} \tag{1.1.1}
1315
$$
1416

1517
微分被定义为:
1618

1719
$$
18-
df = f'(x) \cdot dx
20+
df = f'(x) \cdot dx \tag{1.1.2}
1921
$$
2022

2123
##### 通用函数的微分方法
@@ -48,40 +50,182 @@ $$
4850

4951
#### 偏导数
5052

51-
针对单个变量 $x$ 的函数 $f(x)$ 的导数被定义为 $f'(x)$,而对于向量(多变量组合)的函数,则需要使用偏导数来计算。
53+
针对单个变量 $\mathbf{x}$ 的函数 $f(x)$ 的导数被定义为:
54+
55+
$$
56+
f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h} \tag{1.2.1}
57+
$$
58+
59+
而对于多元变量组合 $x=(x, y, z)$ 的函数,则需要使用偏导数来计算,定义为:
5260

53-
偏导数被定义为:
61+
$$
62+
\frac{\partial f}{\partial x} = \lim_{h \to 0}
63+
\frac{f(x + h, y, z) - f(x, y, z)}{h}
64+
$$
65+
66+
$$
67+
\frac{\partial f}{\partial y} = \lim_{h \to 0}
68+
\frac{f(x, y + h, z) - f(x, y, z)}{h}
69+
$$
5470

5571
$$
56-
\frac{\partial f}{\partial x_i} = \lim_{h \to 0} \frac{f(x_1, x_2, \cdots, x_i + h, \cdots, x_n) - f(x_1, x_2, \cdots, x_i, \cdots, x_n)}{h}
72+
\frac{\partial f}{\partial z} = \lim_{h \to 0}
73+
\frac{f(x, y, z + h) - f(x, y, z)}{h}
5774
$$
5875

59-
将偏导数推广到向量,则有:
76+
将多元变量组合推广到向量 \
77+
:ctip[$\mathbf{x} = [x_1, x_2, \cdots, x_n]^T$]{id="数学和深度学习中通常使用列向量,向量的自然表达是行向量,故而使用*转置*"}\
78+
则可根据 $1.2.2$ 推出梯度公式:
6079

6180
$$
62-
\nabla f = (\frac{\partial f}{\partial x_1}, \frac{\partial f}{\partial x_2}, \cdots, \frac{\partial f}{\partial x_n})
81+
\nabla_x f(x) = [\frac{\partial f}{\partial x_1},
82+
\frac{\partial f}{\partial x_2}, \cdots, \frac{\partial f}{\partial x_n}]^T \tag{1.2.2}
6383
$$
6484

65-
**即向量 $\nabla f$ 的每个分量都是对向量 $x$ 的每个变量求偏导数**
85+
**即向量 :ctip[$\nabla_x f(x)$]{id="当 $\nabla_x f(x)$ 没有歧义时,可被简写为 $\nabla f$"} 的第 $i$ 个分量即是对向量 $\mathbf{x}$ 的第 $i$ 个分量 $x_i$ 求偏导数**
6686

6787
#### 梯度
6888

6989
> 梯度和导数相关,但梯度是向量,导数是实数,梯度是导数在多变量情况下的推广。
7090
71-
**对于输入为单个变量,输出为实数的函数 $f(x)$**_其梯度为其导数_,公式为
91+
:ctip[**$\mathbf{f}: R \to R$**]{id="输入和输出都是**实数**的函数 $f$"},梯度即为导数
7292

7393
$$
74-
\nabla f = \frac{d}{dx} f(x)
94+
\nabla \mathbf{f} = \nabla_{\mathbf{x}} \mathbf{f}(\mathbf{x}) = \mathbf{f}'(\mathbf{x}) = \frac{d}{d\mathbf{x}} \mathbf{f}(\mathbf{x})
7595
$$
7696

77-
**对于输入为向量,输出为实数的函数 $f(x_1, x_2, \cdots, x_n)$**_其梯度为偏导数组成的向量_,公式为
97+
:ctip[**$f: R^n \to R$**]{id="输入为 n 维向量,输出为标量的函数"},其中 $\mathbf = [x_1, x_2, \cdots, x_n]^T$,梯度为偏导数组成的向量
7898

7999
$$
80-
\nabla f = (\frac{\partial f}{\partial x_1}, \frac{\partial f}{\partial x_2}, \cdots, \frac{\partial f}{\partial x_n})
100+
\nabla f = [\frac{\partial f}{\partial x_1}, \frac{\partial f}{\partial x_2}, \cdots, \frac{\partial f}{\partial x_n}]^T
81101
$$
82102

103+
梯度在矩阵微积分中通常存在以下常用公式:
104+
105+
- **线性变换**
106+
107+
- 对于所有的 :ctip[$\mathbf{x} \in R^n$]{id="$\mathbf{x} = [x_1, x_2, \cdots, x_n]^T$"} \
108+
和 :ctip[$A \in R^{m \times n}$]{id="$\mathbf{A} = \begin{bmatrix} \
109+
A_{11} & \cdots & A_{1n} \\ \vdots & \ddots & \vdots \\ A_{m1} & \cdots & A_{mn} \
110+
\end{bmatrix}$"}
111+
112+
<Collapse label="$$
113+
\nabla_x (A x) = A^T
114+
$$">
115+
116+
$$
117+
\begin{split}
118+
&\ \nabla_x (A x) = \nabla_x (A_1 x_1 + A_2 x_2 + \cdots + A_n x_n) \\
119+
=&\ \nabla_x ([A_{11} \cdots A_{1m}] x_1 + [A_{21} \cdots A_{2m}] x_2 + \cdots + [A_{n1} \cdots A_{nm}] x_n) \\
120+
=&\ \nabla_x (A_1 x_1 + A_2 x_2 + \cdots + A_n x_n) \\
121+
=&\ \nabla_x (A_1 x_1) + \nabla_x (A_2 x_2) + \cdots + \nabla_x (A_n x_n) \\
122+
=&\ \begin{bmatrix}
123+
\frac{\partial}{\partial x_1} (A_1 x_1) , \frac{\partial}{\partial x_2} (A_2 x_2) , \cdots , \frac{\partial}{\partial x_n} (A_n x_n)
124+
\end{bmatrix} \\
125+
=&\ \begin{bmatrix}
126+
A_1 , A_2 , \cdots , A_n
127+
\end{bmatrix} = A^T
128+
\end{split}
129+
$$
130+
131+
</Collapse>
132+
133+
- 对于所有的 :ctip[$\mathbf{x} \in R^n$]{id="$\mathbf{x} = [x_1, x_2, \cdots, x_n]^T$"} \
134+
和 :ctip[$A \in R^{n \times m}$]{id="$\mathbf{A} = \begin{bmatrix} \
135+
A_{11} & \cdots & A_{1m} \\ \vdots & \ddots & \vdots \\ A_{n1} & \cdots & A_{nm} \
136+
\end{bmatrix}$"}
137+
138+
<Collapse label="$$
139+
\nabla_x (x^T A) = A
140+
$$">
141+
142+
$$
143+
\begin{split}
144+
&\ \nabla_x (x^T A) = \nabla_x (x_1 A_1 + x_2 A_2 + \cdots + x_n A_n) \\
145+
=&\ \nabla_x (x_1 [A_{11} \cdots A_{1m}] + x_2 [A_{21} \cdots A_{2m}] + \cdots + x_n [A_{n1} \cdots A_{nm}]) \\
146+
=&\ \nabla_x (x_1 A_1 + x_2 A_2 + \cdots + x_n A_n) \\
147+
=&\ \nabla_x (x_1 A_1) + \nabla_x (x_2 A_2) + \cdots + \nabla_x (x_n A_n) \\
148+
=&\ \begin{bmatrix} \
149+
\frac{\partial}{\partial x_1} (x_1 A_1) , \frac{\partial}{\partial x_2} (x_2 A_2) , \cdots , \frac{\partial}{\partial x_n} (x_n A_n)
150+
\end{bmatrix} \\
151+
=&\ \begin{bmatrix}
152+
A_1 , A_2 , \cdots , A_n
153+
\end{bmatrix} = A
154+
\end{split}
155+
$$
156+
157+
</Collapse>
158+
159+
- **二次型**(二次型是二次函数在向量空间中的推广):
160+
161+
- 对于所有的 :ctip[$\mathbf{x} \in R^n$]{id="$\mathbf{x} = [x_1, x_2, \cdots, x_n]^T$"} \
162+
和 :ctip[$A \in R^{n \times n}$]{id="$\mathbf{A} = \begin{bmatrix} \
163+
A_{11} & \cdots & A_{1n} \\ \vdots & \ddots & \vdots \\ A_{n1} & \cdots & A_{nn} \
164+
\end{bmatrix}$"}
165+
166+
<Collapse label="$$
167+
\nabla_x x^T A x = (A + A^T) x
168+
$$">
169+
170+
$$
171+
\begin{split}
172+
&\ \nabla_x x^T A x = \nabla_x \sum_{i=1}^n \sum_{j=1}^n x_i A_{ij} x_j \\
173+
=&\ \frac{\partial}{\partial x_k} \sum_{i=1}^n \sum_{j=1}^n x_i A_{ij} x_j + \frac{\partial}{\partial x_k} \sum_{i=1}^n \sum_{j=1}^n x_j A_{ji} x_i \\
174+
=&\ \sum_{i=1}^n \sum_{j=1}^n A_{ij} x_j + \sum_{i=1}^n \sum_{j=1}^n A_{ji} x_i \\
175+
=&\ \sum_{j=1}^n A_{kj} x_j + \sum_{i=1}^n A_{ik} x_i \text{($i, j = k$ 时,$A_{kj} x_j, A_{ik} x_i$ 分别存在一项 $A_{kk} x_k$)} \\
176+
=&\ \sum_{i=1}^n (\sum_{j=1}^n A_{ij} x_j) \cdot e_i + \sum_{j=1}^n (\sum_{i=1}^n A_{ji} x_i) \cdot e_j \\
177+
=&\ \sum_{i=1}^n (\mathbf{A} \mathbf{x})_i \cdot e_i + \sum_{j=1}^n (\mathbf{A^T} \mathbf{x})_j \cdot e_j \\ \
178+
=&\ (A + A^T) x
179+
\end{split}
180+
$$
181+
182+
</Collapse>
183+
184+
- **范数**
185+
186+
| 范数 | 定义 | 梯度 |
187+
| ---------- | ----------------------------------------------- | ---------------------------------------- |
188+
| $L^1$ | $\|x\|_1 = \sum_{i=1}^n x_i$ | $\nabla_x \|x\|_1 = \text{sign}(x)$ |
189+
| $L^2$ | $\|x\|_2 = \sqrt{\sum_{i=1}^n x_i^2}$ | $\nabla_x \|x\|_2 = \frac{x}{\|x\|_2}$ |
190+
| $L^\infty$ | $\|x\|_\infty = \max_{i=1}^n x_i$ | $\nabla_x \|x\|_\infty = \text{sign}(x)$ |
191+
| $L^0$ | $\|x\|_0 = \sum_{i=1}^n \mathbb{I}(x_i \neq 0)$ | $\nabla_x \|x\|_0 = \text{sign}(x)$ |
192+
193+
- 对于所有的 :ctip[$\mathbf{x} \in R^n$]{id="$\mathbf{x} = [x_1, x_2, \cdots, x_n]^T$"} \
194+
和 :ctip[$A \in R^{n \times n}$]{id="$\mathbf{A} = \begin{bmatrix} \
195+
A_{11} & \cdots & A_{1n} \\ \vdots & \ddots & \vdots \\ A_{n1} & \cdots & A_{nn} \
196+
\end{bmatrix}$"}
197+
198+
<Collapse label="$$
199+
\nabla_x \|x\|_2^2 = \nabla_x (x^T x) = 2x
200+
$$">
201+
202+
$$
203+
\begin{split}
204+
&\ \nabla_x \|x\|_2 = \nabla_x (\sqrt{x^T x}) ^ 2 \\
205+
=&\ \nabla_x (x^T x) = \nabla_x (x_1^2 + x_2^2 + \cdots + x_n^2) \\
206+
=&\ 2x
207+
\end{split}
208+
$$
209+
210+
</Collapse>
211+
83212
:::nerd
84-
在深度学习中每层神经网络之间由 **_权重矩阵_(通常还会添加同维度的偏置向量)桥接不同纬度矩阵的计算**随后再通过激活函数将计算结果映射到非线性空间
213+
在深度学习中每层神经网络之间由 **_权重矩阵_(通常还会添加同维度的偏置向量)桥接不同纬度矩阵的计算**随后再通过:term[激活函数]{./terms/dl#activation-function}将计算结果映射到非线性空间,是:term[神经元]{./terms/dl#neuron}的计算核心
85214
:::
86215

87216
#### 链式法则
217+
218+
> 本质是利用复合函数求导的思想,逐层求导(当计算到内层函数时转换为求梯度)并计算内积。
219+
220+
1. 对于复合函数来说,变量有且仅有囊括在复合函数中的变量,即 $g(x)$
221+
2. 对于两层的复合函数来说,若变量 $\mathbf{x} \in R^n$ 应该用梯度进行表示,则有:
222+
223+
$$
224+
f'(x) = f'(g(x)) \cdot \nabla_{x} g(x)
225+
$$
226+
227+
对于复合函数 $f$ 存在 $y_1, y_2, \cdots, y_n$$\mathbf{y} \in R^n$)等变量,对于函数 $y$$y_1 = g_1(x), y_2 = g_2(x), \cdots, y_n = g_n(x)$ 的复合函数,则有:
228+
229+
$$
230+
\nabla_{x} f(y) = \frac{\partial f}{\partial y_1} \cdot \nabla_{x} y_1 + \frac{\partial f}{\partial y_2} \cdot \nabla_{x} y_2 + \cdots + \frac{\partial f}{\partial y_n} \cdot \nabla_{x} y_n
231+
$$

blog/2025-04/dive-into-deep-learning.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ draft: true
1616
import Calculus from "./_partials/calculus.mdx";
1717
import LinearAlgebra from "./_partials/linear-algebra.mdx";
1818

19-
## -预备知识
19+
## 预备知识
2020

2121
:::info
2222
本章节主要是对线代、微积分以及概率论的复习,并不涉及高级理论知识,只是为了加深对 AI 的理解。

docusaurus.config.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ const remarkPlugins = [
3333
test: (node: any) => node.url.startsWith("http")
3434
}
3535
],
36-
[
37-
remarkCommentTooltip,
38-
{
39-
tooltip: "NowrapTooltip",
40-
comment: "Comment"
41-
}
42-
],
36+
remarkCommentTooltip,
4337
[remarkAdmonition, { admonition: "TermAdmonition" }],
4438
remarkCodeImport,
4539
remarkBreaks,
@@ -217,7 +211,7 @@ const config: Config = {
217211
path: "terminologies",
218212
routeBasePath: "terms",
219213
glossaries: "./static/terminologies.yml",
220-
glossaryComponentPath: "@site/src/components/terms/Terminology"
214+
glossaryComponentPath: "@site/src/components/terminology/Terminology"
221215
}
222216
],
223217
[

packages/remark-comment-tooltip/src/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe("remark-comment-tooltip", () => {
1919
test("应该正确转换简单的 tooltip 语法", async () => {
2020
const input = "这是一个:ctip[ tooltip 内容]{title=' 提示'}";
2121
const output = await process(input);
22-
expect(output).toContain('<Tooltip title=" 提示">');
22+
expect(output).toContain('<CommentTooltip title=" 提示">');
2323
expect(output).toContain('<Comment>{" tooltip 内容"}</Comment>');
2424
});
2525

@@ -29,7 +29,7 @@ describe("remark-comment-tooltip", () => {
2929
标题"}`;
3030
const output = await process(input);
3131
console.log(output);
32-
expect(output).toContain(`<Tooltip title="多行\n标题">`);
32+
expect(output).toContain(`<CommentTooltip title="多行\n标题">`);
3333
expect(output).toContain(`<Comment>{"多行\\n内容"}</Comment>`);
3434
});
3535

@@ -46,17 +46,17 @@ describe("remark-comment-tooltip", () => {
4646
const input =
4747
"第一个:ctip[内容1]{title='提示1'} 第二个:ctip[内容2]{title='提示2'}";
4848
const output = await process(input);
49-
expect(output).toContain('<Tooltip title="提示1">');
49+
expect(output).toContain('<CommentTooltip title="提示1">');
5050
expect(output).toContain('<Comment>{"内容1"}</Comment>');
51-
expect(output).toContain('<Tooltip title="提示2">');
51+
expect(output).toContain('<CommentTooltip title="提示2">');
5252
expect(output).toContain('<Comment>{"内容2"}</Comment>');
5353
});
5454

5555
test("应该处理包含特殊字符的内容", async () => {
5656
const input = `:ctip[包含 \\\\| * ! @ # $ 的内容]{title="特殊*|字符!"}`;
5757
const output = await process(input);
5858
console.log(output);
59-
expect(output).toContain('<Tooltip title="特殊*|字符!">');
59+
expect(output).toContain('<CommentTooltip title="特殊*|字符!">');
6060
expect(output).toContain(
6161
'<Comment>{"包含 \\\\| * ! @ # $ 的内容"}</Comment>'
6262
);
@@ -66,7 +66,7 @@ describe("remark-comment-tooltip", () => {
6666
const input = `:ctip[包含 \`markdown\` 的内容]{title="特殊*|字符!"}`;
6767
const output = await process(input);
6868
console.log(output);
69-
expect(output).toContain('<Tooltip title="特殊*|字符!">');
69+
expect(output).toContain('<CommentTooltip title="特殊*|字符!">');
7070
expect(output).toContain(
7171
'<Comment>{"包含 "}<_components.code>{"markdown"}</_components.code>{" 的内容"}</Comment>'
7272
);
@@ -75,7 +75,7 @@ describe("remark-comment-tooltip", () => {
7575
test("应该处理 id 属性", async () => {
7676
const input = `:ctip[内容]{#提示}`;
7777
const output = await process(input);
78-
expect(output).toContain('<Tooltip title="提示">');
78+
expect(output).toContain('<CommentTooltip title="提示">');
7979
expect(output).toContain('<Comment>{"内容"}</Comment>');
8080
});
8181
});

0 commit comments

Comments
 (0)