ufldl学习笔记和编程作业:Softmax Regression(softmax回报)
ufldl学习笔记与编程作业:Softmax Regression(softmax回归)
ufldl出了新教程。感觉比之前的好,从基础讲起。系统清晰,又有编程实践。
在deep learning高质量群里面听一些前辈说,不必深究其它机器学习的算法,能够直接来学dl。
于是近期就開始搞这个了。教程加上matlab编程,就是完美啊。
新教程的地址是:http://ufldl.stanford.edu/tutorial/
本节学习链接:http://ufldl.stanford.edu/tutorial/supervised/SoftmaxRegression/
softmax回归事实上是逻辑回归的扩展形式,
逻辑回归通经常使用作2类的分类器,
softmax则用作多类的分类器。
从数学形式来说,事实上逻辑回归就是softmax回归中k=2的情况。这点教程里也说了。
softmax的目标函数和參数的偏导数教程推导也非常清楚。
对于编程作业。因为对matlab实现不熟,跳了非常多坑。
弄了非常久,并且还仅仅是用for循环来实现的。
这次最终体会到了,for循环的性能之差了。迭代了200次。1个多小时。
也跟这个模型比前两个模型复杂有关。
先贴第一个版本号的代码吧。以后想出了向量化的编程再补上。
下面是softmax_regression.m的代码
- function [f,g] = softmax_regression_vec(theta, X,y)
- %
- % Arguments:
- % theta - A vector containing the parameter values to optimize.
- % In minFunc, theta is reshaped to a long vector. So we need to
- % resize it to an n-by-(num_classes-1) matrix.
- % Recall that we assume theta(:,num_classes) = 0.
- %
- % X - The examples stored in a matrix.
- % X(i,j) is the i'th coordinate of the j'th example.
- % y - The label for each example. y(j) is the j'th example's label.
- %
- m=size(X,2);
- n=size(X,1);
- %theta本来是矩阵,传參的时候,theta(:)这样进来的。是一个vector,仅仅有一列,如今我们得把她变为矩阵
- % theta is a vector; need to reshape to n x num_classes.
- theta=reshape(theta, n, []);
- num_classes=size(theta,2)+1;
- % initialize objective value and gradient.
- f = 0;
- g = zeros(size(theta));
- h = theta'*X;%h(k,i)第k个theta。第i个样本 麻痹还是得循环求啊
- a = exp(h);
- a = [a;ones(1,size(a,2))];%加行
- b = sum(a,1);
- for i=1:m
- for j=1:num_classes
- if y(i)!=j
- continue;
- end
- f+=log2(a(j,i)/b(i));
- end
- end
- f=-f;%符号
- flag=0;
- for j=1:num_classes-1
- for i=1:m
- if (y(i)==j)
- flag =1;
- else
- flag=0;
- end
- g(:,j)+=X(:,i)*(a(j,i)/b(i)-flag);
- end
- end
- %
- % TODO: Compute the softmax objective function and gradient using vectorized code.
- % Store the objective function value in 'f', and the gradient in 'g'.
- % Before returning g, make sure you form it back into a vector with g=g(:);
- %
- %%% YOUR CODE HERE %%%
- g=g(:); % make gradient a vector for minFunc
下面是执行结果:
旧教程http://deeplearning.stanford.edu/wiki/index.php/Exercise:Softmax_Regression
也有softmax的编程作业。里面也是识别手写体数字。
当中提到准确率的问题。
Our implementation achieved an accuracy of 92.6%.
If your model's accuracy is significantly less (less than 91%), check your code, ensure that you are using the trained weights, and that you are training your model on the full 60000 training images. Conversely, if your accuracy is too high (99-100%), ensure
that you have not accidentally trained your model on the test set as well.
也就是说,从准确率来说,我的代码还是能够的。
接下来就是想办法实现向量化编程,加高速度了。
假设您有什么好想法。记得分享一下哦!
本文作者:linger
本文链接:http://blog.csdn.net/lingerlanlan/article/details/38410123
版权声明:本文博客原创文章,博客,未经同意,不得转载。
ufldl学习笔记和编程作业:Softmax Regression(softmax回报)的更多相关文章
- ufldl学习笔记与编程作业:Softmax Regression(vectorization加速)
ufldl学习笔记与编程作业:Softmax Regression(vectorization加速) ufldl出了新教程,感觉比之前的好.从基础讲起.系统清晰,又有编程实践. 在deep learn ...
- ufldl学习笔记与编程作业:Logistic Regression(逻辑回归)
ufldl学习笔记与编程作业:Logistic Regression(逻辑回归) ufldl出了新教程,感觉比之前的好,从基础讲起.系统清晰,又有编程实践. 在deep learning高质量群里面听 ...
- ufldl学习笔记与编程作业:Linear Regression(线性回归)
ufldl学习笔记与编程作业:Linear Regression(线性回归) ufldl出了新教程,感觉比之前的好.从基础讲起.系统清晰,又有编程实践. 在deep learning高质量群里面听一些 ...
- ufldl学习笔记与编程作业:Multi-Layer Neural Network(多层神经网络+识别手写体编程)
ufldl学习笔记与编程作业:Multi-Layer Neural Network(多层神经网络+识别手写体编程) ufldl出了新教程,感觉比之前的好,从基础讲起,系统清晰,又有编程实践. 在dee ...
- ufldl学习笔记和编程作业:Feature Extraction Using Convolution,Pooling(卷积和汇集特征提取)
ufldl学习笔记与编程作业:Feature Extraction Using Convolution,Pooling(卷积和池化抽取特征) ufldl出了新教程,感觉比之前的好,从基础讲起.系统清晰 ...
- Andrew Ng机器学习编程作业: Linear Regression
编程作业有两个文件 1.machine-learning-live-scripts(此为脚本文件方便作业) 2.machine-learning-ex1(此为作业文件) 将这两个文件解压拖入matla ...
- UFLDL教程笔记及练习答案三(Softmax回归与自我学习***)
:softmax回归 当p(y|x,theta)满足多项式分布,通过GLM对其进行建模就能得到htheta(x)关于theta的函数,将其称为softmax回归. 教程中已经给了cost及gradie ...
- Andrew Ng机器学习编程作业:Logistic Regression
编程作业文件: machine-learning-ex2 1. Logistic Regression (逻辑回归) 有之前学生的数据,建立逻辑回归模型预测,根据两次考试结果预测一个学生是否有资格被大 ...
- 我的学习笔记_Windows_HOOK编程 2009-12-03 11:19
一.什么是HOOK? "hook"这个单词的意思是"钩子","Windows Hook"是Windows消息处理机制的一个重要扩展,程序猿能 ...
随机推荐
- Java经典面试题及详解
Java基础方面: 1.作用域public,private,protected,以及不写时的区别 答:区别如下: 作用域 当前类 同一package ...
- JavaScript学习总结1
/***我是切割线 的開始***/ //利用prototype属性能够加入公有属性和方法 function myConstructor2(){ this.a='大灰狼'; }; //声明构造函数,能够 ...
- 对struts2的OGNL的理解
OGNL:Object-Graph Navigation Language.对象图形化导航语言 OGNL是集成进struts2框架中比較强大的技术有助于传输数据和类型转换,OGNL由表达式语言和类型装 ...
- Setup SSH and SVN on Windows Server
cygwin: install sshd, cygrunsrv http://lifehacker.com/205090/geek-to-live--set-up-a-personal-home-ss ...
- 用Qt开发Web和本地混合的应用
QtWebkit 模块使得Qt widget能够通过HTML的object标签嵌入到web页面中,并通过JavaScript代码进行访问,而Qt对象也能相应的访问web页面元素. 将Qt对象插入到we ...
- thinkPHP 空模块和空操作、前置操作和后置操作 详细介绍(十四)
原文:thinkPHP 空模块和空操作.前置操作和后置操作 详细介绍(十四) 本章节:介绍 TP 空模块和空操作.前置操作和后置操作 详细介绍 一.空模块和空操作 1.空操作 function _em ...
- 深入 CSocket 编程之阻塞和非阻塞模式
有时,花上几个小时阅读.调试.跟踪优秀的源码程序,能够更快地掌握某些技术关键点和精髓.当然,前提是对这些技术大致上有一个了解. 我通过几个采用 CSocket 类编写并基于 Client/Server ...
- 解决编译apache出现的问题:configure: error: APR not found . Please read the documentation - ____哊.時^随记 - 51CTO技术博客
解决编译apache出现的问题:configure: error: APR not found . Please read the documentation - ____哊.時^随记 - 51CTO ...
- ssh-copy-id -i ~/.ssh/id_rsa.pub admin@172.17.42.66
ssh-copy-id -i ~/.ssh/id_rsa.pub admin@172.17.42.66
- Ajenti 1.0 发布,服务器管理系统 - 开源中国社区
Ajenti 1.0 发布,服务器管理系统 - 开源中国社区 Ajenti 1.0 发布,服务器管理系统