Autoencoder与RBM结合使用

AutoEncoder是多层神经网络,其中输入层和输出层表示相同的含义,具有相同的节点数。AutoEncode学习的是一个输入输出相同的“恒等函数”。不过输入和输出相同,使得这个网络的输出没有任何意义。AutoEncoder的意义在于学习的(通常是节点数更少的)中间coder层(最中间的那一层),这一层是输入向量的良好表示。这个过程起到了“降维”的作用。当AutoEncoder只有一个隐含层的时候,其原理相当于主成分分析(PCA),当AutoEncoder有多个隐含层的时候,每两层之间可以用RBM来pre-training,最后由BP来调整最终权值。网络权重更新公式很容易用求偏导数的方法推导出来,算法是梯度下降法。(RBM:层内无连接,层间全连接,二分图)

Denoising AutoEncoder是AutoEncoder的一个变种,与AutoEncoder不同的是,Denoising AutoEncoder在输入的过程中加入了噪声信息,从而让AutoEncoder能够学习这种噪声。

Denoising AutoEncoder与RBM非常像:
(1)参数一样:隐含层偏置、显示层偏置、网络权重
(2)作用一样:都是输入的另一种(压缩)表示
(3)过程类似:都有reconstruct,并且都是reconstruct与input的差别,越小越好

Denoising AutoEncoder与RBM的区别:
背后原理就不说了(RBM是能量函数),区别在于训练准则。RBM是隐含层“产生”显示层的概率(通常用log表示),Denoising AutoEncoder是输入分布与reconstruct分布的KL距离。所用的训练方法,前者是CD-k,后者是梯度下降。RBM固定只有两层;AutoEncoder,可以有多层,并且这些多层网络可以由标准的bp算法来更新网络权重和偏置,与标准神经网络不同的是,AutoEncoder的输入层和最终的输出层是“同一层”,不仅仅是节点数目、输出相同,而是完完全全的“同一层”,这也会影响到这一层相关的权值更新方式。总之,输入与输出是同一层,在此基础上,再由输入与输出的差别构造准则函数,再求各个参数的偏导数,再用bp方式更新各个权重。

【AutoEncoder工程代码】:相关Matlab工程代码主页:http://www.cs.toronto.edu/~hinton/MatlabForSciencePaper.html

论文:Science – 2006 Science_Reducing the Dimensionality of Data with Neural Networks

(如下所有文件,放到同一个目录下)

1). 下载手写体数据MNIST: http://yann.lecun.com/exdb/mnist/, 并在Linux或Windows下进行解压;(60,000 个训练集 和, 10,000 个测试集,数字手写体0-9 10类)
train-images-idx3-ubyte.gz: training set images (9912422 bytes)
train-labels-idx1-ubyte.gz: training set labels (28881 bytes)
t10k-images-idx3-ubyte.gz: test set images (1648877 bytes)
t10k-labels-idx1-ubyte.gz: test set labels (4542 bytes)

2). 下载共轭梯度代码:http://learning.eng.cam.ac.uk/carl/code/minimize/minimize.m

3). 下载AutoEncoder代码,包括如下13个Matlab文件:
mnistdeepauto.m //训练AutoEncoder的主文件;
mnistclassify.m //用于训练分类器的主文件;
converter.m //转换MNIST文件为Matlab数据格式;
rbm.m //训练RBM二进制隐层和二进制可视单元;
rbmhidlinear.m //训练RBM高斯隐层和二进制可视单元;
backprop.m //进行fine-tuning的反向传播代码;
backpropclassify.m //利用“Encoder”网络进行分类的反向传播;
CG_MNIST.m //Conjugate Gradient optimization for fine-tuning an autoencoder
CG_CLASSIFY_INIT.m //Conjugate Gradient optimization for classification (training top-layer weights while holding low-level weights fixed)
CG_CLASSIFY.m //Conjugate Gradient optimization for classification (training all weights)
makebatches.m //Creates minibatches for RBM training
mnistdisp.m //显示fine-tuning阶段的进度;
README.txt //说明文件

4). 在Matlab中执行mnistdeepauto.m文件训练autoencoder;我们看一下此文件中大致做了一些什么操作:

