神经网络的编程基础(Basics of Neural Network programming)学习笔记

作者 :arsoooo

1.1二分类(Binary Classification)+逻辑回归(Logistic Regression)

我下面用自己浅显的语言描述我对 “二分类” 和“逻辑回归” 的理解,如确认一个图片是不是猫这个动物,“二分类”就是用是(1)或者不是(0)去判断,而逻辑回归是一个用于二分类的算法。
算法其实很简单,就下面这张图:
在这里插入图片描述
1.yhat表示y(我们测试图片的输出结果)等于1的一种可能性或者是机会
2.Z=wTx+b是最为重要的,其中x是我们测试图片所有的特征值组成的特征向量,wT是每个向量对应的权重,b是一个偏差值
3.而sigmod函数就是一个归一化函数,把Z归一化到0和1之间,即yhat

简单吧,就相当于把输入图片的特征输入,通过逻辑回归的算法,最后输出对这个图片的判断。而里面的权重(wT)和偏差(b)就是我们要计算机自己训练的到的变量。


1.2逻辑回归的代价函数(Logistic Regression Cost Function)

逻辑回归的损失函数:
在这里插入图片描述
说来也简单,在这门课中有很多的函数效果和现在这个类似,损失函数的意思就是如果y等于1,我们就尽可能让yhat变大,如果y等于0,我们就尽可能让yhat变小。而结果越大,损失就越大。
而什么是代价函数呢?代价函数J是对个m样本的损失函数求和然后除m
如下图所示:
在这里插入图片描述
所以说代价函数就是一个判断你精确度的测量数值,而我们肯定是希望用更好的wT和b,从而让代价函数J的总代价降到最低。


1.3梯度下降法(Gradient Descent)

什么是梯度下降呢?看到下面的笑脸了吗,他其实就是我们的代价函数J,他有一个最小值。
在这里插入图片描述
2D的图片太丑(哈哈),下面是一个3D的图片,更为直观,我们需要的就是不断调整w和b,从而让代价函数J最小,这意味着更精确,而不断下降去找到最低点的过程就是梯度下降,通过训练,朝最陡的下坡方向走一步,不断地迭代。
在这里插入图片描述

这里要引入一个参数α表示学习率(learning rate),用来控制步长(step)
在这里插入图片描述
我们称上式是w和b的修正量。所以简单来说,α就是你控制w和b每次迭代,去试探最小值点的速度,公式中的偏导数就是斜率。


1.4逻辑回归中的梯度下降(Logistic Regression Gradient Descent)

(下面式子是通过对损失函数L微积分计算得来,过程略,记结论)
dz = a-y (注:这里a=yhat)
dwi = xi * dz
db = dz
由上面三个式子得到dz、dwi、db,然后通过w和b的修正量的式子:
wi = wi - αdwi
b = b - αb
这就是关于单个样本实例的梯度下降算法中参数更新一次的步骤。


1.5 m 个样本的梯度下降(Gradient Descent on m Examples)

1.4是对一个样本,用的是损失函数L,而这里m样本对应的就是代价函数J了。
代价函数J的定义就是损失函数L的求和平均
在这里插入图片描述
同理,m个样本的梯度下降就是单个样本梯度下降的求和平均,实际上是1到m项各个损失的平均。


1.6 向量化(Vectorization)

向量化是为了解决代码中for循环导致的低效问题,应该避免写循环(loop)语句。

//下面是计算Z的numpy代码,此处b是实数,会自动变成向量进行计算
Z = np.dot(w.T,X) + b;
A = sigmoid(Z);	//A就是yhat

//其余的量也可以用向量计算代替loop循环
dZ = A - Y;	//这里就是m个dzi组成的行向量
dw = (X-dz.T)/m; //求平均
db = np.sum(dZ)/m; //求平均

注:一般大写表示向量,小写代表元素


1.7 numpy中的广播(Broadcasting in numpy)

在这里插入图片描述
这里不赘述其特性,吴恩达老师给出的建议是,在编程中若需要一个5行1列的矩阵,请使用:

a = np.radom.randn(5,1); //这是一个51列的矩阵

而不是下面这种,注意区别:

a = np.radom.randn(5); //这是一个一维数组,转置即本身

当在编程练习或者在执行逻辑回归和神经网络时,不需要使用这些一维数组。
当然,如果你不小心以一维数组来执行,你也能够重新改变数组维数 :

a = a.reshape((5,1)); //reshape()是数组array中的方法,作用是将数据重新组织

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hands-On Network Programming with C# and .NET Core: A comprehensive guide to understanding network architecture, communication protocols, and network analysis to build secure applications compatible with the latest versions of C# 8 and .NET Core 3.0 The C# language and the .NET Core application framework provide the tools and patterns required to make the discipline of network programming as intuitive and enjoyable as any other aspect of C# programming. With the help of this book, you will discover how the C# language and the .NET Core framework make this possible. The book begins by introducing the core concepts of network programming, and what distinguishes this field of programming from other disciplines. After this, you will gain insights into concepts such as transport protocols, sockets and ports, and remote data streams, which will provide you with a holistic understanding of how network software fits into larger distributed systems. The book will also explore the intricacies of how network software is implemented in a more explicit context, by covering sockets, connection strategies such as Transmission Control Protocol (TCP) and User Datagram Protocol (UDP), asynchronous processing, and threads. You will then be able to work through code examples for TCP servers, web APIs served over HTTP, and a Secure Shell (SSH) client. What You Will Learn Understand the breadth of C#’s network programming utility classes Utilize network-layer architecture and organizational strategies Implement various communication and transport protocols within C# Discover hands-on examples of distributed application development Gain hands-on experience with asynchronous socket programming and streams Learn how C# and the .NET Core runtime interact with a hosting network Understand a full suite of network programming tools and features By the end of this Hands-On Network Programming with C# and .NET Core book, you will have a good understanding of the Open Systems Interconnection (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值