owned this note
owned this note
Published
Linked with GitHub
# SOC Calculus
## Homework 3
1. Consider the following functions:
$$
f(x) = \mathbf{x}\mathbf{x}^T, \quad \mathbf{x}\in\mathbb{R}^2
$$
a. What are the dimensions of $\frac{\partial f}{\partial \mathbf{x}}$
b. Compute the Jacobians.
:::info
* 和作業二類似,這裡的dimensions建議用matrix of dimension $m\times n$的方式表示,比方說
$[x_1,x_2,x_3]$ 是matrix of dimension $1\times 3$
* dimension 還有 Jacobians (gradient)的決定方式參考(5.40)、(5.56)、(5.57),依照$f$還有$x$是向量還是純量決定如何套用公式。
:::
2. Differentiate ${g}$ with respect to $\mathbf{X}$, where
$${g}(\mathbf{X}) = tr(\mathbf{A}\mathbf{X}\mathbf{B}), \quad \mathbf{A} \in \mathbb{R}^{3\times 2}, \mathbf{X} \in \mathbb{R}^{2\times 2}, \mathbf{B} \in \mathbb{R}^{2\times 3},$$
where $tr(\cdot)$ denotes the trace.
:::info
* $\mathbf{A}$和 $\mathbf{B}$是常數矩陣,可以假設矩陣的elements是$a_{ij}$和$b_{ij}$
:::
3. Compute the Taylor polynomials $T_n$, $n = 0, 1, 2$ of $f(\mathbf{x}) = \exp{(\mathbf{x}^T\mathbf{x})}$ at $\mathbf{x}_0=[0,0]^T$.
:::info
* Taylor polynomials 參考(5.152),其中的$D^k_x f(x_0)\delta^k$參考(5.156)-(5.158)
* 可以參考Example 5.15,由於這題只需要計算$T_0$,$T_1$和$T_2$,所以不需要計算$D^3_x f(x_0)\delta^3$ (5.174-5.179),比較簡單。
* 可以使用matlab的symbolic toolbox計算taylor series和你的答案比較(參考底下的詳細資料)
:::
:::spoiler
* matlab code 求$e^x$ 的Taylor polynomial of degree 2 at $x_0=1$:
```
syms x;
taylor(exp(x),x,1,'Order',3)
```
* matlab code 求$\sin(x^2+y^2)$ 的Taylor polynomial of degree 3 at $\mathbf{x}_0=[0,0]^T$:
```
syms x y;
taylor(sin(x^2+y^2),[x y], [0 0],'Order',4)
```
* 注意上面code中的'Order'後的數字是多項式degree+1
:::
4. Use the Taylor polynomials $T_n$, $n = 0, 1, 2$ of $f(\mathbf{x}) = \exp{(\mathbf{x}^T\mathbf{x})}$ at $\mathbf{x}_0=[0,0]^T$ to approximate $f([0.1,0.1]^T)$.
## Homework 2
:::info
第四題$\mathbf{f}(\mathbf{z}) = \sin{(\mathbf{z})}$是向量函數,所以第四題併到Homework 3繳交
:::
1. Consider the following functions:
$$
f(x) = \sin{(x_1)} \cos{(x_2)}, \quad \mathbf{x}\in\mathbb{R}^2
$$
a. What are the dimensions of $\frac{\partial f}{\partial \mathbf{x}}$
b. Compute the Jacobians.
:::info
* 這裡的dimensions建議用matrix of dimension $m\times n$的方式表示,比方說
$[x_1,x_2,x_3]$ 是matrix of dimension $1\times 3$
* dimension 還有 Jacobians (gradient)的決定方式參考(5.40)、(5.56),依照$f$還有$x$是向量還是純量決定如何套用公式。
:::
2. Differentiate $f$ with respect to $\mathbf{t}$, where
$$f(t) = \sin{(\ln{(\mathbf{t}^T\mathbf{t})})}, \quad \mathbf{t} \in \mathbb{R}^2$$
3. Compute the derivatives $df/dx$ of the function by using the chain rule. Provide the dimensions of every single partial derivative. Describe your steps in detail.
$$
{f}({z}) = \ln(1 + z), \quad z = x^T x,\quad x\in \mathbb{R}^2.
$$
3. Compute the derivatives $df/dx$ of the function by using the chain rule. Provide the dimensions of every single partial derivative. Describe your steps in detail.
$$
\mathbf{f}(\mathbf{z}) = \sin{(\mathbf{z})}, \quad \mathbf{z} = \mathbf{A}\mathbf{x}+\mathbf{b},\quad \mathbf{A}\in \mathbb{R}^{2\times 2}, ,\quad \mathbf{x},\mathbf{b}\in \mathbb{R}^2.
$$
:::info
第四題的$\mathbf{f}(\mathbf{z}) = \sin{(\mathbf{z})}$是一個向量函數,對$\mathbf{z}$的每個分量取值:
$$
\mathbf{f}(
\begin{pmatrix}
z_{1}\\
z_{2}
\end{pmatrix}
)=
\begin{pmatrix}
\sin(z_{1})\\
\sin(z_{2})
\end{pmatrix}
$$
:::
## Homework 1
1. Compute the derivative $f'(x)$ for
$$f(x) = \ln{(x^4)}\sin{(x^3)}.$$
2. Compute the derivative $f'(x)$ of the logistic sigmoid
$$
f(x) = \frac{1}{1 + e^{-x}}
$$
3. Compute the derivative $f'(x)$ of the function
$$f(x) = \exp{(-\frac{1}{2\sigma^2}(x-\mu)^2)},
$$
where $\mu$,$\sigma \in \mathbb{R}$ are constants.
4. Compute the Taylor polynomials $T_n$, $n = 0, \dots, 5$ of $f(x) = \sin{(x)} + \cos{(x)}$ at $x_0=0$.
5. Use the Taylor polynomials $T_n$, $n = 0, \dots, 5$ of $f(x) = \sin{(x)} + \cos{(x)}$ to estimate $\sin{(0.1)} + \cos{(0.1)}$.
## Scratch
1.
a. (1 %) 自己選擇一個非多項式的單變量函數$f(x)$,並且找出它的$df/dx$。
b. (1 %) 透過計算機或相關軟體,找一個非零的數字$a$,及一個相對$a$小很多的數字$\Delta a$,計算$\Delta f=f(a+\Delta a)−f(a)$
c. (1 %) 計算$f′(a) \cdot \Delta a$,並比較與Δf差距,是否遠比$\Delta a$來得小?
1.
a. (1 %) 自己選擇一個非多項式的多變量函數${f}(\mathbf{x})$,並且找出它的$\frac{\partial {f}}{\partial \mathbf{x}}$。
b. (1 %) 透過計算機或相關軟體,找一個非零向量$\mathbf{u}$,及一個相對$\mathbf{u}$長度小很多的非零向量$\Delta\mathbf{u}$,計算$\Delta {f}={f}(\mathbf{u}+\Delta\mathbf{u})−{f}(\mathbf{u})$
c. (1 %) 計算$\frac{\partial \mathbf{f}}{\partial \mathbf{x}}\cdot \Delta \mathbf{u}$。並比較與$\Delta \mathbf{f}$之間的差距,是否遠比$||\Delta \mathbf{u}||$來得小?
1.
a. (1 %) 自己找一個之前曾經學習過,且具有三個變量以上的等式。請先移項至等號右邊為零,等號左邊令為$f(\mathbf{x})$。自己推導這個等式f(x)=0中,其變數及該變數的變化量之間應該滿足何種關係式。
b. (1 %) 請在這個等式中,找到一組滿足該等式的數字組u,也就是f(u)=0。然後改變其中幾個變數一點點,用計算機或相關軟體,找到這樣子的改變之下,滿足它的第二組數字f(v)=0。從這兩組數字中,找到其他變數的變化量v−u。
c. (1 %) 計算$\frac{\partial \mathbf{f}}{\partial \mathbf{x}}(\mathbf{u})\cdot (\mathbf{v}-\mathbf{u})$,是否遠比$||\mathbf{v}-\mathbf{u}||$來得小?
d. (1 %) 計算$\frac{\partial \mathbf{f}}{\partial \mathbf{x}}(\mathbf{v})\cdot (\mathbf{v}-\mathbf{u})$,是否遠比$||\mathbf{v}-\mathbf{u}||$來得小?跟上面( c )中的數字有差別嗎?
1.
a. (1 %) 自己找三個之前曾經學習過,且具有共同兩個變量的函數組合成一個3×1的向量$\mathbf{f}(\mathbf{x})$。請從這三個函數,計算$\frac{\partial \mathbf{f}}{\partial \mathbf{x}}$
b. (1 %) 找到一組數字組$\mathbf{u}$,及一個相對$\mathbf{u}$長度小很多的非零向量$\Delta \mathbf{u}$。用計算機或相關軟體,計算$\Delta \mathbf{f}=\mathbf{f}(\mathbf{u}+\Delta\mathbf{u})-\mathbf{f}(\mathbf{u})=$。
c. (1 %) 計算$\frac{\partial \mathbf{f}}{\partial \mathbf{x}}(\mathbf{u})\cdot \Delta \mathbf{u}$。並比較與$\Delta\mathbf{f}$向量之間的差距,是否遠比$||\Delta\mathbf{u}||$來得小?
1. (2 %) 請整理上述這四題的共同點與不同點。