Class1-Week3-Neural Networks Overview

如何实现高校科技成果转化的高效对接?.docx 科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。 立即下载

Neural Network Representation

Like logistic regression architecture, you can from a Neural Network just by stacking a lot of little sigmoid units. As shown in the figure below:

在这里插入图片描述

Compute a Neural Network’s Output

Firstly, We set:

W [ 1 ] = [ ⋯ w 1 [ 1 ] ⋯ ⋯ w 2 [ 1 ] ⋯ ⋯ w 3 [ 1 ] ⋯ ] W^{[1]}= \begin{bmatrix} \cdots & w_{1}^{[1]} & \cdots \\ \cdots & w_{2}^{[1]} & \cdots \\ \cdots & w_{3}^{[1]} & \cdots \\ \end{bmatrix} W[1]=w1[1]w2[1]w3[1]

b [ 1 ] = [ ⋯ b 1 [ 1 ] ⋯ ⋯ b 2 [ 1 ] ⋯ ⋯ b 3 [ 1 ] ⋯ ] b^{[1]} = \begin{bmatrix} \cdots & b_{1}^{[1]} & \cdots \\ \cdots & b_{2}^{[1]} & \cdots \\ \cdots & b_{3}^{[1]} & \cdots \\ \end{bmatrix} b[1]=b1[1]b2[1]b3[1]

X = A [ 0 ] = [ ⋮ ⋮ ⋮ a [ 0 ] ( 1 ) a [ 0 ] ( 2 ) a [ 0 ] ( 3 ) ⋮ ⋮ ⋮ ] X = A^{[0]} = \begin{bmatrix} \vdots & \vdots & \vdots \\ a^{[0](1)} & a^{[0](2)} & a^{[0](3)} \\ \vdots & \vdots & \vdots \end{bmatrix} X=A[0]=a[0](1)a[0](2)a[0](3)

  • The horizontally the matrix A/Z goes over different training examples
  • The vertically the different indices in the maxtrix A/Z goes over differect hidden units of one layer

Z [ 1 ] = W [ 1 ] X + b [ 1 ] Z^{[1]} = W^{[1]}X + b^{[1]} Z[1]=W[1]X+b[1]

A [ 1 ] = g [ 1 ] ( Z [ 1 ] ) A^{[1]} = g^{[1]}(Z^{[1]}) A[1]=g[1](Z[1])

Z [ 2 ] = W [ 2 ] A [ 1 ] + b [ 2 ] Z^{[2]} = W^{[2]}A^{[1]} + b^{[2]} Z[2]=W[2]A[1]+b[2]

A [ 2 ] = g [ 2 ] ( Z [ 2 ] ) A^{[2]} = g^{[2]}(Z^{[2]}) A[2]=g[2](Z[2])


Activation Function

Why do you Need Non-linear Activation Functions?

linear activation functions just make the neural network output the linear funtion of the input no matter how many layers contains. But somtimes, linear activation functions can be used to activate the output layer or compress neural network models.

Activation Functions’ Image

import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline
x = np.arange(-10, 10, 0.001)
y1 = 1 / (1 + np.exp(-x))
y2 = (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))
y3 = np.maximum(0, x)
y4 = np.maximum(0.1*x, x)

plt.rcParams['figure.dpi'] = 120
plt.subplots_adjust(left=2, bottom=2, right=3, top=3, 
wspace=0.5, hspace=0.5)

plt.subplot(221)
plt.plot(x, y1, label="Sigmoid")
plt.grid(color="gray", linestyle="--")
plt.title(r"$y=\frac{1}{1+e^{(-x)}}$")
plt.legend()

plt.subplot(222)
plt.plot(x, y2, label="Tanh")
plt.grid(color="gray", linestyle="--")
plt.title(r"$y=\frac{e^{(x)}-e^{(-x)}}{e^{(x)}+e^{(-x)}}$")
plt.legend()

plt.subplot(223)
plt.plot(x, y3, label="Relu")
plt.grid(color="gray", linestyle="--")
plt.title(r"$y=\frac{1}{1+e^{(-x)}}$")
plt.legend()

