zoukankan      html  css  js  c++  java
  • 单输出感知机及其梯度

    recap

    • (y = XW + b)

    • (y = sum{x_i}*w_i + b)

    Perceptron

    22-单输出感知机及其梯度-感知机模型.jpg

    • (x_i^0) i表示当成第i个节点
    • (w_{ij}^0) 表示当层的第i个节点,j表示下一个隐藏层的第j个节点
    • (sigma) 表示激活函数后的节点
    • E表示error值
    • t表示target值

    Derivative

    • (E=frac{1}{2}(O_0^1-t)^2)
    import tensorflow as tf
    
    x = tf.random.normal([1, 3])
    w = tf.ones([3, 1])
    b = tf.ones([1])
    y = tf.constant([1])
    
    with tf.GradientTape() as tape:
        tape.watch([w, b])
        prob = tf.sigmoid(x @ w + b)
        loss = tf.reduce_mean(tf.losses.MSE(y, prob))
    
    grads = tape.gradient(loss, [w, b])
    
    [<tf.Tensor: id=203, shape=(3, 1), dtype=float32, numpy=
     array([[-0.00047306],
            [-0.00288958],
            [-0.00280226]], dtype=float32)>,
     <tf.Tensor: id=201, shape=(1,), dtype=float32, numpy=array([-0.00275796], dtype=float32)>]
    
    grads[0]
    
    <tf.Tensor: id=203, shape=(3, 1), dtype=float32, numpy=
    array([[-0.00047306],
           [-0.00288958],
           [-0.00280226]], dtype=float32)>
    
    grads[1]
    
    <tf.Tensor: id=201, shape=(1,), dtype=float32, numpy=array([-0.00275796], dtype=float32)>
  • 相关阅读:
    P1005 矩阵取数
    [BZOJ2662][BeiJing wc2012]冻结
    [BZOJ1191]超级英雄Hero
    [bzoj1008] 越狱
    [bzoj1001]狼抓兔子 最小割
    网络流24题——负载平衡问题
    分形小山
    可并堆——左偏树、斜堆
    NOIP最优贸易
    洛谷P2073送花
  • 原文地址:https://www.cnblogs.com/nickchen121/p/10908602.html
Copyright © 2011-2022 走看看