maxepoch=10; //RBM学习时的迭代次数
numhid=1000; numpen=500; numpen2=250; numopen=30; //设置各个隐藏层的神经元的个数;这个程序所采用的网络共有四层。【1000 500 250 30】
converter; \\作者提供的二进制数据需要将原始数据文件转换成Matlab数据格式
makebatches; \\把大的数据块拆成每块100个样本的小块 batchdata [样本数,维数,分块数]
//开始四层RBM训练
rbm; \\迭代学习,分别学习到4个RBM模型,mnisthp.mat, mnisthp2.mat, mnistpo.mat, mnistvh.mat记录了RBM学习到的模型(3个参数:权重矩阵W,前向偏移量b,后向偏移量c)
这里有一个问题,就是W,叫做链接权重矩阵可能更合适一点,如果叫做转移矩阵的话,一个问题就是,为什么P(v=1|h)=sigmod(c+Wv), 而P(h=1|v)=sigmod(b+W’h),这里W是用的转置而不是W的逆?因为直观上会有一个问题就是说 y=Wx的话,那么就应该有x=inv(W)y,但是这里确只是用一个转置,而且正交矩阵才具有此性质,W’=inv(W). 而其实 这个是RBM 能量函数的性质,在RBM能量函数中 v和h 有种伪对阵性,上述两式是在能量函数基础上计算条件概率得到的。
backprop; \\反向传播的训练速度好慢啊。==b,迭代200次估计需要1天多,我们直接迭代1次跑个demo,最终反向传播之后可以学习到 w1,w2,w3,w4四个编码权重矩阵及w5,w6,w7,w8四个解码权重矩阵。

5). 若执行mnistclassify.m可训练MNIST分类器

6). 代码中有很多参数可以进行调节You can also set various parameters in the code, such as maximum number of epochs, learning rates, network architecture, etc.

Q:DAE 比DBN 好?

【参考】:
1. http://blog.csdn.net/xceman1997/article/details/9392153
2. http://deeplearning.net/
3. http://www.cs.toronto.edu/~hinton/MatlabForSciencePaper.html
4. DeepLearning 工具包汇总 http://blog.csdn.net/zouxy09/article/details/11910527
5. DeepLearning 工具包Matlab代码集合:https://github.com/rasmusbergpalm/DeepLearnToolbox,是丹麦工业大学以为硕士期间的工作
6. DeepLearning 工具包C, C++, Java, phython, scala代码集合, https://github.com/yusugomori/DeepLearning
7. RBM详解:http://ibillxia.github.io/blog/2013/04/12/Energy-Based-Models-and-Boltzmann-Machines/

【备注源码注释】:http://jacoxu.com/?p=692

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
Code provided by Ruslan Salakhutdinov and Geoff Hinton Permission is granted for anyone to copy, use, modify, or distribute this program and accompanying programs and documents for any purpose, provided this copyright notice is retained and prominently displayed, along with a note saying that the original programs are available from our web page. The programs and documents are distributed without any warranty, express or implied. As the programs were written for research purposes only, they have not been tested to the degree that would be advisable in any important application. All use of these programs is entirely at the user's own risk. How to make it work: 1. Create a separate directory and download all these files into the same directory 2. Download from http://yann.lecun.com/exdb/mnist the following 4 files: o train-images-idx3-ubyte.gz o train-labels-idx1-ubyte.gz o t10k-images-idx3-ubyte.gz o t10k-labels-idx1-ubyte.gz 3. Unzip these 4 files by executing: o gunzip train-images-idx3-ubyte.gz o gunzip train-labels-idx1-ubyte.gz o gunzip t10k-images-idx3-ubyte.gz o gunzip t10k-labels-idx1-ubyte.gz If unzipping with WinZip, make sure the file names have not been changed by Winzip. 4. Download Conjugate Gradient code minimize.m 5. Download Autoencoder_Code.tar which contains 13 files OR download each of the following 13 files separately for training an autoencoder and a classification model: o mnistdeepauto.m Main file for training deep autoencoder o mnistclassify.m Main file for training classification model o converter.m Converts raw MNIST digits into matlab format o rbm.m Training RBM with binary hidden and binary visible units o rbmhidlinear.m Training RBM with Gaussian hidden and binary visible units o backprop.m Backpropagation for fine-tuning an autoencoder o backpropclassify.m Backpropagation for classification using "encoder" network o CG_MNIST.m Conjugate Gradient optimization for fine-tuning an autoencoder o CG_CLASSIFY_INIT.m Co

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值