这一节其实很简单,所谓线性解码器,就是将输出层的激活函数换成了线性函数,其他的没有变。
输出层用线性函数替代sigmoid函数的目的是使输出不再受限在[0,1]范围内。
数据集采用STL-10 彩色图像,但是是8×8的patches,不是原始的64×64图像。
导入数据集:load stlSampledPatches.得到矩阵patches, 192*100000,192=8*8*3
后面在卷积和池化中会用原始的64×64的STL-10图像作为输入。
inputSize = 8×8×3 = 192; 3个通道的颜色。
隐藏层的节点数400,lambda = 3e-3,beta = 5,sparsity = 0.035,这里对输入数据进行预处理,使用ZCA白化,对应的参数epsilon = 0.1;
STEP 1: Create and modify sparseAutoencoderLinearCost.m to use a linear decoder,
这一步借助前面的 sparseAutoencoderCost.m ,更改最后一层的激活函数。andrew ng有一个习惯很好,每一步及时验证保证正确性,这一步同样还是利用数值计算检查梯度计算是否正确,而且设置了debug时的输入层和隐藏层节点数(8,5),保证debug时候速度很快。
下面的代码与sparseAutoencoderCost.m基本一样,只是改了2行语句,我用%@@注释了。
function [cost,grad] = 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 --------------------
% visibleSize: the number of input units (probably 64)
% hiddenSize: the number of hidden units (probably 25)
% lambda: weight decay parameter
% sparsityParam: The desired average activation for the hidden units (denoted in