论文阅读+代价函数+激活函数

本文详细介绍了机器学习中的代价函数与激活函数,包括它们的定义、常见类型及其应用场景。探讨了代价函数如均方误差、交叉熵等在不同算法中的应用,并深入解析了激活函数如ReLU、tanh等在神经网络中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

=================第一部分 代价函数====================

代价函数=损失函数

    在机器学习中的每一种算法中,训练模型的过程就是优化代价函数的过程。代价函数对每个参数的偏导数就是梯度下降中提到的梯度,防止过拟合时添加的正则化项也是加在代价函数后面的。

一、什么是代价函数

假设有训练样本(x, y),模型h,参数θ。h(θ) = θTx(θT表示θ的转置)。

(1)概况来讲,任何能够衡量模型的预测值h(θ)与真实值y之间差异的函数都可以叫做代价函数C(θ),如果有多个样本,则可以将所有代价函数的结果求均值,记做J(θ)。因此很容易得出以下关于代价函数的性质:

  • 对于每种算法来说,代价函数不是唯一的;

  • 代价函数是参数θ的函数;

  • 总的代价函数J(θ)可以用来评价模型的好坏,代价函数越小说明模型和参数越符合训练样本(x, y);

  • J(θ)是一个标量;

(2)当我们确定了模型h,后面做的所有事情就是训练模型的参数θ。那么什么时候训练才能结束呢?这时候也涉及到代价函数,由于代价函数是用来衡量模型好坏的,我们的目标当然是得到最好的模型(也就是最符合训练样本(x, y)的模型)。因此训练参数的过程就是不断改变θ,从而得到更小的J(θ)的过程。理想情况下,当我们取到代价函数J的最小值时,就得到了最优的参数θ,记为:

                                                                             

例如,J(θ) = 0,表示我们的模型完美的拟合了观察的数据,没有任何误差。

(3)在优化参数θ的过程中,最常用的方法是梯度下降,这里的梯度就是代价函数J(θ)对θ1, θ2, ..., θn的偏导数。由于需要求偏导,我们可以得到另一个关于代价函数的性质:

  • 选择代价函数时,最好挑选对参数θ可微的函数(全微分存在,偏导数一定存在)

经过上面的描述,一个好的代价函数需要满足两个最基本的要求:能够评价模型的准确性,对参数θ可微。

二、常见的代价函数

均方误差、交叉熵、sotmax代价函数、逻辑斯蒂回归代价函数、0-1损失函数、指数损失函数。

交叉熵、逻辑斯蒂回归代价函数、softmax函数的形式非常相似。 

三、均方误差代价函数

   在线性回归中,最常用的是均方误差(Mean squared error),具体形式为:


四、交叉熵代价函数

在逻辑回归中,最常用的是代价函数是交叉熵(Cross Entropy),交叉熵是一个常见的代价函数,在神经网络中也会用到。

(1)对交叉熵的解释:

  交叉熵是对“出乎意料”的是事件的度量。假如我们认为p是y=1的概率,(1-p)是y=0的概率,那么交叉熵衡量的是我们在知道y的真实值时平均“出乎意料”的程度。当输出是我们期望的值时,我们“出乎意料”程度较低;当输出不是我们期望的值时,我们“出乎意料”的程度较高。

(2)交叉熵公式:


(3)交叉熵推导。

=>推导过程:



我们将概率取对数,其单调性不变,有


则取0。那么对于一共m组样本,我们就可以得到模型对于整体训练样本的表现能力:

 

推导结束。

参考文献:https://blog.youkuaiyun.com/jasonzzj/article/details/52017438

https://blog.youkuaiyun.com/u014313009/article/details/51043064

---------------------------------------------------------------------------------------------------------------

扩充:交叉熵继续化简的结果:



sigmoid函数和假设函数长的是一个样的啊!!!!快被它们几个绕晕了。

五、逻辑回归代价函数

         逻辑回归是神经网络的一种特例,因此神经网络中的代价函数与逻辑回归中的代价函数很相似:

                      

