博客
关于我
Numpy编写BP传播过程全解
阅读量:185 次
发布时间:2019-02-28

本文共 1822 字,大约阅读时间需要 6 分钟。

BP???Numpy??????

??

BP??????????????????????????????????????????????????????????????????????????BP?????????????????????????

?????BP????????????????????????????????????PyTorch?TensorFlow??????????????????????????????????????????????????????????????Numpy????BP?????????????????

???????????Numpy???BP????????????????????????????????????????????

????

????4?????????????????784??????128????1??64????2??10??????????????784?128?128?64?64?10?10?1???????????????

?????

  • ????784????
  • ???1?128????
  • ???2?64????
  • ????10????

?????

  • W1?784?128?
  • W2?128?64?
  • W3?64?10?
  • W4?10?1?

???????Sigmoid???????????

Sigmoid(x) = 1/(1 + e^(-x))

Sigmoid'(x) = Sigmoid(x) * (1 - Sigmoid(x))

????

???????????

  • data ??????MNIST??????????mnist.pkl.gz
  • mnist_loader.py?????MNIST???
  • BP_Numpy.py?BP????????????
  • 1. ?????

    ??????????

    def initialize_weights(shape):    np.random.seed(42)    return np.random.randn(*shape)

    ??????????????????????????????????

    2. ????

    ?????????

    def forward_propagation(inputs, weights, biases):    activation = sigmoid(np.dot(inputs, weights) + biases)    return activation, weights, biases

    ????????????????????

    3. ????

    ?????????

    def backward_propagation(outputs, targets, weights, biases):    loss = np.mean(np.sum((outputs - targets) ** 2))    delta = (outputs - targets) * sigmoid_derivative(outputs - targets)    gradients = np.dot(weights.T, delta) + biases.T    return loss, gradients

    ????????????

    4. ????

    ?????????

    def update_parameters(weights, biases, gradients, learning_rate):    weights -= gradients[0] * learning_rate    biases -= gradients[1] * learning_rate    return weights, biases

    ??????????????

    ????

    ??????????????

    • ????0.1
    • epoch??1000
    • ?????10

    ???????????????????????????????????????

    ??

    ??????????????????BP???????????????????????????????????????????Numpy????????????????

    ????BP????????????????PaperWeekly??????????????????

    转载地址:http://teoj.baihongyu.com/

    你可能感兴趣的文章
    Netty工作笔记0014---Buffer类型化和只读
    查看>>
    Netty工作笔记0020---Selectionkey在NIO体系
    查看>>
    Vue踩坑笔记 - 关于vue静态资源引入的问题
    查看>>
    Netty工作笔记0025---SocketChannel API
    查看>>
    Netty工作笔记0027---NIO 网络编程应用--群聊系统2--服务器编写2
    查看>>
    Netty工作笔记0050---Netty核心模块1
    查看>>
    Netty工作笔记0084---通过自定义协议解决粘包拆包问题2
    查看>>
    Netty常见组件二
    查看>>
    netty底层源码探究:启动流程;EventLoop中的selector、线程、任务队列;监听处理accept、read事件流程;
    查看>>
    Netty核心模块组件
    查看>>
    Netty框架的服务端开发中创建EventLoopGroup对象时线程数量源码解析
    查看>>
    Netty源码—2.Reactor线程模型一
    查看>>
    Netty源码—4.客户端接入流程一
    查看>>
    Netty源码—4.客户端接入流程二
    查看>>
    Netty源码—5.Pipeline和Handler一
    查看>>
    Netty源码—6.ByteBuf原理二
    查看>>
    Netty源码—7.ByteBuf原理三
    查看>>
    Netty源码—7.ByteBuf原理四
    查看>>
    Netty源码—8.编解码原理二
    查看>>
    Netty源码解读
    查看>>