Skip to content

Commit

Permalink
10.9
Browse files Browse the repository at this point in the history
  • Loading branch information
yhtq committed Oct 9, 2024
1 parent ad15fc2 commit 623bcff
Show file tree
Hide file tree
Showing 13 changed files with 1,590 additions and 102 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/**.pdf
忽略/**
忽略/**
**/**.zip
**/target
31 changes: 25 additions & 6 deletions template.typ
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#let elasticity(P, Q) = $((diff #Q)/(diff #P))/(#Q / #P)$
#let autoVec3(a, delim: "(" ) = $vec(#a _1, #a _2, #a _3, delim: delim)$
#let autoVecN(a, n, delim: "(" ) = $vec(#a _1, #a _2, dots.v, #a _#n, delim: delim)$
#let autoVecNF(f, n, delim: "(" ) = $vec(#(f(1)), #(f(2)), dots.v, #(f(n)), delim: delim)$
#let autoRVecNF(f, n ) = $(#(f(1)), #(f(2)), dots, #(f(n)))$
#let autoMat3(delim: "(", ..var) = {
let varList = var.pos()
let row(n) = varList.map(v => $#v _#n$)
Expand All @@ -46,6 +48,15 @@
#let with = "with"
#let andC = $" 且 "$
#let orC = $" 或 "$
#let hb = $hat(bold(beta))$
#let sb = $bold(beta)^star$
#let bbeta = $bold(beta)$
#let balpha = $bold(alpha)$
#let bgamma = $bold(gamma)$
#let by = $bold(y)$
#let bx = $bold(x)$
#let bu = $bold(u)$
#let bv = $bold(v)$

#let inner(x, y) = $〈#x, #y〉$
#let HomoCoor = math.vec.with(delim: "[")
Expand Down Expand Up @@ -383,7 +394,9 @@
// box(scale(160%, origin: bottom + right, sym.square.stroked))
//})
#let note(title: "Note title", author: "Name", logo: none, date: none,
preface: none, code_with_line_number: true, withOutlined: true, withTitle: true, withHeadingNumbering: true, body) = {
preface: none, code_with_line_number: true, withOutlined: true, withTitle: true, withHeadingNumbering: true,
withChapterNewPage: false,
body) = {
// Set the document's basic properties.
set document(author: (author, ), title: title)
set page(
Expand Down Expand Up @@ -413,7 +426,6 @@
"(" + (counter(heading).get() + (num,)).map(str).join(".") + ")") if withHeadingNumbering == true
let headingfunc = (it => it)
if withHeadingNumbering == false {
set math.equation(numbering: "(1)")
}
else {
headingfunc = (it => {
Expand All @@ -436,7 +448,13 @@
// )
// Set paragraph spacing.
show par: set block(above: 1.2em, below: 1.2em)

let headingfunc1 = it => it
if withChapterNewPage == true{
headingfunc1 = it => {
pagebreak()
it
}
}
if withTitle{
// Title page.
// The page can contain a logo if you pass one with `logo: "logo.png"`.
Expand Down Expand Up @@ -475,18 +493,19 @@
} else {
outline(depth: 3, indent: true)
}

pagebreak()
if withChapterNewPage == false{
pagebreak() // 补上目录的换页
}
}
}
show heading.where(level: 1) : headingfunc1


// Main body
set par(justify: true, first-line-indent: 22pt)

set heading(numbering: "1.")
set heading(numbering: none) if withHeadingNumbering == false

// Code
show raw.where(block: false): box.with(
fill: luma(240),
Expand Down
302 changes: 211 additions & 91 deletions 数理逻辑/main.typ

Large diffs are not rendered by default.

64 changes: 63 additions & 1 deletion 机器学习数学导引/main.typ
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
date: datetime.today().display(),
logo: none,
)

= 前言
- 教师:吴磊(leiwu\@math.pku.edu.cn)
- 成绩:作业 40% + 大作业 60%(两到三人组)
Expand Down Expand Up @@ -38,6 +39,7 @@
通过训练集得到的近似函数在训练集之外往往一定程度上有效,这被称为泛化。泛化的成立根本上依赖于问题本身具有的某些良好性质,例如连续性,可微性等等。然而随着提供的训练数据在高维空间中迅速变得稀疏,这些简单直观的性质提供的泛化能力往往会在维度升高时迅速衰减,这被称为维度灾难(curse of dimensionality)。
= 传统机器学习
== 线性回归
#let hR = $hat(cal(R))$
使用线性函数:
$
f_i (x) = beta^T x + beta_0
Expand All @@ -46,7 +48,67 @@
$
f_i (x) = (beta^T, beta_0) vec(x, 1)
$
使用均方误差时,它有解析解。
定义均方误差:
$
hR_n (beta) = 1/n sum_(j=1)^n 1/2 (beta^T x_j - y_j)^2 = 1/(2 n) norm(vec(x_1^T, dots.v, x_n^T) beta - y)
$
#algorithm[OLS 普通最小二乘][
求解:
$
0 = nabla hR_n (beta)
$
得到:
$
1/n sum_(j=1)^n (beta^T x_j - y_j) x_j &= 0\
sum_(j=1)^n (beta^T x_j) x_j &= sum_(j=1)^n y_j x_j\
sum_(j=1)^n x_j (beta^T x_j) &= sum_(j=1)^n y_j x_j\
sum_(j=1)^n x_j x_j^T beta &= (x_1, ..., x_n) y\
(sum_(j=1)^n x_j x_j^T) beta &= (x_1, ..., x_n) y\
(x_1, ..., x_n) vec(x_1^T, dots.v, x_n^T) beta &= (x_1, ..., x_n) y\
$
$X = vec(x_1^T, dots.v, x_n^T)$,上式化为:
$
X^T X beta = X^T y
$
假设 $X$ 满秩,则上式有唯一解:
$
hat(beta) = (X^T X)^(-1) X^T y
$
否则,需要找到一个最优解。例如许多时候我们希望找到一个最小范数的解,这被称为 Ridge Regression,也就是求解以下问题:
$
min_(beta in RR^d) norm(beta) \
s.t. X beta = y
$
其中 $n < d, X in RR^(n times d) "满秩", y in RR^n$,此时可以解得解析解:
$
hb = X^T (X X^T)^(-1) by
$
#proof[
由条件,方程显然有解。设 $bbeta = X^T bu + bv$,代入方程有:
$
X (X^T bu + bv) &= by\
bu &= (X X^T)^(-1) (by - X bv)\
norm(bbeta)^2 &= (bu^T X + bv^T)(X^T bu + bv)\
&= bu^T X X^T bu + bu^T X bv + bv^T X^T bu + bv^T bv\
&= (by^T - bv^T X^T)(X X^T)^(-1)(by - X bv) + (by^T - bv^T X^T) (X X^T)^(-1) X bv + bv^T X^T (X X^T)^(-1) (by - X bv) + bv^T bv\
&= bv^T (I - X^T (X X^T)^(-1) X) bv + by^T (X X^T)^(-1) by
$
#lemmaLinear[][
$I - X^T (X X^T)^(-1) X$ 是半正定矩阵
]
#proof[
$P = X^T (X X^T)^(-1) X$,注意到:
- $P^2 = P$
- $P = P^T$
因此:
$
(I - P)^2 = I - 2P + P^2 = I - P\
x^T (I - P) x = x^T (I - P)^2 x = x^T (I -P)^T (I - P) x = norm((I- P) x) >= 0
$
]
由引理,显然上式取得最小值当且仅当 $bv = 0$,此时 $bbeta = x^T (X X^T)^(-1) by$
]
]
#example[][
通常情况下数据是有噪声的,这时需要采用正则化方法,例如:
- Ridge Regression:$min_(beta) sum_(i=1)^n (y_i - beta^T x_i)^2 + lambda norm(beta)_2^2$
Expand Down
Loading

0 comments on commit 623bcff

Please sign in to comment.