这里多了一层求和项,是因为神经网络的输出值一般不是单一的值,K表示在多分类问题中的类型数。



第六、softmax 回归算法的代价函数(在逻辑斯蒂回归中扩展到K类问题)

softmax回归算法中的代价函数为:

\begin{align}J(\theta) = - \frac{1}{m} \left[ \sum_{i=1}^{m} \sum_{j=1}^{k}  1\left\{y^{(i)} = j\right\} \log \frac{e^{\theta_j^T x^{(i)}}}{\sum_{l=1}^k e^{ \theta_l^T x^{(i)} }}\right]\end{align}

在Softmax回归中将 \textstyle x 分类为类别 \textstyle j 的概率为:

p(y^{(i)} = j | x^{(i)} ; \theta) = \frac{e^{\theta_j^T x^{(i)}}}{\sum_{l=1}^k e^{ \theta_l^T x^{(i)}} }

我们通过添加一个权重衰减项 \textstyle \frac{\lambda}{2} \sum_{i=1}^k \sum_{j=0}^{n} \theta_{ij}^2 来修改代价函数,这个衰减项会惩罚过大的参数值,现在我们的代价函数变为:

\begin{align}J(\theta) = - \frac{1}{m} \left[ \sum_{i=1}^{m} \sum_{j=1}^{k} 1\left\{y^{(i)} = j\right\} \log \frac{e^{\theta_j^T x^{(i)}}}{\sum_{l=1}^k e^{ \theta_l^T x^{(i)} }}  \right]              + \frac{\lambda}{2} \sum_{i=1}^k \sum_{j=0}^n \theta_{ij}^2\end{align}

为了使用优化算法,我们需要求得这个新函数 \textstyle J(\theta) 的导数,如下:

\begin{align}\nabla_{\theta_j} J(\theta) = - \frac{1}{m} \sum_{i=1}^{m}{ \left[ x^{(i)} ( 1\{ y^{(i)} = j\}  - p(y^{(i)} = j | x^{(i)}; \theta) ) \right]  } + \lambda \theta_j\end{align}


通过最小化 \textstyle J(\theta),我们就能实现一个可用的 softmax 回归模型。 

参考资料: http://deeplearning.stanford.edu/wiki/index.php/Softmax%E5%9B%9E%E5%BD%92

================第二部分激活函数================

一、什么是激活函数+激活函数的作用

=>不用激活函数可不可以?答案是不可以。

=>激活函数是什么?激活函数是这样的一种函数,首先它们具有以下的一些性质:可微性、单调性、以及输出值的范围是有限的。其次,激活函数一般使用在神经网络中。最后,激活函数的作用是为了让网络具有非线性的建模能力。

那么激活函数应该具有什么样的性质呢?

可微性: 当优化方法是基于梯度的时候,这个性质是必须的。 
单调性: 当激活函数是单调的时候,单层网络能够保证是凸函数。 
输出值的范围: 当激活函数输出值是 有限 的时候,基于梯度的优化方法会更加 稳定,因为特征的表示受有限权值的影响更显著;当激活函数的输出是 无限 的时候,模型的训练会更加高效,不过在这种情况小,一般需要更小的learning rate

=>激活函数有什么用?激活函数的主要作用是提供网络的非线性建模能力。如果没有激活函数,那么该网络仅能够表达线性映射,此时即便有再多的隐藏层,其整个网络跟单层神经网络也是等价的。因此也可以认为,只有加入了激活函数之后,深度神经网络才具备了分层的非线性映射学习能力。 

二、常见的激活函数有哪些?各自的应用场景是什么?如何选择合适的激活函数?

从目前来看,常见的激活函数多是分段线性和具有指数形状的非线性函数

    函数  优点缺点
   sigmoid                 

1.饱和性。从上图可以看到,其两侧导数逐渐趋近于0 

2.sigmoid函数的输出均大于0,使得输出不是0均值,这称为偏移现象,这会导致后一层的神经元将得到上一层输出的非0均值的信号作为输入。

