W!o+ 的《小伶鼬工坊演義》︰神經網絡【Sigmoid】二

雖然 Michael Nielsen 先生嘗試藉著最少的數學來談『 S 神經元』︰

What about the algebraic form of \sigma? How can we understand that? In fact, the exact form of \sigma isn’t so important – what really matters is the shape of the function when plotted. Here’s the shape:

Logistic-curve.svg

This shape is a smoothed out version of a step function:

Dirac_distribution_CDF.svg

If \sigma had in fact been a step function, then the sigmoid neuron would be a perceptron, since the output would be 1 or 0 depending on whether w \cdot x+b was positive or negative*

*Actually, when w \cdot x+b = 0 the perceptron outputs 0, while the step function outputs 1. So, strictly speaking, we’d need to modify the step function at that one point. But you get the idea.

. By using the actual \sigma function we get, as already implied above, a smoothed out perceptron. Indeed, it’s the smoothness of the \sigma function that is the crucial fact, not its detailed form. The smoothness of \sigma means that small changes \Delta w_j in the weights and \Delta b in the bias will produce a small change \Delta output in the output from the neuron. In fact, calculus tells us that \Delta output is well approximated by

\Delta \mbox{output} \approx \sum_j \frac{\partial \, \mbox{output}}{\partial w_j} \Delta w_j + \frac{\partial \, \mbox{output}}{\partial b} \Delta b, \ \ \ \ \ (5)

where the sum is over all the weights, w_j , and \partial \, \mbox{output} / \partial w_j  and \partial \, \mbox{output} /\partial b denote partial derivatives of the output with respect to w_j and b, respectively. Don’t panic if you’re not comfortable with partial derivatives! While the expression above looks complicated, with all the partial derivatives, it’s actually saying something very simple (and which is very good news): \Delta output is a linear function of the changes \Delta w_j and \Delta b in the weights and bias. This linearity makes it easy to choose small changes in the weights and biases to achieve any desired small change in the output. So while sigmoid neurons have much of the same qualitative behaviour as perceptrons, they make it much easier to figure out how changing the weights and biases will change the output.

───

 

假使能夠深入了解背後的數學,或許會更容易掌握的吧!何不開卷閱讀『無窮小』系列文本,從直覺觀點學習微積分的呢!!

在《吃一節 TCPIP!!中》一文中我們談到了『拓撲學』 Topology 一詞源自希臘文『地點之研究』,始於歐拉柯尼斯堡的七橋問題。這門數學探討『連通性』 connectedness 、『連續性』 continuity 、以及『邊界』 boundary。它不用東西的『形狀』來作分類,而是分析在那個東西裡所有連通的點,各個連續的區域,和有哪些分別內外的邊界。假使從『拓撲學』的觀點來談『函數』的『連續性』,那麼 |f(x) - f(x_0)| < \varepsilon 就是 f(x_0) 的『鄰域』 neighborhood,而 |x-x_0| < \delta 也就是 x_0 的『鄰域』 。所以函數上『一點』的連續性是說『這個點』的所有『指定鄰域』,都有一個『實數區間』── 鄰域的另一種說法 ── 與之『對應』,『此函數』將『此區間』映射到那個『指定鄰域』裡。

然而一個函數在『某個點』的『連續性』,並不能夠『確保』在『那個點』的『斜率存在』 ── 或說『可微分性』,比方說

f(x) = \begin{cases}x & \mbox{if }x \ge 0, \\ 0 &\mbox{if }x < 0\end{cases}