plt.subplot(224)
plt.plot(x, y4, label="LeakRelu")
plt.grid(color="gray", linestyle="--")
plt.title(r"$y=\frac{1}{1+e^{(-x)}}$")
plt.legend()

在这里插入图片描述

Derivatives of Activation Functions

x = np.arange(-10, 10, 0.001)
dy1 = y1* (1 - y1)
dy2 = 1 - y2 ** 2
dy3 = np.where(x>0, 1, 0)
dy4 = np.where(x>0, 1, 0.1)

plt.rcParams['figure.dpi'] = 120
plt.subplots_adjust(left=2, bottom=2, right=3 , top=3, wspace=0.5, hspace=0.5)

plt.subplot(221)
plt.plot(x, dy1, label="Sigmoid")
plt.grid(color="gray", linestyle="--")
plt.title(r"$dy=sigmoid(x)(1-sigmoid(x))$")
plt.legend()

plt.subplot(222)
plt.plot(x, dy2, label="Tanh")
plt.grid(color="gray", linestyle="--")
plt.title(r"$dy=1-tanh^{2}(x)$")
plt.legend()

plt.subplot(223)
plt.plot(x, dy3, label="Relu")
plt.grid(color="gray", linestyle="--")
plt.title(r"$")
plt.legend()

plt.subplot(224)
plt.plot(x, dy4, label="LeakRelu")
plt.grid(color="gray", linestyle="--")
plt.title(r"$")
plt.legend()

在这里插入图片描述

Different Choices

Recap:

If we set the 1st-convolution-layer’s parameters as W 1 , b 1 W_{1}, b_{1} W1,b1, the 2nd-convolution-layer’s parameters as W 2 , b 2 W_{2}, b_{2} W2,b2 and so on. we set a i a_{i} ai as the neural unit’s output, and the z i z_{i} zi as the output value before passing the activation function g g g.

According to the above statement, in CNN, the output of the first layer is a 1 = g ( W 1 x + b 1 ) a_{1} = g(W_{1}x + b_{1}) a1=g(W1x+b1), the output of the second layer is a 2 = g ( W 2 g ( W 1 x + b 1 ) + b 2 ) a_{2} = g(W_{2}g(W_{1}x + b_{1})+b_{2}) a2=g(W2g(W1x+b1)+b2), and the output of the third layer is a 3 = g ( W 3 g ( W 2 g ( W 1 x + b 1 ) + b 2 ) + b 3 ) a_{3} = g(W_{3}g(W_{2}g(W_{1}x + b_{1})+b_{2}) + b_{3}) a3=g(W3g(W2g(W1x+b1)+b2)+b3).

Set the final loss as L L L, let’s try to start with the third layer and use the BP algorithm to derive the bias of the loss on the parameters W 1 W_{1} W1 to see what happens.

Just for simplicity, I’m going to skip over the derivation, and the result is:
α L α W 1 = α L α a 3 α a 3 α z 3 W 3 α a 2 α z 2 W 2 α a 1 α z 1 α z 1 W 1 \frac{\alpha L}{\alpha W_{1}} =\frac{\alpha L}{\alpha a_{3}} \frac{\alpha a_{3}}{\alpha z_{3}}W_{3} \frac{\alpha a_{2}}{\alpha z_{2}}W_{2} \frac{\alpha a_{1}}{\alpha z_{1}} \frac{\alpha z_{1}}{W_{1}} αW1αL=αa3αLαz3αa3W3αz2αa2W2αz1αa1W1αz1

The derivative α a 3 α z 3 \frac{\alpha a_{3}}{\alpha z_{3}} αz3αa3, α a 2 α z 2 \frac{\alpha a_{2}}{\alpha z_{2}} αz2αa2 and α a 1 α z 1 \frac{\alpha a_{1}}{\alpha z_{1}} αz1αa1 are always the chief culprit of the problem about gradient vanishing.

