Exercise:Learning color features with Sparse Autoencoders

习题链接:Exercise:Learning color features with Sparse Autoencoders

sparseAutoencoderLinearCost.m

function [cost,grad,features] = sparseAutoencoderLinearCost(theta, visibleSize, hiddenSize, ...lambda, sparsityParam, beta, data)
% -------------------- YOUR CODE HERE --------------------
% Instructions:
%   Copy sparseAutoencoderCost in sparseAutoencoderCost.m from your
%   earlier exercise onto this file, renaming the function to
%   sparseAutoencoderLinearCost, and changing the autoencoder to use a
%   linear decoder.
% -------------------- YOUR CODE HERE --------------------                                    % W1 is a hiddenSize * visibleSize matrix
W1 = reshape(theta(1:hiddenSize*visibleSize), hiddenSize, visibleSize);
% W2 is a visibleSize * hiddenSize matrix
W2 = reshape(theta(hiddenSize*visibleSize+1:2*hiddenSize*visibleSize), visibleSize, hiddenSize);
% b1 is a hiddenSize * 1 vector
b1 = theta(2*hiddenSize*visibleSize+1:2*hiddenSize*visibleSize+hiddenSize);
% b2 is a visible * 1 vector
b2 = theta(2*hiddenSize*visibleSize+hiddenSize+1:end);numCases = size(data, 2);% forward propagation
z2 = W1 * data + repmat(b1, 1, numCases);
a2 = sigmoid(z2);
z3 = W2 * a2 + repmat(b2, 1, numCases);
a3 = z3;% error
sqrerror = (data - a3) .* (data - a3);
error = sum(sum(sqrerror)) / (2 * numCases);
% weight decay
wtdecay = (sum(sum(W1 .* W1)) + sum(sum(W2 .* W2))) / 2;
% sparsity
rho = sum(a2, 2) ./ numCases;
divergence = sparsityParam .* log(sparsityParam ./ rho) + (1 - sparsityParam) .* log((1 - sparsityParam) ./ (1 - rho));
sparsity = sum(divergence);cost = error + lambda * wtdecay + beta * sparsity;% delta3 is a visibleSize * numCases matrix
delta3 = -(data - a3);
% delta2 is a hiddenSize * numCases matrix
sparsityterm = beta * (-sparsityParam ./ rho + (1-sparsityParam) ./ (1-rho));
delta2 = (W2' * delta3 + repmat(sparsityterm, 1, numCases)) .* sigmoiddiff(z2);

W1grad = delta2 * data' ./ numCases + lambda * W1;
b1grad = sum(delta2, 2) ./ numCases;W2grad = delta3 * a2' ./ numCases + lambda * W2;
b2grad = sum(delta3, 2) ./ numCases;%-------------------------------------------------------------------
% After computing the cost and gradient, we will convert the gradients back
% to a vector format (suitable for minFunc).  Specifically, we will unroll
% your gradient matrices into a vector.grad = [W1grad(:) ; W2grad(:) ; b1grad(:) ; b2grad(:)];endfunction sigm = sigmoid(x)sigm = 1 ./ (1 + exp(-x));
endfunction sigmdiff = sigmoiddiff(x)sigmdiff = sigmoid(x) .* (1 - sigmoid(x));
end

如果跑出来是这样的,可能是把a3 = z3写成了a3 = sigmoid(z3)

转载于:https://www.cnblogs.com/ganganloveu/p/4218111.html

【DeepLearning】Exercise:Learning color features with Sparse Autoencoders相关推荐

  1. UFLDL教程: Exercise:Learning color features with Sparse Autoencoders

    Linear Decoders Deep Learning and Unsupervised Feature Learning Tutorial Solutions 以三层的稀疏编码神经网络而言,在s ...

  2. 深度学习笔记6:Learning color features with Sparse Autoencoders

    线性解码器 动机 当采用稀疏自编码器的输出层采用sigmoid作为激励函数时,要求对输入进行缩放或限制,使其位于[0,1]范围中.但是有些输入值很难满足要求,如PCA白化处理的输入并不满足该范围要求. ...

  3. 【DeepLearning】Exercise:Sparse Autoencoder

    Exercise:Sparse Autoencoder 习题的链接:Exercise:Sparse Autoencoder 注意点: 1.训练样本像素值需要归一化. 因为输出层的激活函数是logist ...

  4. 【学习】Deep Learning for Deepfakes Creation and Detection

    论文题目:Deep Learning for Deepfakes Creation and Detection 翻译:基于深度学习的Deepfake创建与检测 作者: Thanh Thi Nguyen ...

  5. 【翻译】Android Support Library Features(二)

    原文地址:http://developer.android.com/tools/support-library/features.html 在Android Support Library包中,包含了 ...

  6. 【机器学习】Few-shot learning(少样本学习)

    文章目录 少样本学习的诞生 元学习 少样本学习 少样本学习中的相关概念 概念1:Support set VS training set 概念2:Supervised learning VS few-s ...

  7. 【Paper】Deep Learning for Anomaly Detection:A survey

    论文原文:PDF 论文年份:2019 论文被引:253(2020/10/05) 922(2022/03/26) 文章目录 ABSTRACT 1 Introduction 2 What are anom ...

  8. 【Deeplearning】暗影精灵3安装Windows10+Ubuntu18.04双系统及CUDA10.0配置

    一.系统盘制作 官网下载ubuntu18.04镜像,使用Rufus(https://rufus.ie/)制作系统盘 二.Windows准备 磁盘管理-->压缩卷-->重启按ESC进入BIO ...

  9. 【转载】Deep Learning(深度学习)学习笔记整理系列

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0  2013-0 ...

最新文章

  1. DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5
  2. cjson调用的实例 c++
  3. html主题居中用什么命令,html – 如何居中的元素 – 使用什么而不是align:center属性?...
  4. 【JFreeChart】JFreeChart—输出组合图表
  5. rabbitMQ教程 一篇文章看懂rabbitMQ
  6. 使用ubuntu过程中遇到的问题汇总
  7. json web token没有哪个成分_【分享项目】给你看看我们公司的登录认证是怎么做的?!(SpringBoot+Shiro+Token+Redis)...
  8. random模块详解
  9. c语言oj1124,程序设计入门——C语言 第2周编程练习 1时间换算(5分)
  10. 数组-去重、排序方法、json排序
  11. 在没有导师的指导下,研究生如何阅读文献、提出创见、写出论文?
  12. nodejs下载文件
  13. 小韦XPSP3 V10.0_Ghost精简版
  14. mysql gtid 还是pxc_PXC中的GTIDs
  15. Redis 雪崩,穿透,击穿
  16. Docker概述(一)(标贝科技)
  17. vmware 虚拟机安装系统成功,没有虚拟网卡的完美解决方法
  18. 二进制,八进制,十进制,十六进制的详解
  19. 通配符(一般用来查找文件)
  20. 牡丹的冬季修剪及管理方法

热门文章

  1. 配置mysql使其允许外部ip进行登录
  2. Sub-Projects in Xcode(Xcode中的子项目)
  3. python编程口诀_科学网—Python编程技巧汇总 - 高关胤的博文
  4. linux shell 中判断字符串为空的正确方法
  5. sas infile和filename
  6. 隐马尔科夫模型C#语言算法实现
  7. 万字长文:对账系统从入门到精通(建议收藏)
  8. python的matplotlib风格_matplotlib 的几种风格 练习
  9. 订单生产计划表范本_工厂生产管理为什么需要ERP软件?
  10. 国际站html代码,国际站必须看得懂的HTML代码