Dropout是指在模型训练时随机让网络某些隐含层节点的权重不工作,不工作的那些节点可以暂时认为不是网络结构的一部分,但是它的权重得保留下来(只是暂时不更新而已),因为下次样本输入时它可能又得工作了。
训练神经网络模型时,如果训练样本较少,为了防止模型过拟合,Dropout可以作为一种trikc供选择。Dropout是hintion最近2年提出的,源于其文章Improving neural networks by preventing co-adaptation of feature detectors.中文大意为:通过阻止特征检测器的共同作用来提高神经网络的性能。
Denoise Autoencoder(简称dAE)是指当采用无监督的方法分层预训练深度网络的权值时,为了学习到较鲁棒的特征,可以在网络的可视层(即数据的输入层)引入随机噪声,这里并不是加入高斯噪声,而是以一定概率使输入层节点的值清为0。这种方法由Bengio在08年提出,见其文章Extracting and composing robust features with denoising autoencoders.使用dAE时,可以用被破坏的输入数据重构出原始的没被破坏的数据,所以它训练出来的特征会更鲁棒。
Bengio对dAE的直观解释为:1.dAE有点类似人体的感官系统,比如人眼看物体时,如果物体某一小部分被遮住了,人依然能够将其识别出来,2.多模态信息输入人体时(比如声音,图像等),少了其中某些模态的信息有时影响也不大。3.普通的autoencoder的本质是学习一个相等函数,即输入和重构后的输出相等,这种相等函数的表示有个缺点就是当测试样本和训练样本不符合同一分布,即相差较大时,效果不好,明显,dAE在这方面的处理有所进步。
当在训练深度网络时,且采用了无监督方法预训练权值,通常,Dropout和Denoise Autoencoder在使用时有一个小地方不同:Dropout在分层预训练权值的过程中是不参与的,只是后面的微调部分引入;而Denoise Autoencoder是在每层预训练的过程中作为输入层被引入,在进行微调时不参与。另外,一般的重构误差可以采用均方误差的形式,但是如果输入和输出的向量元素都是位变量,则一般采用交叉熵来表示两者的差异。
test_example_SAE.m
function test_example_SAE
sae = saesetup([327 200 20]);%1*2cell,[327 200 327]和[200 20 200]两个神经网络
sae.ae{
1}.activation_function = 'sigm';%只改变第一个神经网络的参数
sae.ae{
1}.learningRate = 1;
sae.ae{
1}.inputZeroMaskedFraction = 0.5;
opts.numepochs = 1;
opts.batchsize = 100;
[reducedim_x,sae] = saetrain(sae, X, opts);%reducedim_x是降维后的20维的训练样本
saesetup.m
function sae = saesetup(size)%[327 200 20]
for u = 2 : numel(size)%3
sae.ae{u-1} = nnsetup([size(u-1) size(u) size(u-1)]);%sae.ae{1} = nnsetup([327 200 327]);以此为例注释
%sae.ae{2} = nnsetup([200 20 200]);
end
end
nnsetup.m
function nn = nnsetup(architecture)
%NNSETUP creates a Feedforward Backpropagate Neural Network
% nn = nnsetup(architecture) returns an neural network structure with n=numel(architecture)
% layers, architecture being a 1 x n vector of layer sizes e.g. [784 100 10]
nn.size = architecture;%构建神经网络[327 200 327]
nn.n = numel(nn.size);%n=3
nn.activation_function = 'tanh_opt'; % Activation functions of hidden layers: 'sigm' (sigmoid) or 'tanh_opt' (optimal tanh).
nn.learningRate = 2; % learning rate Note: typically needs to be lower when using 'sigm' activation function and non-normalized inputs.
nn.momentum = 0.5; % Momentum
nn.scaling_learningRate = 1; % 学习率的收缩因子;Scaling factor for the learning rate (each epoch)
nn.weightPenaltyL2 = 0; % W的L2规则项的系数;L2 regularization
nn.nonSparsityPenalty = 0; % 稀疏惩罚项的系数;Non sparsity penalty
nn.sparsityTarget = 0.05; % 稀疏因数(Sparse AE)Sparsity target
nn.inputZeroMaskedFraction = 0; % Used for Denoising AutoEncoders
nn.dropoutFraction = 0; % Dropout level (http://www.cs.toronto.edu/~hinton/absps/dropout.pdf)
nn.testing = 0; % Internal variable. nntest sets this to one.
nn.output = 'sigm'; % output unit 'sigm' (=logistic), 'softmax' and 'linear'
for i = 2 : nn.n
% weights and weight momentum
nn.W