【转帖】【面向代码】学习 Deep Learning(四) Stacked Auto-Encoders(SAE)

今天介绍的呢是DL另一个非常重要的模型:SAE

把这个放在最后来说呢,主要是因为在UFLDL tutorial 里已经介绍得比较详细了,二来代码非常简单(在NN的基础之上)

先放一张autoencoder的基本结构:

基本意思就是一个隐藏层的神经网络,输入输出都是x,属于无监督学习

==========================================================================================

基本代码

saesetup.m

[cpp] view plaincopyprint?

  1. function sae = saesetup(size)
  2. for u = 2 : numel(size)
  3. sae.ae{u-1} = nnsetup([size(u-1) size(u) size(u-1)]);
  4. end
  5. end
function sae = saesetup(size)
    for u = 2 : numel(size)
        sae.ae{u-1} = nnsetup([size(u-1) size(u) size(u-1)]);
    end
end

saetrain.m

[cpp] view plaincopyprint?

  1. function sae = saetrain(sae, x, opts)
  2. for i = 1 : numel(sae.ae);
  3. disp([‘Training AE ‘ num2str(i) ‘/‘ num2str(numel(sae.ae))]);
  4. sae.ae{i} = nntrain(sae.ae{i}, x, x, opts);
  5. t = nnff(sae.ae{i}, x, x);
  6. x = t.a{2};
  7. %remove bias term
  8. x = x(:,2:end);
  9. end
  10. end
function sae = saetrain(sae, x, opts)
    for i = 1 : numel(sae.ae);
        disp([‘Training AE ‘ num2str(i) ‘/‘ num2str(numel(sae.ae))]);
        sae.ae{i} = nntrain(sae.ae{i}, x, x, opts);
        t = nnff(sae.ae{i}, x, x);
        x = t.a{2};
        %remove bias term
        x = x(:,2:end);
    end
end

其实就是每一层一个autoencoder,隐藏层的值作为下一层的输入

各类变形

为了不致于本文内容太少。。。现在单独把它的几个变形提出来说说

sparse autoencoder:

这就是ufldl讲的版本,toolbox中的代码和ufldl中练习的部分基本一致:

在nnff.m中使用:nn.p{i} = 0.99 * nn.p{i} + 0.01 * mean(nn.a{i}, 1);计算

在nnbp.m中使用

pi = repmat(nn.p{i}, size(nn.a{i}, 1), 1);

sparsityError = [zeros(size(nn.a{i},1),1) nn.nonSparsityPenalty * (-nn.sparsityTarget ./ pi + (1 - nn.sparsityTarget) ./ (1 - pi))];

计算sparsityError即可

denoising autoencoder:

denoising其实就是在autoencoder的基础上,给输入的x加入噪声,就相当于dropout用在输入层

toolbox中的也实现非常简单:

在nntrain.m中:

batch_x = batch_x.*(rand(size(batch_x))>nn.inputZeroMaskedFraction)

也就是随即把大小为(nn.inputZeroMaskedFraction)的一部分x赋成0,denoising autoencoder的表现好像比sparse autoencoder要强一些

Contractive Auto-Encoders:

这个变形呢是《Contractive auto-encoders: Explicit invariance during feature extraction》提出的

这篇论文里也总结了一下autoencoder,感觉很不错

Contractive autoencoders的模型是:

其中:

 hj是表示hidden layer的函数,用它对x求导

论文里说:这个项是

encourages the mapping to the feature space to be contractive in the neighborhood of the training data

具体的实现呢是:

代码呢参看:论文作者提供的:点击打开链接

主要是

jacobian(self,x):

_jacobi_loss():

_fit_reconstruction():

这几个函数和autoencoder有出入,其实也比较简单,就不细讲了

总结:

总的来说,autoencoder感觉是DL中比较好理解的一部分,所以介绍内容不长

可能你也发现了,Toolbox里还有一个文件夹叫CAE,不过这个CAE是Convolutional Auto-Encoders

参考http://www.idsia.ch/~ciresan/data/icann2011.pdf,以后有时间再学习一下~

时间: 2024-08-08 14:46:38

【转帖】【面向代码】学习 Deep Learning(四) Stacked Auto-Encoders(SAE)的相关文章

【深度学习Deep Learning】资料大全

转载:http://www.cnblogs.com/charlotte77/p/5485438.html 最近在学深度学习相关的东西,在网上搜集到了一些不错的资料,现在汇总一下: Free Online Books Deep Learning66 by Yoshua Bengio, Ian Goodfellow and Aaron Courville Neural Networks and Deep Learning42 by Michael Nielsen Deep Learning27 by

