研一时候没有选学校的模式识别课程,心里总感觉缺了点什么哈哈。
最近实验室师弟上这门课,老师布置了一个手写神经网络的作业,想想自己之前的实验都用的人家的框架,干脆这次自己也花点时间拿着个作业练练手。
我实现的就是一个非常简单的网络结构,网络层数可以随意加。
网络层类型:全连接
激活函数:Sigmoid
训练损失函数:欧氏距离
主要实现功能:1.前向传播(Test);2.训练过程(Training)
import numpy as np
def sigmoid(x):
# return x
return 1.0 / (1.0 + np.exp(-x))
def sigmoid_dev(x):
# return 1
return x*(1-x)
class fc_layer:
def __init__(self,name,shape,mean_,variance_):
# args: name: String. The name of this layer.
# shape: List or Numpy array. The shape of this full-connected layers
# like [3,10]
# mean_: Using normal distribution to initialize the network,
# mean_ is the mean for normal distribution.
# variance_: Using normal distribution to initialize the network,
# variance_ is the variance for normal distribution.
self.name=name # String, the name of this layer
self.shape=shape # Matrix(numpy array), represent the shape of this layer
self.output=None # Vector(numpy array), the output of this layer
self.weight=np.random.normal(mean_,variance_