softmax原理及Matlab实现

一、从广义线性模型中导出softmax模型
摘要由CSDN通过智能技术生成

一、softmax 

softmax模型的含义是假设后验概率P(y|x)服从多项式分布,y=1,2,3,4,..,k,即有k类,根据多项式分布(n=1,也可以称为目录分布)的定义:



二、从广义线性模型中推导出softmax模型


我们的目标是给定X,求出参数phi,需要建立参数phi对X的模型,下面给出模型的推导。


下面我们将后验概率写成指数函数族的形式,以得出



三、优化函数与梯度

现在我们已经建立了参数phi对X的模型,下面需要做的是估计参数theta的值,利用最大似然估计即可。

下面求解梯度:


四、正则惩罚

为了使目标函数严格凸函数即存在唯一最小值,再加入一个权值惩罚项,得到新的目标函数与梯度:



五、matlab实验

实验数据用到了mnist数据库,用于识别10个手写数字。
%% CS294A/CS294W Softmax Exercise 

%  Instructions
%  ------------
% 
%  This file contains code that helps you get started on the
%  softmax exercise. You will need to write the softmax cost function 
%  in softmaxCost.m and the softmax prediction function in softmaxPred.m. 
%  For this exercise, you will not need to change any code in this file,
%  or any other files other than those mentioned above.
%  (However, you may be required to do so in later exercises)

%%==============================================
  • 2
    点赞
  • 64
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值