机器学习(Machine Learning)&深度学习(Deep Learning)资料

机器学习(Machine Learning)&深度学习(Deep Learning)资料 機器學習.深度學習方面不錯的資料,轉載. 原作:https://github.com/ty4z2008/Qix/blob/master/dl.md 原作作者會不斷更新.本文更新至2014-12-21 <Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍非常全面.从感知机.神经网络.决策树.SVM.Adaboost到随机森林.Deep L

机器学习(Machine Learning)&amp;深度学习(Deep Learning)资料

机器学习(Machine Learning)&深度学习(Deep Learning)资料 <Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost到随机森林.Deep Learning. <Deep Learning in Neural Networks: An Overview> 介绍:这是瑞士人工智能实验室Jurgen Schmidhuber写的最新版本

【转载】浅谈深度学习(Deep Learning)的基本思想和方法

浅谈深度学习(Deep Learning)的基本思想和方法 分类: 机器学习 信息抽取 Deep Learning2013-01-07 22:18 25010人阅读 评论(11) 收藏 举报 深度学习(Deep Learning),又叫Unsupervised Feature Learning或者Feature Learning,是目前非常热的一个研究主题. 本文将主要介绍Deep Learning的基本思想和常用的方法. 一. 什么是Deep Learning? 实际生活中,人们为了解决一个问

【转载】机器学习——深度学习(Deep Learning)

机器学习——深度学习(Deep Learning) 分类: Machine Learning2012-08-04 09:49 142028人阅读 评论(70) 收藏 举报 algorithmclassificationfeaturesfunctionhierarchy Deep Learning是机器学习中一个非常接近AI的领域,其动机在于建立.模拟人脑进行分析学习的神经网络,最近研究了机器学习中一些深度学习的相关知识,本文给出一些很有用的资料和心得. Key Words:有监督学习与无监督学习

机器学习——深度学习(Deep Learning)

Deep Learning是机器学习中一个非常接近AI的领域,其动机在于建立.模拟人脑进行分析学习的神经网络,最近研究了机器学习中一些深度学习的相关知识,本文给出一些很有用的资料和心得. Key Words:有监督学习与无监督学习,分类.回归,密度估计.聚类,深度学习,Sparse DBN, 1. 有监督学习和无监督学习 给定一组数据(input,target)为Z=(X,Y). 有监督学习:最常见的是regression & classification. regression:Y是实数vec

【转帖】【面向代码】学习 Deep Learning(一)Neural Network

最近一直在看Deep Learning,各类博客.论文看得不少 但是说实话,这样做有些疏于实现,一来呢自己的电脑也不是很好,二来呢我目前也没能力自己去写一个toolbox 只是跟着Andrew Ng的UFLDL tutorial 写了些已有框架的代码(这部分的代码见github) 后来发现了一个matlab的Deep Learning的toolbox,发现其代码很简单,感觉比较适合用来学习算法 再一个就是matlab的实现可以省略掉很多数据结构的代码,使算法思路非常清晰 所以我想在解读这个too

【转帖】【面向代码】学习 Deep Learning(三)Convolution Neural Network(CNN)

今天是CNN的内容啦,CNN讲起来有些纠结,你可以事先看看convolution和pooling(subsampling),还有这篇:tornadomeet的博文 下面是那张经典的图: ====================================================================================================== 打开\tests\test_example_CNN.m一观 [cpp] view plaincopyprin

机器学习(Machine Learning)&amp;深入学习(Deep Learning)资料

<Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost 到随机森林.Deep Learning. <Deep Learning in Neural Networks: An Overview> 介绍:这是瑞士人工智能实验室 Jurgen Schmidhuber 写的最新版本<神经网络与深度学习综述>本综述的特点是以时间排序,从 1940 年开始讲起,到

深度学习 Deep Learning UFLDL 最新 Tutorial 学习笔记 1:Linear Regression

1 前言 Andrew Ng的UFLDL在2014年9月底更新了! 对于开始研究Deep Learning的童鞋们来说这真的是极大的好消息! 新的Tutorial相比旧的Tutorial增加了Convolutional Neural Network的内容,了解的童鞋都知道CNN在Computer Vision的重大影响.并且从新编排了内容及exercises. 新的UFLDL网址为: http://ufldl.stanford.edu/tutorial/ 2 Linear Regression