tanh 


它的输出均值是0,使得其收敛速度要比sigmoid快,减少迭代次数。tanh一样具有软饱和性,从而造成梯度消失。
softmax激活函数                           
   

三、sigmoid激活函数

1.函数的公式以及数学图像。


sigmoid 是使用范围最广的一类激活函数,具有指数函数形状,它在物理意义上最为接近生物神经元。此外,(0, 1) 的输出还可以被表示作概率,或用于输入的归一化,代表性的如Sigmoid交叉熵损失函数。

然而,sigmoid也有其自身的缺陷,最明显的就是饱和性。从上图可以看到,其两侧导数逐渐趋近于0 

sigmoid 的软饱和性,使得深度神经网络在二三十年里一直难以有效的训练,是阻碍神经网络发展的重要原因。具体来说,由于在后向传递过程中,sigmoid向下传导的梯度包含了一个 f(x) 因子(sigmoid关于输入的导数),因此一旦输入落入饱和区,f(x) 就会变得接近于0,导致了向底层传递的梯度也变得非常小。此时,网络参数很难得到有效训练。这种现象被称为梯度消失。一般来说, sigmoid 网络在 5 层之内就会产生梯度消失现象

此外,sigmoid函数的输出均大于0,使得输出不是0均值,这称为偏移现象,这会导致后一层的神经元将得到上一层输出的非0均值的信号作为输入。


四、RELU激活函数、P-ReLU, Leaky-ReLU


ReLU的全称是Rectified Linear Units,是一种后来才出现的激活函数。 可以看到,当x<0时,ReLU硬饱和,而当x>0时,则不存在饱和问题。所以,ReLU 能够在x>0时保持梯度不衰减,从而缓解梯度消失问题。这让我们能够直接以监督的方式训练深度神经网络,而无需依赖无监督的逐层预训练。

然而,随着训练的推进,部分输入会落入硬饱和区,导致对应权重无法更新。这种现象被称为“神经元死亡”。与sigmoid类似,ReLU的输出均值也大于0,偏移现象和 神经元死亡会共同影响网络的收敛性。

针对在x<0的硬饱和问题,我们对ReLU做出相应的改进,使得 

这就是Leaky-ReLU, 而P-ReLU认为,α也可以作为一个参数来学习,原文献建议初始化a为0.25,不采用正则。

五、tanh函数


tanh也是一种非常常见的激活函数。与sigmoid相比,它的输出均值是0,使得其收敛速度要比sigmoid快,减少迭代次数。然而,从途中可以看出,tanh一样具有软饱和性,从而造成梯度消失。

第六、ELU


        融合了sigmoid和ReLU,左侧具有软饱和性,右侧无饱和性。右侧线性部分使得ELU能够缓解梯度消失,而左侧软饱能够让ELU对输入变化或噪声更鲁棒。ELU的输出均值接近于零,所以收敛速度更快。在 ImageNet上,不加 Batch Normalization 30 层以上的 ReLU 网络会无法收敛,PReLU网络在MSRA的Fan-in (caffe )初始化下会发散,而 ELU 网络在Fan-in/Fan-out下都能收敛。

第七、maxout函数

    这个激活函数有点大一统的感觉,因为maxout网络能够近似任意连续函数,且当w2,b2,…,wn,bn为0时,退化为ReLU。Maxout能够缓解梯度消失,同时又规避了ReLU神经元死亡的缺点,但增加了参数和计算量。

第八、softmax激活函数

1.softmaxe函数的数学表达式


                                                                       

2.softmax的应用场景

       用于多分类过程中,它将多个神经元的输出,映射到(0,1)区间内,可以看成概率来理解,从而来进行多分类!

3.softmax激活函数的特点

1.它把每个神经元的输入占当前层所有神经元输入之和的比值,当作该神经元的输出。这使得输出更容易被解释:神经元的输出值越大,则该神经元对应的类别是真实类别的可能性更高。

