资源简介
稀疏自编码器的MATLAB代码实现,按照UFLDL教程给出的教程进行补充编写。
代码片段和文件信息
function [] = checkNumericalGradient()
% This code can be used to check your numerical gradient implementation
% in computeNumericalGradient.m
% It analytically evaluates the gradient of a very simple function called
% simpleQuadraticFunction (see below) and compares the result with your numerical
% solution. Your numerical gradient implementation is incorrect if
% your numerical solution deviates too much from the analytical solution.
% Evaluate the function and gradient at x = [4; 10]; (Here x is a 2d vector.)
x = [4; 10];
[value grad] = simpleQuadraticFunction(x);
% Use your code to numerically compute the gradient of simpleQuadraticFunction at x.
% (The notation “@simpleQuadraticFunction“ denotes a pointer to a function.)
numgrad = computeNumericalGradient(@simpleQuadraticFunction x);
% Visually examine the two gradient computations. The two columns
% you get should be very similar.
disp([numgrad grad]);
fprintf(‘The above two columns you get should be very similar.\n(Left-Your Numerical Gradient Right-Analytical Gradient)\n\n‘);
% Evaluate the norm of the difference between two solutions.
% If you have a correct implementation and assuming you used EPSILON = 0.0001
% in computeNumericalGradient.m then diff below should be 2.1452e-12
diff = norm(numgrad-grad)/norm(numgrad+grad);
disp(diff);
fprintf(‘Norm of the difference between numerical and analytical gradient (should be < 1e-9)\n\n‘);
end
function [valuegrad] = simpleQuadraticFunction(x)
% this function accepts a 2D vector as input.
% Its outputs are:
% value: h(x1 x2) = x1^2 + 3*x1*x2
% grad: A 2x1 vector that gives the partial derivatives of h with respect to x1 and x2
% Note that when we pass @simpleQuadraticFunction(x) to computeNumericalGradients we‘re assuming
% that computeNumericalGradients will use only the first returned value of this function.
value = x(1)^2 + 3*x(1)*x(2);
grad = zeros(2 1);
grad(1) = 2*x(1) + 3*x(2);
grad(2) = 3*x(1);
end
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1982 2011-01-05 17:27 starter\checkNumericalGradient.m
文件 1259 2015-05-20 19:00 starter\computeNumericalGradient.m
文件 2647 2011-01-05 01:48 starter\display_network.m
文件 20971720 2011-01-03 21:39 starter\IMAGES.mat
文件 622 2011-01-05 00:13 starter\initializeParameters.m
文件 3251 2011-01-03 21:39 starter\minFunc\ArmijoBacktrack.m
文件 807 2011-01-03 21:39 starter\minFunc\autoGrad.m
文件 901 2011-01-03 21:39 starter\minFunc\autoHess.m
文件 317 2011-01-03 21:39 starter\minFunc\autoHv.m
文件 870 2011-01-03 21:39 starter\minFunc\autoTensor.m
文件 385 2011-01-03 21:39 starter\minFunc\callOutput.m
文件 1845 2011-01-03 21:39 starter\minFunc\conjGrad.m
文件 995 2011-01-03 21:39 starter\minFunc\dampedUpdate.m
文件 2421 2011-01-03 21:39 starter\minFunc\example_minFunc.m
文件 1604 2011-01-03 21:39 starter\minFunc\example_minFunc_LR.m
文件 107 2011-01-03 21:39 starter\minFunc\isLegal.m
文件 924 2011-01-03 21:39 starter\minFunc\lbfgs.m
文件 2408 2011-01-03 21:39 starter\minFunc\lbfgsC.c
文件 7707 2011-01-03 21:39 starter\minFunc\lbfgsC.mexa64
文件 7733 2011-01-03 21:39 starter\minFunc\lbfgsC.mexglx
文件 9500 2011-01-03 21:39 starter\minFunc\lbfgsC.mexmac
文件 12660 2011-01-03 21:39 starter\minFunc\lbfgsC.mexmaci
文件 8800 2011-01-03 21:39 starter\minFunc\lbfgsC.mexmaci64
文件 7168 2011-01-03 21:39 starter\minFunc\lbfgsC.mexw32
文件 9728 2011-01-03 21:39 starter\minFunc\lbfgsC.mexw64
文件 614 2011-01-03 21:39 starter\minFunc\lbfgsUpdate.m
文件 417 2011-01-03 21:39 starter\minFunc\logistic\LogisticDiagPrecond.m
文件 216 2011-01-03 21:39 starter\minFunc\logistic\LogisticHv.m
文件 659 2011-01-03 21:39 starter\minFunc\logistic\LogisticLoss.m
文件 1154 2011-01-03 21:39 starter\minFunc\logistic\mexutil.c
............此处省略31个文件信息
评论
共有 条评论