so choose a proper activation function is important:

  • Sigmoid – rarely use except in the output layer of a two-classes classification problem, because the output value between [0,1]

  • Tanh – The tanh activation usually works better than sigmoid activation function for hidden units because the mean of its output is closer to zero, and so it centers the data better for the next layer

  • Relu – almost used

  • LeakRelu – better than Relu

TODO:: (Improve later)


Backpropagation of Neural Network

[外链图片转存失败(img-bLCOVzbl-1565522831176)(attachment:Screenshot%20from%202019-08-02%2020-52-40.png)]

we can get the derivative below:

single examplem examples
d z [ 2 ] = a [ 2 ] − y dz^{[2]} = a^{[2]} - y dz[2]=a[2]y d z [ 2 ] = a [ 2 ] − y dz^{[2]} = a^{[2]} - y dz[2]=a[2]y
d W [ 2 ] = d z [ 2 ] a [ 1 ] T dW^{[2]} = dz^{[2]}a^{[1]T} dW[2]=dz[2]a[1]T d W [ 2 ] = 1 m ( d z [ 2 ] a [ 1 ] T ) dW^{[2]} = \frac{1}{m}(dz^{[2]}a^{[1]T}) dW[2]=m1(dz[2]a[1]T)
d b [ 2 ] = d z [ 2 ] db^{[2]} = dz^{[2]} db[2]=dz[2] d b [ 2 ] = 1 m n p . s u m ( d z [ 2 ] , a x i s = 1 , k e e p d i m s = T r u e ) db^{[2]} = \frac{1}{m}np.sum(dz^{[2]}, axis=1, keepdims=True) db[2]=m1np.sum(dz[2],axis=1,keepdims=True)
d a [ 1 ] = W [ 2 ] T d z [ 2 ] da^{[1]} = W^{[2]T}dz^{[2]} da[1]=W[2]Tdz[2] d a [ 1 ] = W [ 2 ] T d z [ 2 ] da^{[1]} = W^{[2]T}dz^{[2]} da[1]=W[2]Tdz[2]
d z [ 1 ] = W [ 2 ] T d z [ 2 ] ∗ g ′ [ 1 ] ( z [ 1 ] ) dz^{[1]} = W^{[2]T}dz^{[2]} * g^{'[1]}(z^{[1]}) dz[1]=W[2]Tdz[2]g[1](z[1]) d z [ 1 ] = W [ 2 ] T d z [ 2 ] ∗ g ′ [ 1 ] ( z [ 1 ] ) dz^{[1]} = W^{[2]T}dz^{[2]} * g^{'[1]}(z^{[1]}) dz[1]=W[2]Tdz[2]g[1](z[1])
d W [ 1 ] = d z [ 1 ] a [ 0 ] T dW^{[1]} = dz^{[1]}a^{[0]T} dW[1]=dz[1]a[0]T d W [ 1 ] = 1 m ( d z [ 1 ] a [ 0 ] T ) dW^{[1]} = \frac{1}{m}(dz^{[1]}a^{[0]T}) dW[1]=m1(dz[1]a[0]T)
d b [ 2 ] = d z [ 1 ] db^{[2]} = dz^{[1]} db[2]=dz[1] d b [ 2 ] = 1 m n p . s u m ( d z [ 1 ] , a x i s = 1 , k e e p d i m s = T r u e ) db^{[2]} = \frac{1}{m}np.sum(dz^{[1]}, axis=1, keepdims=True) db[2]=m1np.sum(dz[1],axis=1,keepdims=True)

Random Initialization

