数学表达式魔训
Day 1
1.1 概述
学习第一天,感觉还好。
主要问题:矩阵和集合容易混
1.2 集合的表示与运算
-
A
=
{
3
,
5
}
\mathbf{A} = \{3, 5\}
A={3,5},
2
A
=
{
∅
,
{
3
}
,
{
5
}
,
{
3
,
5
}
}
2^{\mathbf{A}} = \{ \emptyset, \{3\}, \{5\}, \{3, 5\} \}
2A={∅,{3},{5},{3,5}}.
Source Code: 2^{\mathbf{A}} = { \emptyset, {3}, {5}, {3, 5} } -
2
∅
=
{
∅
}
2^{\emptyset} = \{\emptyset\}
2∅={∅}.
Source Code: 2^{\emptyset} = {\emptyset} -
A
=
{
5
,
6
,
7
,
8
,
9
}
=
[
5..9
]
=
{
a
∈
N
∣
4
<
a
<
10
}
\mathbf{A} = \{5, 6, 7, 8, 9\} = [5..9] = \{a \in \mathbb{N} \vert 4 < a < 10 \}
A={5,6,7,8,9}=[5..9]={a∈N∣4<a<10}.
Source Code: [5…9], {a \in \mathbb{N} \vert 4 < a < 10 }
1.3 向量与矩阵
[ 1 1 2 2 3 3 ] × [ 1 2 3 1 4 5 6 1 ] = [ 5 7 9 2 10 14 18 4 15 21 27 6 ] \left[\begin{array}{ll} 1 & 1 \\ 2 & 2 \\ 3 & 3 \end{array}\right] \times\left[\begin{array}{lll} 1 & 2 & 3 & 1 \\ 4 & 5 & 6 & 1 \end{array}\right]=\left[\begin{array}{ccc} 5 & 7 & 9 & 2 \\ 10 & 14 & 18 & 4 \\ 15 & 21 & 27& 6 \end{array}\right] ⎣⎡123123⎦⎤×[14253611]=⎣⎡510157142191827246⎦⎤
Source Code:
\left[\begin{array}{ll}
1 & 1 \\
2 & 2 \\
3 & 3
\end{array}\right] \times\left[\begin{array}{lll}
1 & 2 & 3 & 1 \\
4 & 5 & 6 & 1
\end{array}\right]=\left[\begin{array}{ccc}
5 & 7 & 9 & 2 \\
10 & 14 & 18 & 4 \\
15 & 21 & 27& 6
\end{array}\right]
[ 1 3 5 7 9 2 ] × [ 2 4 6 8 3 5 7 1 ] = [ 11 19 27 11 31 55 79 47 24 46 68 74 ] \begin{bmatrix} 1 & 3 \\ 5 & 7 \\ 9 & 2 \\ \end{bmatrix} \times \begin{bmatrix} 2 & 4 & 6 & 8 \\ 3 & 5 & 7 & 1 \\ \end{bmatrix} = \begin{bmatrix} 11 & 19 & 27 & 11 \\ 31 & 55 & 79 & 47 \\ 24 & 46 & 68 & 74 \\ \end{bmatrix} ⎣⎡159372⎦⎤×[23456781]=⎣⎡113124195546277968114774⎦⎤
Source Code:
\begin{bmatrix}
1 & 3 \\
5 & 7 \\
9 & 2 \\
\end{bmatrix}
\times
\begin{bmatrix}
2 & 4 & 6 & 8 \\
3 & 5 & 7 & 1 \\
\end{bmatrix}
= \begin{bmatrix}
11 & 19 & 27 & 11 \\
31 & 55 & 79 & 47 \\
24 & 46 & 68 & 74 \\
\end{bmatrix}
Day 2
2.1 二元关系
-
A = { 1 , 2 , 5 , 8 , 9 } \mathbf{A} = \{1, 2, 5, 8, 9\} A={1,2,5,8,9}.
R = { ( a , b ) ∈ A × A ∣ a m o d 2 = b m o d 2 } = { ( 1 , 1 ) , ( 2 , 2 ) , ( 5 , 5 ) , ( 8 , 8 ) , ( 9 , 9 ) , ( 1 , 5 ) , ( 1 , 9 ) , ( 2 , 8 ) , ( 5 , 9 ) , ( 5 , 1 ) , ( 9 , 1 ) , ( 8 , 2 ) , ( 9 , 5 ) } \mathbf{R} = \{(a, b) \in \mathbf{A} \times \mathbf{A} \vert a \mod 2 = b \mod 2\} = \{(1, 1), (2, 2), (5, 5), (8, 8), (9, 9), (1, 5), (1, 9), (2, 8), (5, 9), (5, 1), (9, 1), (8, 2), (9, 5)\} R={(a,b)∈A×A∣amod2=bmod2}={(1,1),(2,2),(5,5),(8,8),(9,9),(1,5),(1,9),(2,8),(5,9),(5,1),(9,1),(8,2),(9,5)}.
P = { { 1 , 5 , 9 } , { 2 , 8 } } \mathcal{P} = \{\{1, 5, 9\}, \{2, 8\} \} P={{1,5,9},{2,8}}. -
A = { 1 , 2 , 5 , 8 , 9 } \mathbf{A} = \{1, 2, 5, 8, 9\} A={1,2,5,8,9}.
R 1 = { ( 1 , 5 ) , ( 1 , 9 ) , ( 2 , 8 ) , ( 5 , 9 ) } \mathbf{R}_1 = \{(1, 5), (1, 9), (2, 8), (5, 9)\} R1={(1,5),(1,9),(2,8),(5,9)}.
R 2 = { ( 2 , 5 ) , ( 2 , 8 ) , ( 5 , 8 ) } \mathbf{R}_2 = \{(2, 5), (2, 8), (5, 8)\} R2={(2,5),(2,8),(5,8)}.
R 2 ∘ R 1 = { ( 1 , 8 ) } \mathbf{R}_2 \circ \mathbf{R}_1 = \{(1, 8)\} R2∘R1={(1,8)}.
R 1 + = ⋃ i = 1 ∣ A ∣ R i = { ( 1 , 5 ) , ( 1 , 9 ) , ( 2 , 8 ) , ( 5 , 9 ) } \mathbf{R}_1^+ = \bigcup_{i = 1}^{\vert \mathbf{A} \vert} \mathbf{R}^i = \{(1, 5), (1, 9), (2, 8), (5, 9)\} R1+=⋃i=1∣A∣Ri={(1,5),(1,9),(2,8),(5,9)}.
R 1 ∗ = R 1 + ⋃ R 0 = { ( 1 , 5 ) , ( 1 , 9 ) , ( 2 , 8 ) , ( 5 , 9 ) , ( 1 , 1 ) , ( 2 , 2 ) , ( 5 , 5 ) , ( 8 , 8 ) , ( 9 , 9 ) } \mathbf{R}_1^* = \mathbf{R}_1^+ \bigcup \mathbf{R}^0 = \{(1, 5), (1, 9), (2, 8), (5, 9), (1, 1), (2, 2), (5, 5), (8, 8), (9, 9)\} R1∗=R1+⋃R0={(1,5),(1,9),(2,8),(5,9),(1,1),(2,2),(5,5),(8,8),(9,9)}.
2.2 函数
定义域: 身高.
值域: 高矮.
从身高到高矮的一种关系.
2.3 范数
A
=
[
1
−
2
3
4
−
5
6
7
−
8
9
]
\mathbf{A} = \begin{bmatrix} 1 & -2 & 3 \\ 4 & -5 & 6 \\ 7 & -8 & 9 \\ \end{bmatrix}
A=⎣⎡147−2−5−8369⎦⎤.
∣
∣
A
∣
∣
0
=
9
{||\mathbf{A}||}_0 = 9
∣∣A∣∣0=9.
∣
∣
A
∣
∣
1
=
1
+
∣
−
2
∣
+
3
+
⋯
+
9
=
45
{||\mathbf{A}||}_1 = 1 + |-2| + 3 + \dots + 9 = 45
∣∣A∣∣1=1+∣−2∣+3+⋯+9=45.
∣
∣
A
∣
∣
2
=
[
1
4
9
16
25
36
49
64
81
]
=
285
{||\mathbf{A}||}_2 = \begin{bmatrix} 1 & 4 & 9 \\ 16 & 25 & 36 \\ 49 & 64 & 81 \\ \end{bmatrix}=\sqrt{285}
∣∣A∣∣2=⎣⎡116494256493681⎦⎤=285.
∣
∣
A
∣
∣
∞
=
9
{||\mathbf{A}||}_{\infty}= 9
∣∣A∣∣∞=9
2.4 min 与 argmin
用户信息表
X
=
[
x
i
j
]
n
×
d
u
\mathbf{X} = [x_{ij}]_{n \times d_u}
X=[xij]n×du.
商品信息表
T
=
[
t
i
j
]
m
×
d
t
\mathbf{T} = [t_{ij}]_{m \times d_t}
T=[tij]m×dt.
由函数
f
f
f得到
X
\mathbf{X}
X与
T
\mathbf{T}
T的联合矩阵
U
=
[
u
i
j
]
(
n
m
)
×
(
d
u
+
d
t
)
\mathbf{U} = [u_{ij}]_{(nm) \times (d_u + d_t)}
U=[uij](nm)×(du+dt).
将
R
\mathbf{R}
R视作
(
n
m
)
×
1
(nm) \times 1
(nm)×1的向量.
建立
U
\mathbf{U}
U与
R
\mathbf{R}
R之间的损失函数并最小化.
- 浏览矩阵
R
=
[
r
i
j
]
n
×
m
\mathbf{R} = [r_{ij}]_{n \times m}
R=[rij]n×m取值范围为
{
0
,
1
}
\{0, 1\}
{0,1}.
此时为二分类, 样本数视为 n m nm nm, 特征数视为 d u + d t d_u + d_t du+dt, 标签数视为 1 1 1, 标签的取值记为 0 0 0或 1 1 1. - 评分矩阵
R
=
[
r
i
j
]
n
×
m
\mathbf{R} = [r_{ij}]_{n \times m}
R=[rij]n×m取值范围为
{
0
,
1
,
2
,
3
,
4
,
5
}
\{0, 1, 2, 3, 4, 5\}
{0,1,2,3,4,5}.
此时为回归, 样本数视为 n m nm nm, 特征数视为 d u + d t d_u + d_t du+dt, 标签数视为 1 1 1, 标签的取值为 [ 0 , 5 ] [0, 5] [0,5]之间的数.
Day 3
3.1 累加、累乘与积分
- ∑ i = 1 ∞ x 2 i \sum_{i = 1}^{\infty} x_{2i} ∑i=1∞x2i
- ∫ 0 ∞ x 2 d x \int_{0}^{\infty} x^2 \mathrm{d}x ∫0∞x2dx
3.2 线性回归
X = [ 2 1 4 1 7 1 ] \mathbf{X} = \begin{bmatrix} 2 & 1 \\ 4 & 1 \\ 7 & 1 \\ \end{bmatrix} X=⎣⎡247111⎦⎤, Y = [ 7 9 14 ] \mathbf{Y} = \begin{bmatrix} 7 \\ 9 \\ 14 \\ \end{bmatrix} Y=⎣⎡7914⎦⎤.
- w = ( X T X ) − 1 X T Y = [ 1.42 3.84 ] \mathbf{w} = (\mathbf{X}^\mathrm{T} \mathbf{X})^{-1} \mathbf{X}^\mathrm{T} \mathbf{Y} = \begin{bmatrix} 1.42 \\ 3.84 \\ \end{bmatrix} w=(XTX)−1XTY=[1.423.84], Y p = [ 6.68 9.52 13.79 ] \mathbf{Y}_p = \begin{bmatrix} 6.68 \\ 9.52 \\ 13.79 \\ \end{bmatrix} Yp=⎣⎡6.689.5213.79⎦⎤, l o s s = 0.65 loss = 0.65 loss=0.65.
- w = ( X T X − λ I ) − 1 X T Y = [ 1.27 4.64 ] \mathbf{w} = (\mathbf{X}^\mathrm{T} \mathbf{X} - \lambda \mathbf{I})^{-1} \mathbf{X}^\mathrm{T} \mathbf{Y} = \begin{bmatrix} 1.27 \\ 4.64 \\ \end{bmatrix} w=(XTX−λI)−1XTY=[1.274.64], Y p = [ 7.18 9.73 13.54 ] \mathbf{Y}_p = \begin{bmatrix} 7.18 \\ 9.73 \\ 13.54 \\ \end{bmatrix} Yp=⎣⎡7.189.7313.54⎦⎤, l o s s = 0.88 loss = 0.88 loss=0.88, λ = 0.1 \lambda = 0.1 λ=0.1.
3.3 Logistic 回归
- x \mathbf{x} x与超平面之间的距离在 ( − ∞ , + ∞ ) (-\infty, +\infty) (−∞,+∞)之间, 将其转为 ( 0 , 1 ) (0, 1) (0,1)之间的概率. 在 x \mathbf{x} x较大或较小时, 概率接近 1 1 1或 0 0 0, 适合二分类.
- 使用sigmoid函数, 将原来的线性模型转为非线性模型. 可以将一些线性不可分的点分开. 是不是可以把sigmoid换成其它函数? 对于特定场景是不是可以建一个特定的函数?
- 将 y y y取值为 1 1 1或 0 0 0的两种情况结合起来, 建立一个优化目标. 能不能给两种情况加权?加权时再引入新的函数,来个套娃操作?
- 取log将原来的连乘转为连加, 方便求解. 感觉跟熵的公式有点像呀.
- 万能的梯度下降, 求解参数。
注:上述内容为个人学习过程中的笔记,如有不当的地方还望指正