-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlbfgsFunc.m
executable file
·23 lines (20 loc) · 1.01 KB
/
lbfgsFunc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function [opttheta, cost] = lbfgsFunc (visibleSize, hiddenSize, lambda, data, theta)
% Calls L-BFGS algorithm to minimize a function
% Randomly initialize the parameters if not specified
if nargin < 5
theta = initializeParameters(hiddenSize, visibleSize);
end
% Use minFunc to minimize the function
addpath minFunc/
options.Method = 'lbfgs'; % Here, we use L-BFGS to optimize our cost
% function. Generally, for minFunc to work, you
% need a function pointer with two outputs: the
% function value and the gradient. In our problem,
% sparseAutoencoderCost.m satisfies this.
options.maxIter = 400; % Maximum number of iterations of L-BFGS to run
options.display = 'off';
[opttheta, cost] = minFunc( @(p) autoencoderCost(p, ...
visibleSize, hiddenSize, ...
lambda, data), ...
theta, options);
end