,當 x > 0 時,『斜率』是 f^{'}(x) = \frac{df(x)}{dx} = 1,在 x < 0 時,『斜率』為 0,然而 x = 0 時『斜率』不存在!這使得我們必須研究一個函數在『每個點』之『鄰域』情況,於是數學步入了『解析的』 Analytic 時代。所謂『解析的』一詞是指『這類函數』在 x = x_0 的『鄰域』,可以用『泰勒級數』來作展開

T(x) = \sum \limits_{n=0}^{\infty} \frac{f^{(n)}(x_0)}{n!} (x-x_0)^{n}

。於是一個『解析函數』在定義域的『每一點』上都是『無窮階可導』的。人們將『無窮階可導』的函數,又稱之為『光滑函數』 smooth function。然而『可導性』卻不同於『連續性』,因此又定義了『連續可導性』︰假使一個函數從『一階到 N 階』的導數都『存在』而且『連續』,我們稱之為 C^{N} 類函數。舉例來說

f(x) = \begin{cases}x^2\sin{(\tfrac{1}{x})} & \mbox{if }x \neq 0, \\ 0 &\mbox{if }x = 0\end{cases}

雖然『一階導數』存在但是在 x = 0 時,並不『連續』,所以它只能屬於 C^{0} 類,而不是屬於 C^{1} 類。

雖然一個『光滑函數』就屬於 C^{\infty} 類,但是它可以不是『解析函數』,比方說

f(x) = \begin{cases}e^{-\frac{1}{1-x^2}} & \mbox{ if } |x| < 1, \\ 0 &\mbox{ otherwise }\end{cases}

是『光滑的』,然而在 x = \pm 1 時無法用『泰勒級數』來作展開,因此不是『解析的』。

縱使人們覺得『連續』與『鄰近』以及『導數』和『光滑』彼此之間有聯繫,由於失去『直觀』的導引,『概念』卻又越來越『複雜』,因此『微積分』也就遠離了一般人的『理解』,彷彿鎖在『解析』與『極限』的『巴別塔』中!更不要說還有一些『很有用』卻是『很奇怪』的函數。舉例來說,『單位階躍』函數,又稱作『黑維塞階躍函數』 Heaviside step function ,可以定義如下

H(x) = \begin{cases} 0, & x < 0 \\ \frac{1}{2}, & x = 0 \\ 1, & x > 0 \end{cases}

,在 x = 0 時是『不連續』的,它可以『解析』為

H(x)=\lim \limits_{k \rightarrow \infty}\frac{1}{2}(1+\tanh kx)=\lim \limits_{k \rightarrow \infty}\frac{1}{1+\mathrm{e}^{-2kx}}

,它的『微分』是 \frac{dH(x)}{dx} = \delta(x),而且這個『狄拉克 \delta(x) 函數』 Dirac Delta function 是這樣定義的

\delta(x) = \begin{cases} +\infty, & x = 0 \\ 0, & x \ne 0 \end{cases}

,滿足

\int_{-\infty}^\infty \delta(x) \, dx = 1

。怕是想『解析』一下都令人頭大,『極限』和『微分』與『積分』能不能『交換次序』,它必須滿足『什麼條件』,假使再加上『無限級數』求和,

\operatorname{III}_T(t) \ \stackrel{\mathrm{def}}{=}\ \sum_{k=-\infty}^{\infty} \delta(t - k T) = \frac{1}{T}\operatorname{III}\left(\frac{t}{T}\right)

,果真是我的天啊的吧!!

Mug_and_Torus_morph

240px-Möbius_strip

220px-Trefoil_knot_arb

250px-Bump2D_illustration

220px-C0_function.svg

f(x) = \begin{cases}x & \mbox{if }x \ge 0, \\ 0 &\mbox{if }x < 0\end{cases}

Rational_sequence_with_2_accumulation_points_svg.svg

220px-Diagonal_argument.svg

220px-X^2sin(x^-1).svg

f(x) = \begin{cases}x^2\sin{(\tfrac{1}{x})} & \mbox{if }x \neq 0, \\ 0 &\mbox{if }x = 0\end{cases}

f'(x) = \begin{cases}-\mathord{\cos(\tfrac{1}{x})} + 2x\sin(\tfrac{1}{x}) & \mbox{if }x \neq 0, \\ 0 &\mbox{if }x = 0.\end{cases}

Mollifier_Illustration.svg

f(x) = \begin{cases}e^{-\frac{1}{1-x^2}} & \mbox{ if } |x| < 1, \\ 0 &\mbox{ otherwise }\end{cases}

Non-analytic_smooth_function

f(x) := \begin{cases}e^{-\frac{1}{x}} & x > 0, \\ 0 & x \leq 0 \end{cases}

250px-StepFunctionExample

Dirac_distribution_CDF.svg

H(x) = \begin{cases} 0, & x < 0 \\ \frac{1}{2}, & x = 0 \\ 1, & x > 0 \end{cases}

325px-Dirac_distribution_PDF.svg
狄拉克 δ 函數
單位脈衝函數

Dirac_function_approximation
\delta_{a}(x) = \frac{1}{a \sqrt{\pi}} e^{- x^2 / a^2}
a \rightarrow 0

220px-Dirac_comb.svg

一九六零年,德國數學家『亞伯拉罕‧魯濱遜』 Abraham Robinson 將『萊布尼茲』的微分直觀落實。 用嚴謹的方法來定義和運算實數的『無窮小』與『無限大』,這就是數學史上著名的『非標準微積分』Non-standard calculus ,可說是『非標準分析』non-standard analysis 之父。

就像『複數C 是『實數系R 的『擴張』一樣,他將『實數系』增入了『無窮小』 infinitesimals 元素 \delta x ,魯濱遜創造出『超實數』 hyperreals r^{*} = r + \delta x,形成了『超實數系R^{*}。那這個『無窮小』是什麼樣的『』呢?對於『正無窮小』來說,任何給定的『正數』都比要它大,就『負無窮小』來講,它大於任何給定的『負數』。 『』也就自然的被看成『實數系』裡的『無窮小』的了。假使我們說兩個超實數 a, b, \ a \neq b 是『無限的鄰近』 indefinitly close,記作 a \approx b 是指 b -a \approx 0 是個『無窮小』量。在這個觀點下,『無窮小』量不滿足『實數』的『阿基米德性質』。也就是說,對於任意給定的 m 來講, m \cdot \delta x 為『無窮小』量;而 \frac{1}{\delta x} 是『無限大』量。然而在『系統』與『自然』的『擴張』下,『超實數』的『算術』符合所有一般『代數法則』。

hyperreals

Standard_part_function_with_two_continua.svg

220px-Sentido_geometrico_del_diferencial_de_una_funcion

速度里程表

有人把『超實數』想像成『數原子』,一個環繞著『無窮小』數的『實數』。就像『複數』有『實部R_e 與『虛部I_m 取值『運算』一樣,『超實數』也有一個取值『運算』叫做『標準部份函數』Standard part function

st(r^{*}) = st(r + \delta x)
= st(r) + st(\delta x) = r + 0 = r

。 如此一個『函數f(x)x_0 是『連續的』就可以表示成『如果 x \approx x_0, \ x \neq x_0,可以得到 f(x) \approx f(x_0)』。

假使 y = x^2,那麼 y 的『斜率』就可以這麼計算

\frac{dy}{dx} = st \left[ \frac{\Delta y}{\Delta x} \right] = st \left[ \frac{(x + \Delta x)^2 - x^2}{\Delta x} \right]
= st \left[2 x + \Delta x \right] = 2 x

。 彷彿在用著可以調整『放大倍率』的『顯微鏡』逐步『觀入』 zoom in 一個『函數』,隨著『解析度』的提高,函數之『曲率』逐漸減小,越來越『逼近』一條『直線』── 某點的切線 ── 的啊!!

同樣的『積分』就像是『里程表』的『累計』一樣,可以用

\forall 0 < \delta x \approx 0, \ \int_{a}^{b} dx \approx f(a)\delta x + f(a + \delta x)\delta x + \cdots + f(b - \delta x)\delta x

來表示的呀!!

─── 摘自《【Sonic π】電路學之補充《四》無窮小算術‧中

 

如是 S 神經元或可這樣理解

\Delta \sigma(z) = \frac{\Delta \sigma(z)}{\Delta z} \cdot \Delta z \approx \sigma(z)(1 - \sigma (z) ) \cdot \Delta z

由於 z(w, b) = w \cdot x + b ,因此

\Delta z = \Delta w \cdot x + \Delta b

所以可得到

\Delta \sigma(z) \approx \sigma(z)(1 - \sigma (z) ) \cdot ( \Delta w \cdot x + \Delta b)

= \sigma(z)(1 - \sigma (z) ) \cdot x \cdot \Delta w + \sigma(z)(1 - \sigma (z) ) \cdot \Delta b

的耶!!!