import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
simple Fully Conected Layer
1、定义3D输出时的图形
def draw3D(X, Y, Z, angle=(45,-30)):
fig = plt.figure(figsize=(15,7))
ax = Axes3D(fig)
ax.view_init(angle[0], angle[1])
ax.plot_surface(X,Y,Z,rstride=1, cstride=1, cmap=’rainbow’)
plt.show()
2、定义一个操作网络结构的类
class FC:
def init(self, in_num, out_num, lr=0.01):
self._in_num = in_num
self._out_num = out_num
self.w = np.random.randn(out_num, in_num) * 10 #曲线挺陡
#self.w = np.ones((out_num, in_num))#相对平缓
# self.w=np.zeros((out_num,in_num))#是一个平面
self.b = np.zeros(out_num)
self.lr = lr
def _sigmoid(self, in_data):
return 1 / (1 + np.exp(-in_data))
#return in_data
def forward(self, in_data):
self.topVal = self._sigmoid(np.dot(self.w, in_data) + self.b)
self.bottomVal = in_data
return self.topVal