2.softmax不仅把神经元输出构造成概率分布,而且还起到了归一化的作用,适用于很多需要进行归一化处理的分类问题。

4.softmax激活函数的求导(反向传播)

由于softmax在ANN算法中的求导结果比较特别,分为两种情况。求导过程如下所示:


参考资料:https://blog.youkuaiyun.com/u014313009/article/details/51045303

这是前面的13篇论 1 Keyword search on structured and semi-structured data Yi Chen, Wei Wang, Ziyang Liu, Xuemin Lin Jun. 2009 Proceedings of the 35th SIGMOD international conference on Management of data 2 Efficient type-ahead search on relational data: a TASTIER approach Guoliang Li, Shengyue Ji, Chen Li, Jianhua Feng 3 FlashLogging: exploiting flash devices for synchronous logging performance Shimin Chen 4 Query processing techniques for solid state drives Dimitris Tsirogiannis, Stavros Harizopoulos, Mehul A. Shah, Janet L. Wiener, Goetz Graefe 5 A revised r*-tree in comparison with related index structures Norbert Beckmann, Bernhard Seeger 6 ZStream: a cost-based query processor for adaptively detecting composite events Yuan Mei, Samuel Madden Jun. 2009 Proceedings of the 35th SIGMOD international conference on Management of data Composite (or Complex) event processing (CEP) systems search sequences of incoming events for occurrences of user-specified event patterns. Recently, they have gained more attention in a variety of areas due to their powerful and expressive ... 7 A comparison of flexible schemas for software as a service Stefan Aulbach, Dean Jacobs, Alfons Kemper, Michael Seibold Jun. 2009 Proceedings of the 35th SIGMOD international conference on Management of data A multi-tenant database system for Software as a Service (SaaS) should offer schemas that are flexible in that they can be extended different versions of the application and dynamically modified while the system is on-line. This ... 8 Query optimizers: time to rethink the contract? Surajit Chaudhuri Jun. 2009 Proceedings of the 35th SIGMOD international conference on Management of data Query Optimization is expected to produce good execution plans for complex queries while taking relatively small optimization time. Moreover, it is expected to pick the execution plans with rather limited knowledge of data and without any ... 9 Keyword search in databases: the power of RDBMS Lu Qin, Jeffrey Xu Yu, Lijun Chang Jun. 2009 Proceedings of the 35th SIGMOD international conference on Management of data Keyword search in relational databases (RDBs) has been extensively studied recently. A keyword search (or a keyword query) in RDBs is specified by a set of keywords to explore the interconnected tuple structures in an RDB ... 10 ROX: run-time optimization of XQueries Riham Abdel Kader, Peter Boncz, Stefan Manegold, Maurice van Keulen Jun. 2009 Proceedings of the 35th SIGMOD international conference on Management of data Optimization of complex XQueries combining many XPath steps and joins is currently hindered by the absence of good cardinality estimation and cost models for XQuery. Additionally, the state-of-the-art of even relational query optimization still ... 11 Query by output Quoc Trung Tran, Chee-Yong Chan, Srinivasan Parthasarathy Jun. 2009 Proceedings of the 35th SIGMOD international conference on Management of data It has recently been asserted that the usability of a database is as important as its capability. Understanding the database schema, the hidden relationships among attributes in the data all play an important role in this context. Subscribing ... 12 Ranking distributed probabilistic data Feifei Li, Ke Yi, Jeffrey Jestes Jun. 2009 Proceedings of the 35th SIGMOD international conference on Management of data Ranking queries are essential tools to process large amounts of probabilistic data that encode exponentially many possible deterministic instances. In many applications where uncertainty and fuzzy information arise, data are collected from ... 13 Authenticated join processing in outsourced databases Yin Yang, Dimitris Papadias, Stavros Papadopoulos, Panos Kalnis Jun. 2009 Proceedings of the 35th SIGMOD international conference on Management of data Database outsourcing requires that a query server constructs a proof of result correctness, which can be verified by the client using the data owner's signature. Previous authentication techniques deal with range queries on a single relation ...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值