Couresra-吴恩达-深度学习-第一章:Neural Network and Deep Learning- 第四周

本周学习内容

  1. Key Concepts on Deep Neural Network
    • Deep L-layer neural network (深层神经网络)
    • Forward Propagation in a Deep Network (前向算法)
    • Getting your matrix dimensions right (核对矩阵的维数)
    • Why deep representations (为什么用深层表示)
    • Building blocks of deep neural networks (搭建深层神经网络)
    • Forward and Backward Propagation (前向和后向算法)
    • Parameters vs Hyperparameters (参数 vs 超参数)
    • What does this have to do with brain (这和大脑有什么关系)

测验

本周题目都比较简单,主要考察参数的维度:
W [ l ] : ( n [ l ] , n [ l − 1 ] ) W^{[l]} : (n^{[l]},n^{[l-1]}) W[l]:(n[l],n[l1])
b [ l ] : ( n [ l ] , 1 ) b^{[l]} : (n^{[l]},1) b[l]:(n[l],1)

代码练习

任务1:Building your Deep Neural Network: Step by Step

目标

  1. Develop an intuition of the over all structure of a neural network.
  2. Write functions (e.g. forward propagation, backward propagation, logistic loss, etc…) that would help you decompose your code and ease the process of building a neural network.
  3. Initialize/update parameters according to your desired structure.

大纲(Outline of the Assignment)

我们将构建两个神经网络,一个是两层的,一个是多层的。必须的步骤有:

  • 初始化参数
  • 前向传播(图中紫色部分)
    • LINEAR part - 生成 Z [ l [ Z^{[l[} Z[l[ Z = np.dot(W,A) + b
    • LINEAR > ACTIVATION forward function
      • LINEAR > ReLU (L-1层) A = relu(Z)
      • LINEAR > Sigmoid(最后一层L) A = sigmoid(Z)
  • 计算损失函数
  • 反向传播 (图中红色部分)
    • 线性部分的反向传播
    • 激活函数部分的反向传播
    • 结合线性部分与激活函数的反向传播公式
  • 更新参数
  • 在这里插入图片描述

1. 初始化参数(Initialization)

两层的:

def initialize_parameters(n_x,n_h,n_y):
    """
    此函数是为了初始化两层网络参数而使用的函数。
    参数:
        n_x - 输入层节点数量
        n_h - 隐藏层节点数量
        n_y - 输出层节点数量
    
    返回:
        parameters - 包含你的参数的python字典:
            W1 - 权重矩阵,维度为(n_h,n_x)
            b1 - 偏向量,维度为(n_h,1)
            W2 - 权重矩阵,维度为(n_y,n_h)
            b2 - 偏向量,维度为(n_y,1)

    """
    W1 = np.random.randn(n_h, n_x) * 0.01
    b1 = np.zeros((n_h, 1))
    W2 = np.random.randn(n_y, n_h) * 0.01
    b2 = np.zeros((n_y, 1))
    
    #使用断言确保我的数据格式是正确的
    assert(W1.shape == (n_h, n_x))
    assert(b1.shape == (n_h, 1))
    assert(W2.shape == (n_y, n_h))
    assert(b2.shape == (n_y, 1))
    
    parameters = {
   "W1": W1,
                  "b1": b1,
                  "W2": W2,
                  "b2": b2}
    
    return parameters  

L层的参数初始化稍复杂,另外涉及到一点broadcasting,但只要记住 w , b w,b w,b的维度即可
在这里插入图片描述

def initialize_parameters_deep(layers_dims):
    """
    此函数是为了初始化多层网络参数而使用的函数。
    参数:
        layers_dims - 包含我们网络中每个图层的节点数量的列表
    
    返回:
        parameters - 包含参数“W1”,“b1”,...,“WL”,“bL”的字典:
                     W1 - 权重矩阵,维度为(layers_dims [1],layers_dims [1-1])
                     bl - 偏向量,维度为(layers_dims [1],1)
    """
    np.<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值