# Ch5 -- Neuron Network and Deep Learning
[TOC]
## Activation Function

input:神經元的結果,不同的function會決定如何處理這些結果
### Non-Linear Activation Function -- 非線性活化函數
多層神經網路必須用非線性活化函數,不然分類效果會很差
(linear activation function會解釋為什麼)
non-linear activation function包含以下幾種:
1. Binary step function
* 
2. Bipolar step function
* 
3. Binary Sigmoid: 0~1
* 
4. Bipolar Sigmoid: -1~1
* 
四個activation function比較:

* Binary step function: 黑色虛線,此處threshold設為0
* Bipolar step function: 紅色實線,此處threshold設為0
* Binary Sigmoid: 橘色實線,此處threshold設為2
* Bipolar Sigmoid: 藍色實線,此處threshold設為2
### Linear Activation Function -- 線性活化函數
f(x) = cx,此處的c為一個常數
若是多層神經網路使用linear activation function,則會得出此式:
f(f(f(x))) = $$c^3*x$$
=> 則效果與一層神經網路並無太大分別
此處介紹的linear activation function為ReLU


### Implement on Python
* Step Function-- 階梯活化函數

* 執行Sigmoid活化函數

* 執行ReLU活化函數

## 神經網路的乘積

## Perceptron -- 感知器

perceptron是最基本的neuron network(可以看為一個neuron)
通常perceptron可以接受多個信號,給出一個信號
perceptron計算出來的y~in~放入activation function變成簡單的信號y
一個的perceptron可以決定一條分割線
### single perception
AND gate:

OR gate:

### multiple perceptrons
#### two layers perceptrons
XOR gate:

在XOR gate當中,我們可以很明顯的看出無法用單一直線將A和B類別完全分開
因此我們可以列出兩條切割的直線方程式,如下

雖然看起來好像是切了兩條線,但如果提升到高維空間會發現是同一個平面,以下可以算是證明?

若我們將四個點帶入這兩個方程式,可以得出以下表格結果
| 類別 | 座標 | h1(x,y) | h2(x,y) |
| -------- | -------- | -------- | -------- |
| A | (0,1) | 0.5 | -0.5 |
| A | (1,0) | 0.5 | -0.5 |
| B | (0,0) | -0.5 | -1.5 |
| B | (1,1) | 1.5 | 0.5 |
且經由方程式,我們已知:
* h1將(0,0)class為B的點排除
* h2將(1,1)class為B的點排除
則使用activation中的binary step function可得出下表
| 類別 | 座標 | h1(x,y) | h2(x,y) |
| -------- | -------- | -------- | -------- |
| A | (0,1) | f(0.5) \= 1 | f(-0.5) \= 0 |
| A | (1,0) | f(0.5) \= 1 | f(-0.5) \= 0 |
| B | (0,0) | f(-0.5) \= 0 | f(-1.5) \= 0 |
| B | (1,1)| f(1.5) \= 1 | f(0.5) \= 1 |
將點標回座標上,便可用單一線劃分

---
而我們這邊標題是打2 layers,並不是因為我們要用2個perceptron!
如下圖:

* 第0層: input layer
* 第1層: perceptron layer (上述的兩個perceptron,都被放在了第一層)
* 第2層: output layer
這也是我們NN的最基礎的一個小模型
#### Implement Logic on Python
這裡用數位邏輯的方式來思考

##### Implement on Python


#### three layers perceptrons

能夠分類輸入向量,包含任何組合的多面體類別
=> 因為不管是哪種多面體,都是三維的
跟剛剛所提到在平面上的XOR有點類似,我們可以把多個平面在正方體H~p~上的頂點 (p為維度)
因此我們也可以將這P個神經元製作成超平面,讓每個神經元的輸出都是0,1(像是剛剛XOR一樣)
fully connection: 每個neuron都會連接到下一層的每個neuron
---
現在舉一個例子,我們把向量維度為3的資料輸入進三層感知器當中

從上圖可得知,我們需要三條直線(g~1~.g~2~.g~3~)才可以把AB兩個class完全的切割開來
以點(0,0,1)為例
g~1~(0,0,1) => -
#### Implement on Python
