1.6、作业
- 数学符号太多,不熟悉,读起来比较缓慢
- 不知道如何用数学表达式去描述
2.6、作业
- 2 A = { ∅ , { 1 } , { 3 } , { 1 , 3 } } 2^\mathbf A = \{\emptyset,\{1\},\{3\},\{1,3\}\} 2A={∅,{1},{3},{1,3}}
- 2 ∅ = { ∅ } 2^\emptyset = \{\emptyset\} 2∅={∅}
- A = { 5 , 6 , 7 , 8 , 9 } = [ 5..9 ] = { x ∈ N ∣ x > 4 , x < 10 } \mathbf A = \{5, 6, 7, 8, 9\} = [5 .. 9] = \{x \in \mathbb N | x > 4, x < 10 \} A={5,6,7,8,9}=[5..9]={x∈N∣x>4,x<10}
3.3、作业
4.6
-
A
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
}
,
则
R
=
{
(
x
,
y
)
∈
A
2
∣
x
m
o
d
2
=
y
m
o
d
2
}
\mathbf A =\{1,2,3,4,5,6,7,8,9\},则\mathbf R=\{(x,y)∈\mathbf A^2∣x \mod 2 = y \mod 2\}
A={1,2,3,4,5,6,7,8,9},则R={(x,y)∈A2∣xmod2=ymod2}
相应的划分: P = { { 1 , 5 , 9 } , { 2 , 8 } } P=\{\{1,5,9\},\{2,8\}\} P={{1,5,9},{2,8}} -
A
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
}
\mathbf A = \{1,2,3,4,5,6,7,8,9\}
A={1,2,3,4,5,6,7,8,9},
R
1
=
{
(
x
,
y
)
∈
A
2
∣
x
+
k
∗
2
=
y
}
\mathbf R_1 =\{(x,y)∈\mathbf A^2∣x + k*2 = y \}
R1={(x,y)∈A2∣x+k∗2=y}其中k为任意整数。再定义
R
2
=
{
(
x
,
y
)
∈
R
2
∣
x
=
y
−
1
}
\mathbf R_2 =\{(x,y) \in \R^2 \vert x = y - 1\}
R2={(x,y)∈R2∣x=y−1}则
R
1
∘
R
2
=
{
(
2
,
9
)
}
\mathbf R_1 \circ \mathbf R_2 = \{(2, 9)\}
R1∘R2={(2,9)}
R 1 2 = { ( 1 , 9 ) } , R 1 3 = ∅ , R 1 4 = ∅ , R 1 5 = ∅ \mathbf R_1^2 = \{(1, 9)\},\mathbf R_1^3 =\emptyset,\mathbf R_1^4=\emptyset,\mathbf R_1^5=\emptyset R12={(1,9)},R13=∅,R14=∅,R15=∅
R 1 + = ∪ i + 1 ∣ A ∣ R 1 i = { ( 1 , 9 ) , ( 2 , 9 ) } \mathbf R_1^+=\cup_{i+1}^{|A|}\mathbf R^i_1 = \{(1, 9),(2, 9)\} R1+=∪i+1∣A∣R1i={(1,9),(2,9)}
R 1 ∗ = { ( 1 , 9 ) , ( 2 , 9 ) , ( 1 , 1 ) , ( 2 , 2 ) , ( 5 , 5 ) , ( 8 , 8 ) , ( 9 , 9 ) } \mathbf R_1^* =\{(1, 9),(2, 9),(1,1),(2,2),(5,5),(8,8),(9,9)\} R1∗={(1,9),(2,9),(1,1),(2,2),(5,5),(8,8),(9,9)}
5.5
问题:举例说明你对函数的认识
函数有三个重要的特征,自变量、因变量、函数值。有定义域与值域, 且对于定义域的每个值, 在值域中有且仅有一个值与其对应。函数就像一个盒子,将输入的x转换为y,就在x和y之间建立了对应关系,我们把这种关系称为映射。
6.5
问题:自己给定一个矩阵并计算其各种范数.
设矩阵为:
[
1
2
3
4
]
\left[ \begin{matrix} 1 & 2 \\ 3 & 4 \end{matrix} \right]
[1324]
l
0
l_0
l0范数:
∥
A
∥
0
=
4
\|A\|_0 = 4
∥A∥0=4
l
1
l_1
l1范数:
∥
A
∥
1
=
10
\|A\|_1 = 10
∥A∥1=10
l
2
l_2
l2范数:
∥
A
∥
2
=
30
\|A\|_2 = \sqrt{30}
∥A∥2=30
l
∞
l_∞
l∞范数:
∥
A
∥
∞
=
4
\|A\|_∞ = 4
∥A∥∞=4
7.3
解释 推荐系统: 问题、算法与研究思路 2.1 中的优化目标的各符号及含义
上述表达式本质是用方差求最小误差,在机器学习的线性回归中也有使用。求经过模型计算的值与评分表中对应的非零元素的方差,目标就是让方差最小,求得最符合期望的值。
符号解释:
x
i
x_i
xi:用户i的信息
t
j
t_j
tj: 商品 j 的信息
f
f
f:假设函数
r
i
,
j
r_{i,j}
ri,j:用户i对j的评分
Ω
\Omega
Ω:用户 i 与商品 j 下标的组合,
0
<
i
<
n
,
0
<
j
<
m
0<i<n,0<j<m
0<i<n,0<j<m
8.4
-
问题:将向量下标为偶数的分量 (x2, x4, …) 累加, 写出相应表达式.
∑ i m o d 2 = 0 x i \sum_{i\mod2=0}x_i imod2=0∑xi -
各出一道累加、累乘、积分表达式的习题, 并给出标准答案.
定义向量 x = [ 1 , 2 , … , 9 ] x=[1,2,\dots,9] x=[1,2,…,9]
累加:将向量分量大于1的累加起来
∑ x i > 1 x i = 44 \sum_{x_i>1}x_i = 44 xi>1∑xi=44
累乘:将向量分量小于5的累乘起来
∏ x i > 1 10 x i = 24 \prod_{x_i > 1}^{10} x_i = 24 xi>1∏10xi=24
积分表达式:
∫ 0 ∞ e − x d x = 1 \int_{0}^{∞}e^{-x}dx=1 ∫0∞e−xdx=1 -
你使用过三重累加吗? 描述一下其应用.
物理运用:计算体积。
-
给一个常用的定积分, 将手算结果与程序结果对比.
∫ 0 1 1 − x 2 d x = π 4 \int_0^{1}\sqrt{1-x^2}dx = \frac \pi4 ∫011−x2dx=4πimport math step = 0.001 sum = 0 for i in range(0, int(1 / step)): sum += math.sqrt(1 - pow(i * step, 2)) * step print(sum)
计算结果:0.7858888667277573
9.3
问题:自己写一个小例子 ( n = 3 , m = 1 )来验证最小二乘法.
数据:
x | y |
---|---|
1 | 2 |
2 | 4 |
3 | 6 |
根据线性回归,可建立假设函数:
h
(
x
)
=
x
1
w
1
+
x
2
w
2
h(x)=x_1w_1+x_2w_2
h(x)=x1w1+x2w2
向量化:
h
(
x
)
=
W
T
X
h(x) = \mathbf W^\mathrm{T}\mathbf X
h(x)=WTX
回归目标:
arg
m
i
n
w
∣
∣
X
w
−
Y
∣
∣
2
2
\arg min_{\mathbf{w}} ||\mathbf{X} \mathbf{w} - \mathbf{Y}||_2^2
argminw∣∣Xw−Y∣∣22
利用偏导数为0取得极值得如下公式:
w
=
(
X
T
X
)
−
1
X
T
Y
\mathbf w=(\mathbf X^\mathrm{T} \mathbf X)^{−1}\mathbf X^\mathrm{T}\mathbf Y
w=(XTX)−1XTY
计算
X
T
X
\mathbf X^\mathrm{T} \mathbf X
XTX
X
T
X
=
[
1
2
3
1
1
1
]
×
[
1
1
2
1
3
1
]
=
[
14
66
3
]
\mathbf X^\mathrm{T} \mathbf X = \left[ \begin{matrix} 1 & 2 & 3 \\ 1 & 1 & 1 \\ \end{matrix} \right] \times \left[ \begin{matrix} 1 & 1\\ 2 & 1 \\ 3 & 1 \\ \end{matrix} \right]= \left[ \begin{matrix} 14 & 66 & 3\\ \end{matrix} \right]
XTX=[112131]×⎣⎡123111⎦⎤=[14663]
计算
X
T
Y
\mathbf X^\mathrm{T}\mathbf Y
XTY
X
T
Y
=
[
1
2
3
1
1
1
]
×
[
2
4
6
]
=
[
28
12
]
\mathbf X^\mathrm{T} \mathbf Y = \left[ \begin{matrix} 1 & 2 & 3 \\ 1 & 1 & 1 \\ \end{matrix} \right] \times \left[ \begin{matrix} 2 \\ 4 \\ 6 \\ \end{matrix} \right]= \left[ \begin{matrix} 28 \\ 12 \\ \end{matrix} \right]
XTY=[112131]×⎣⎡246⎦⎤=[2812]
最终计算得到
w
=
[
2
,
0
]
\mathbf w = [2, 0]
w=[2,0]
10.6
问题:自己推导一遍, 并描述这个方法的特点 (不少于 5 条).
- 适合二分类问题,不需要缩放输入特征
- 可以解决多分类问题
- 可直接使用最大似然函数对所有参数进行优化
- 选择sigmoid函数做为限定函数
(当然也有其他可选)
- 可选用梯度上升或梯度下降求解
11.5
A undirected net is a tuple G = ( V , w ) G = (\mathbf{V}, w) G=(V,w), where V \mathbf{V} V is the set of nodes, and w : V × V → R w: \mathbf{V} \times \mathbf{V} \to \mathbb{R} w:V×V→R is the weight function where w ( v i , v j ) w(v_i, v_j) w(vi,vj) is the weight of the edge ( v i , v j ) (v_i, v_j) (vi,vj) and w ( v i , v j ) = w ( v j , v i ) w(v_i, v_j) = w(v_j,v_i) w(vi,vj)=w(vj,vi)
12.4
1.自己画一棵树, 将其元组各部分写出来 (特别是函数 p).
在这里插入图片描述
triple
T
=
(
V
,
r
,
p
)
T = (\mathbf{V}, r, p)
T=(V,r,p)
V
=
{
v
1
,
v
2
,
v
3
,
v
4
,
v
5
,
v
6
,
v
7
,
v
8
}
\mathbf{V} = \{v_1,v_2,v_3,v_4,v_5,v_6,v_7,v_8\}
V={v1,v2,v3,v4,v5,v6,v7,v8}
r
=
v
1
r = v_1
r=v1
p
:
V
→
V
∪
{
ϕ
}
p: \mathbf{V} \to \mathbf{V} \cup \{\phi\}
p:V→V∪{ϕ} is the parent mapping satisfying
p
(
v
1
)
=
ϕ
,
p
(
v
2
)
=
v
1
,
p
(
p
(
v
2
)
)
=
ϕ
,
p
(
v
5
)
=
ϕ
,
…
p(v_1) =\phi,p(v_2)=v_1,p(p(v_2))=\phi,p(v_5) = \phi,\dots
p(v1)=ϕ,p(v2)=v1,p(p(v2))=ϕ,p(v5)=ϕ,…
2.针对该树, 将代码中的变量值写出来 (特别是 parent 数组).
n
=
8
,
r
o
o
t
=
0
,
p
a
r
e
n
t
=
[
−
1
,
0
,
0
,
1
,
1
,
0
,
4
,
0
,
6
]
n = 8,root = 0,parent = [-1, 0, 0, 1, 1, 0, 4, 0,6]
n=8,root=0,parent=[−1,0,0,1,1,0,4,0,6]
13.4
1.画一棵三叉树, 并写出它的 child 数组.
c
h
i
l
d
=
[
−
1
1
−
1
−
1
4
−
1
−
1
−
1
−
1
−
1
2
3
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
5
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
7
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
]
child = \left[ \begin{matrix} -1 & 1 & -1 & -1 & 4 & -1 & -1&-1\\ -1 & -1 & 2 & 3 & -1 & -1 & -1&-1\\ -1 & -1 & -1 & -1 & -1 & -1 & -1&-1\\ -1 & -1 & -1 & -1 & -1 & -1 & -1&-1\\ -1 & -1 & -1 & -1 & -1 & 5 & -1&-1\\ -1 & -1 & -1 & -1 & -1 & -1 & -1&-1\\ -1 & -1 & -1 & -1 & -1 & -1 & 7&-1\\ -1 & -1 & -1 & -1 & -1 & -1 & -1&-1\\ \end{matrix} \right]
child=⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎡−1−1−1−1−1−1−1−11−1−1−1−1−1−1−1−12−1−1−1−1−1−1−13−1−1−1−1−1−14−1−1−1−1−1−1−1−1−1−1−15−1−1−1−1−1−1−1−1−17−1−1−1−1−1−1−1−1−1⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎤
2.按照本贴风格, 重新定义树. 提示: 还是应该定义 parent 函数, 字母表里面只有一个元素.
Let
ϕ
\phi
ϕ be the empty node, a tree is a quadruple
T
=
(
V
,
r
,
Σ
,
p
)
T = (\mathbf{V}, r, Σ, p)
T=(V,r,Σ,p) where
- V ≠ ∅ V \neq ∅ V=∅ is the set of nodes;
- r ∈ V r \in \mathbf{V} r∈V is the root node;
- Σ Σ Σ is the alphabet
-
p
:
(
V
∪
ϕ
)
×
Σ
∗
→
V
∪
ϕ
p: (V \cup {ϕ}) \times Σ^∗→ \mathbf V \cup {ϕ}
p:(V∪ϕ)×Σ∗→V∪ϕ satisfying
∀ v ∈ V , ∃ 1 s ∈ Σ ∗ , p ( v , s ) = r ∀v∈V, \exist 1 s \in \Sigma^*,p(v,s) = r ∀v∈V,∃1s∈Σ∗,p(v,s)=r
3.根据图、树、m-叉树的学习, 谈谈你对元组的理解.
元组可以用来对复杂事物进行抽象,元组内部的每一个基本元素都是一个集合,该集合是对事物的特征抽象进行抽象得到的集合,每一个基本元素既代表了事物的一个基本特征。元组可以将各不相同类型的成员变量组合起来用于表示另外一个事物,图能用集合与二元关系的二元组去定义,树能用集合与函数的二元组去定义。
作业14
问题:定义一个标签分布系统, 即各标签的值不是 0/1, 而是[0, 1]区间的实数, 且同一对象的标签和为 1.
A Label Distribution System is a tuple
S
=
(
X
,
Y
)
S = (\mathbf X, \mathbf Y)
S=(X,Y), where
X
=
[
x
i
j
]
n
×
m
∈
R
X=[x_{ij}]_{n×m}∈\mathbb{R}
X=[xij]n×m∈R is the data matrix, and
x
i
=
[
x
i
1
,
…
,
x
i
m
]
\mathbf{x}_i = [x_{i1}, \dots, x_{im}]
xi=[xi1,…,xim] is an vector;
n is the number of instances;
m is the number of features;
Y
=
[
y
i
]
n
×
l
∈
[
0
,
1
]
n
×
l
\mathbf Y = [y_{i}]_{n \times l} \in [0, 1]^{n \times l}
Y=[yi]n×l∈[0,1]n×l is the lable matrix, and
y
i
{y}_i
yi is the label vector of
x
i
\mathbf{x}_i
xi,satisfying
∀
y
i
⊂
Y
,
∑
t
=
1
l
y
i
t
=
1
\forall y_i \subset \mathbf Y, \sum_{t = 1}^{l}y_{it} = 1
∀yi⊂Y,∑t=1lyit=1
l is the number of labels.