Reminder: The general methodology to build a Neural Network is to:
1. Define the neural network structure ( # of input units, # of hidden units, etc).
2. Initialize the model’s parameters
3. Loop:
- Implement forward propagation
- Compute loss
- Implement backward propagation to get the gradients
- Update parameters (gradient descent)

Why we need to initialize parameters randomly?

If we set W [ 1 ] W^{[1]} W[1] as np.zeros(( n [ 1 ] n^{[1]} n[1], n [ 0 ] n^{[0]} n[0])), then a 1 [ 1 ] a^{[1]}_{1} a1[1] will be equal to a 2 [ 1 ] a^{[1]}_{2} a2[1] and d z 1 [ 1 ] dz^{[1]}_{1} dz1[1] will also be equal to d z 2 [ 1 ] dz^{[1]}_{2} dz2[1] in the backpropagation. So even after multiple iterations of gradient descent each neuron in the layer will be computing the same thing as other neurons. It turns out that the hidden units in same layer are completely identical although you update the parameters many times.

To avoid the problem above, we shoud initialize the parameters randomly. So we can set:
W [ 1 ] = n p . r a n d o m . r a n d n ( n [ 1 ] , n [ 0 ] ) W^{[1]} = np.random.randn(n^{[1]}, n^{[0]}) W[1]=np.random.randn(n[1],n[0])

b [ 1 ] = n p . z e r o s ( ( n [ 1 ] , n [ 0 ] ) ) b^{[1]} = np.zeros((n^{[1]}, n^{[0]})) b[1]=np.zeros((n[1],n[0]))

We usually prefer to initialize the weights to very small random values so that we can get a big slope and a faster learning speed when we use sigmoid or tanh activation funtion. so:
W [ 1 ] = n p . r a n d o m . r a n d n ( n [ 1 ] , n [ 0 ] ) ∗ 0.01 W^{[1]} = np.random.randn(n^{[1]}, n^{[0]}) * 0.01 W[1]=np.random.randn(n[1],n[0])0.01

TinyML边缘智能振动诊断实战-ESP32完整工程-v1.0.zip 无硬件可完整体验:固件内置信号合成模拟器(严格复现训练物理模型),串口发 S0~S3 切换 4 种机器故障 算子级正确性:用 inspect_model_ops.py 从 tflite 解析出实际算子(EXPAND_DIMS/CONV_2D/RESHAPE/MEAN/FC/SOFTMAX),固件注册逐一对应——规避了 TFLite Micro 最常见的 "Op type not found" 坑 诚实标注:文档中明确区分“合成演示数据 / 工程近似 / 实测值”,并给出接入真实数据的完整流程 立即下载

相关推荐

基于SpringBoot+Vue校园失物招领系统的设计与实现

校园失物招领系统的设计与实现前端采用了Vue框架,并结合ElementUI来实现界面的设计与布局。后端采用了SpringBoot框架进行开发设计,并结合了Java语言和MySQL数据库来实现。在功能上分为了前端用户模块和管理员模块。前端用户模块主要实现了招领物品信息的发布、查询与管理,失物信息的发布、管理以及自动匹配招领物品,查看校园相关通知公告。管理员模块主要实现了物品分类管理、校园通知管理以及物品招领信息的查询统计等功能。校园失物招领系统的实现优化失物招领的流程,提高了校园失物招领的效率,促进了校园文化的建设,营造了良好的诚信氛围。

Context Encoders: Feature Learning by Inpainting 上下文编码器:通过图像修复进行特征学习

加州大学伯克利分校Abstract摘要我们提出了一种由基于上下文的像素预测驱动的无监督视觉特征学习算法。类比于自动编码器,我们提出了 Context Encoders——一种卷积神经网络,其训练目标是根据任意图像区域周围的环境生成该区域的内容。为了成功完成这一任务,context encoders 不仅需要理解整幅图像的内容,还需要为缺失部分生成一个合理的假设。在训练 context encoders 时,我们同时尝试了标准的逐像素重建损失,以及重建损失加对抗损失。

u013250861的博客 97

科技成果转化效率低怎么办?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

Class4-Week4 Face Recognition & Neural Style Transfer

文章目录Face RecognitionFace Verification vs. Face RecognitionSiamese NetworkTriplet LossFace Verification and Binary classificationNeural Style TransferWhat is Neural Style TransferWhy Intermediate Layer...

language_zcx的博客 765

Class4-Week2 Case study

文章目录Classic NetworksLeNet-5AlexNetVGG-16Residual NetworksArchitectureWhy ResNets Works?Networks in network and 1x1 convolutionsInception NetworkArchitectureInception ModuleTransfer LearningData Argume...

language_zcx的博客 726

Loss Function Evolution for Face Recognition

文章目录Softmax LossSoftmaxSoftmax LossCenter Loss 损失函数往往导向着模型的收敛方向。一个好的损失函数对于所要解决的问题至关重要。现如今,人脸识别方法都是将人脸映射为低维feature vector,通过对比feature vector之间的距离来判断该人脸是否属于同一Identity。由于人脸类别多,同一类别的样本量少,因此通过训练模型增加类间(inter-class)距离,减小类内(intra-class)距离成为人脸识别领域的主要优化方向。近些年人脸识别算法的

language_zcx的博客 661

Class2-Week3 Hyperparameter Tuning

Hyperparameter Tuning Recommended Order: Firstly α\alphaα Secondly β\betaβ of momentum #hidden units #mini-batch size Third #layers learning rate decay Try random values when choose paramet...

language_zcx的博客 635

Class1-Week2-Neural Networks Basics

Logistic Regression Description Logistic regression is a learning algorithm used in a supervised learning problem when the output

language_zcx的博客 513

Class2-Week2 Optimization Algorithm

文章目录Mini-batch GradientImplementUnderstanding mini-batch gradient descentExponentially Weighted AverageGradient Descent with MomentumRMSProp(Root Mean Square Prop)Adam(Adaptive Moment Estimation)Learn...

language_zcx的博客 452

Class2-Week1-Improving Deep Neural Networks

文章目录Setting up your Machine Learning ApplicationTrain/Dev/Test SetsBais/VarianceRegularizing Neural NetworkL2-RegularizationWhy Regularization reduces overfitting?Dropout RegularizationSetting up your...

language_zcx的博客 434

Coursera-Machine Learning-ex2

Some Points: We can use regularization to prevent overfitting. note the index of  theta begin at 1 in the regularization formula.   The Results: plotData.m pos = find(y == 1); neg = find(y == ...

language_zcx的博客 427

Coursera-Machine Learning-ex5

Some Points:   The Results: linearRegCostFunction.m function [J, grad] = linearRegCostFunction(X, y, theta, lambda) % Initialize some useful values m = length(y); % number of training examples %...

language_zcx的博客 387

Class3-Week1 ML Strategy1

Orthogonalization Orthogonalization means you should ensure that adjusting “one parameter” affects only the spectific aspect you want to optimize of your model. Chain of assumptions in ML Fit trainin...

language_zcx的博客 364

Class1-Week4-Deep Neural Network

Compute Process Forward Propagation Layer-l: Input: A[l−1]A^{[l-1]}A[l−1] Compute Process: Z[l]=W[l]A[l−1]+b[l] Z^{[l]}=W^{[l]}A^{[l-1]}+b^{[l]} Z[l]=W[l]A[l−1]+b[l] A[l]=g(Z[l]) A^{[l]}=g(Z^{[l]}) A...

language_zcx的博客 333

有关深度神经网络参数初始化的1.思考

文章目录初始化参数不能为零?测试 A输出结果测试B输出结果结论 初始化参数不能为零? 测试 A import torch import torch.nn as nn import torch.nn.functional as F from torch.utils import data features = torch.randn((100, 3)) labels = torch.randn(100, 1) dataset = data.TensorDataset(features, labels) d

language_zcx的博客 309

Coursera-Machine Learning-ex4

Some Points: Implement Steps: 1.Pick a neural network  architecture. number of input units = dimension of features number of output units = number of classes number of hidden layer = 1(Default), ...

language_zcx的博客 255

Coursera-Machine Learning-ex3

Some Points: In the multi-class classification, the sum of probability of each class is not equal to 1 with the results of using logist regression to  train each class. The Results: lrCostFunction.m...

language_zcx的博客 250
上一篇: Class1-Week2-Neural Networks Basics
下一篇: Class1-Week4-Deep Neural Network
zcx_language
博客等级 码龄8年 15粉丝 73原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值