This file is indexed.

/usr/share/octave/packages/optim-1.3.0/bfgsmin_example.m is in octave-optim 1.3.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
## Copyright (C) 2004,2005,2006 Michael Creel <michael.creel@uab.es>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.

# usage: bfgsmin_example (to run) or edit bfgsmin_example (to examine)
##
# Shows how to call bfgsmin. There are two objective functions, the first
# supplies the analytic gradient, and the second does not. The true minimizer
# is at "location", a 50x1 vector (0.00, 0.02, 0.04 ..., 1.00).
# Note that limited memory bfgs is faster when the dimension is high.
# Also note that supplying analytic derivatives gives a speedup.
##
# Six examples are given:
# Example 1: regular bfgs, analytic gradient
# Example 2: same as Example 1, but verbose
# Example 3: limited memory bfgs, analytic gradient
# Example 4: regular bfgs, numeric gradient
# Example 5: limited memory bfgs, numeric gradient
# Example 6: regular bfgs, analytic gradient, minimize wrt second argument
1;
# example obj. fn.: supplies analytic gradient
function [obj_value, gradient] = objective(theta, location)
	x = theta - location + ones(rows(theta),1); # move minimizer to "location"
	[obj_value, gradient] = rosenbrock(x);
endfunction

# example obj. fn.: no gradient
function obj_value = objective2(theta, location)
	x = theta - location + ones(rows(theta),1); # move minimizer to "location"
	obj_value = rosenbrock(x);
endfunction

# initial values
dim = 20; # dimension of Rosenbrock function
theta0 = zeros(dim+1,1);  # starting values
location = (0:dim)/dim; # true values
location = location';

printf("EXAMPLE 1: Ordinary BFGS, using analytic gradient\n");
t=cputime();
control = {Inf,1};  # maxiters, verbosity
[theta, obj_value, convergence] = bfgsmin("objective", {theta0, location}, control);
fflush(1);
t1 = cputime() - t;
conv = norm(theta-location, 'inf');
test1 = conv < 1e-5;

printf("EXAMPLE 2: Same as Example 1, but verbose\n");
t=cputime();
control = {-1;3};  # maxiters, verbosity
[theta, obj_value, convergence] = bfgsmin("objective", {theta0, location}, control);
fflush(1);
t2 = cputime() - t;
conv = norm(theta-location, 'inf');
test2 = conv < 1e-5;

printf("EXAMPLE 3: Limited memory BFGS, using analytic gradient\n");
t=cputime();
control = {-1;1;1;1;3};  # maxiters, verbosity, conv. requirement., arg_to_min, lbfgs memory
[theta, obj_value, convergence] = bfgsmin("objective", {theta0, location}, control);
fflush(1);
t3 = cputime() - t;
conv = norm(theta-location, 'inf');
test3 = conv < 1e-5;

printf("EXAMPLE 4: Ordinary BFGS, using numeric gradient\n");
t=cputime();
control = {-1;1};  # maxiters, verbosity
[theta, obj_value, convergence] = bfgsmin("objective2", {theta0, location}, control);
fflush(1);
t4 = cputime() - t;
conv = norm(theta-location, 'inf');
test4 = conv < 1e-5;

printf("EXAMPLE 5: Limited memory BFGS, using numeric gradient\n");
t=cputime();
control = {-1;1;1;1;3};  # maxiters, verbosity, conv. reg., arg_to_min, lbfgs memory
[theta, obj_value, convergence] = bfgsmin("objective2", {theta0, location}, control);
fflush(1);
t5 = cputime() - t;
conv = norm(theta-location, 'inf');
test5 = conv < 1e-5;


printf("EXAMPLE 6: Funny case: minimize w.r.t. second argument, Ordinary BFGS, using numeric gradient\n");
t=cputime();
control = {-1;1;1;2};  # maxiters, verbosity, conv. reg., arg_to_min
[theta, obj_value, convergence] = bfgsmin("objective2", {location, theta0}, control);
fflush(1);
t6 = cputime() - t;
conv = norm(theta-location, 'inf');
test6 = conv < 1e-5;

printf("EXAMPLE 7: Ordinary BFGS, using numeric gradient, using non-default tolerances\n");
t=cputime();
control = {-1;1;1;1;0;1e-6;1e-2;1e-2};  # maxiters, verbosity, conv. reg., arg_to_min, lbfgs memory, fun. tol., param. tol., gradient tol.
[theta, obj_value, convergence] = bfgsmin("objective2", {theta0, location}, control);
fflush(1);
t7 = cputime() - t;
conv = norm(theta-location, 'inf');
test7 = conv < 1e-2;


printf("EXAMPLE 1: Ordinary BFGS, using analytic gradient\n");
if test1
	printf("Success!! :-)\n");
else
	printf("Failure?! :-(\n");
endif
printf("Elapsed time = %f\n\n\n\n",t1);

printf("EXAMPLE 2: Same as Example 1, but verbose\n");
if test2
	printf("Success!! :-)\n");
else
	printf("Failure?! :-(\n");
endif
printf("Elapsed time = %f\n\n\n\n",t2);

printf("EXAMPLE 3: Limited memory BFGS, using analytic gradient\n");
if test3
	printf("Success!! :-)\n");
else
	printf("Failure?! :-(\n");
endif
printf("Elapsed time = %f\n\n\n\n",t3);

printf("EXAMPLE 4: Ordinary BFGS, using numeric gradient\n");
if test4
	printf("Success!! :-)\n");
else
	printf("Failure?! :-(\n");
endif
printf("Elapsed time = %f\n\n\n\n",t4);

printf("EXAMPLE 5: Limited memory BFGS, using numeric gradient\n");
if test5
	printf("Success!! :-)\n");
else
	printf("Failure?! :-(\n");
endif
printf("Elapsed time = %f\n\n\n\n",t5);

printf("EXAMPLE 6: Funny case: minimize w.r.t. second argument, Ordinary BFGS, using numeric gradient\n");
if test6
	printf("Success!! :-)\n");
else
	printf("Failure?! :-(\n");
endif
printf("Elapsed time = %f\n\n\n\n",t6);

printf("EXAMPLE 7: Ordinary BFGS, using numeric gradient, using non-default tolerances\n");
if test7
	printf("Success!! :-)\n");
else
	printf("Failure?! :-(\n");
endif
printf("Elapsed time = %f\n\n\n\n",t7);