### 特殊的網(wǎng)絡(luò)結(jié)構(gòu)
**卷積神經(jīng)網(wǎng)絡(luò)**
卷積神經(jīng)網(wǎng)絡(luò)是如何計算的非常簡單。但還是先簡單說說數(shù)學(xué)中的卷積是怎么回事(詳細可以參考[wiki](https://en.wikipedia.org/wiki/Convolution)),再回過頭來則能更好理解卷積神經(jīng)網(wǎng)絡(luò)。
卷積在數(shù)學(xué)中大概是說,兩個函數(shù)通過做卷積,可以生成一個新的函數(shù)。我用兩個最簡單的函數(shù)畫圖示范一下
$$函數(shù)1:f(x)=\begin{cases}
x & \text{ if } x \geq? 0\\
0 & \text{ if } x < 0
\end{cases}$$
$$函數(shù)2:g(x)=\begin{cases}
1 & \text{ if } 0 \leq x \leq? 1\\
0 & \text{ if } x= others
\end{cases}$$
把他們畫下來就是:
```python
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x1 = np.linspace(0, 3, 30)
y1 = x1
x2 = np.linspace(0, 1, 2)
y2 = np.ones_like(x2)
plt.plot(x1, y1, label="f(x)")
plt.plot(x2, y2, label="g(x)")
plt.plot(-x2, y2, label="g(-x)")
plt.legend()
plt.show()
```

對f(x),g(x)做卷積,公式為:
$$(f*g)(t) = \int_{-\infty }^{+\infty }f(x)g(t-x)dx$$
現(xiàn)在來解釋這個式子對于上邊的f(x)和g(x)來說,到底做了什么操作?
現(xiàn)在設(shè)想我們要求$(f*g)(t=0)$的值,那么卷積:
$$(f*g)(t=0) = \int_{-\infty }^{+\infty }f(x)g(-x)dx$$
從上邊圖可以看出f(x)g(-x)乘積為0,因此積分也為0。
再假設(shè)我們要求t=0.5時卷積的值,那么卷積:
$$(f*g)(t=0.5) = \int_{-\infty }^{+\infty }f(x)g(0.5-x)dx$$
把f(x)和g(0.5-x)在圖上畫出來:
```python
x1 = np.linspace(0, 3, 30)
y1 = x1
x2 = np.linspace(-0.5, 0.5, 2)
y2 = np.ones_like(x2)
plt.plot(x1, y1, label="f(x)")
plt.plot(x2, y2, label="g(0.5-x)")
plt.legend()
plt.show()
```

因此f(x)和g(0.5-x)的相乘之后的積分,就是f(x)在0