结合使用稀疏自编码器和Softmax分类器对0到4的手写数字进行分类。首先利用稀疏自编码器无监督学习手写数字5到9的特征。利用学到的权重和偏置计算手写数字0到4的激活值,并将激活值作为Softmax分类器的输入进行分类(有监督学习)。
Train the sparse autoencoder
opttheta = theta;
addpath minFunc/
options.Method = 'lbfgs';
options.maxIter = maxIter;
options.display = 'on';
[opttheta, cost] = minFunc( @(p) sparseAutoencoderCost(p, ...
inputSize, hiddenSize, ...
lambda, sparsityParam, ...
beta, unlabeledData), ...
theta, options);
Extracting features
feedForwardAutoencoder.m
activation = sigmoid(W1*data+repmat(b1,1,size(data,2)));
Train the softmax classifier
lambda = 1e-4;
options.maxIter = 100;
softmaxModel = softmaxTrain(hiddenSize, numLabels, lambda, ...
trainFeatures, trainLabels, options);
Testing
[pred] = softmaxPredict(softmaxModel, testFeatures);