手写多层感知机(简单BP网络)

研一时候没有选学校的模式识别课程,心里总感觉缺了点什么哈哈。
最近实验室师弟上这门课,老师布置了一个手写神经网络的作业,想想自己之前的实验都用的人家的框架,干脆这次自己也花点时间拿着个作业练练手。

我实现的就是一个非常简单的网络结构,网络层数可以随意加。
网络层类型:全连接
激活函数: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_
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值