GALAHAD GLRT package#
purpose#
The glrt
package uses a Krylov-subspace iteration to find an
approximation of the global minimizer of
regularized quadratic objective function.
The aim is to minimize the regularized quadratic objective function
See Section 4 of $GALAHAD/doc/glrt.pdf for additional details.
method#
The required solution \(x\) necessarily satisfies the optimality condition \(H x + \lambda M x + g = 0\), where \(\lambda = \sigma \|x\|_{M}^{p-2}\). In addition, the matrix \(H + \lambda M\) will be positive semi-definite.
The method is iterative. Starting with the vector \(M^{-1} g\), a matrix of Lanczos vectors is built one column at a time so that the \(k\)-th column is generated during iteration \(k\). These columns span a so-called Krylov space. The resulting \(n\) by \(k\) matrix \(Q_k \) has the property that \(Q_{k}^T H Q_k^{} = T_{k}^{}\), where \(T_k\) is tridiagonal. An approximation to the required solution may then be expressed formally as
To minimize (1), the optimality conditions
It is possible to measure the optimality measure \(\|H x + \lambda M x + g\|_{M^{-1}}\) without computing \(x_{k+1}\), and thus without needing \(Q_k \). Once this measure is sufficiently small, a second pass is required to obtain the estimate \(x_{k+1} \) from \(y_k \). As this second pass is an additional expense, a record is kept of the optimal objective function values for each value of \(k\), and the second pass is only performed so far as to ensure a given fraction of the final optimal objective value. Large savings may be made in the second pass by choosing the required fraction to be significantly smaller than one.
Special code is used in the special case \(p=2\), as in this case a single pass suffices.
reference#
The method is described in detail in
C. Cartis, N. I. M. Gould and Ph. L. Toint, ``Adaptive cubic regularisation methods for unconstrained optimization. Part {I}: motivation, convergence and numerical results’’. Mathematical Programming 127(2) (2011) 245-295.
introduction to function calls#
To solve a given problem, functions from the glrt package must be called in the following order:
glrt_initialize - provide default control parameters and set up initial data structures
glrt_read_specfile (optional) - override control values by reading replacement values from a file
glrt_import_control - import control parameters prior to solution
glrt_solve_problem - solve the problem by reverse communication, a sequence of calls are made under control of a status parameter, each exit either asks the user to provide additional informaton and to re-enter, or reports that either the solution has been found or that an error has occurred
glrt_information (optional) - recover information about the solution and solution process
glrt_terminate - deallocate data structures
See the examples section for illustrations of use.
callable functions#
overview of functions provided#
// typedefs typedef float spc_; typedef double rpc_; typedef int ipc_; // structs struct glrt_control_type; struct glrt_inform_type; // global functions void glrt_initialize( void **data, struct glrt_control_type* control, ipc_ *status ); void glrt_read_specfile( struct glrt_control_type* control, const char specfile[] ); void glrt_import_control( struct glrt_control_type* control, void **data, ipc_ *status ); void glrt_solve_problem( void **data, ipc_ *status, ipc_ n, const rpc_ power, const rpc_ weight, rpc_ x[], rpc_ r[], rpc_ vector[] ); void glrt_information(void **data, struct glrt_inform_type* inform, ipc_ *status); void glrt_terminate( void **data, struct glrt_control_type* control, struct glrt_inform_type* inform );
typedefs#
typedef float spc_
spc_
is real single precision
typedef double rpc_
rpc_
is the real working precision used, but may be changed to float
by
defining the preprocessor variable SINGLE
.
typedef int ipc_
ipc_
is the default integer word length used, but may be changed to
int64_t
by defining the preprocessor variable INTEGER_64
.
function calls#
void glrt_initialize( void **data, struct glrt_control_type* control, ipc_ *status )
Set default control values and initialize private data
Parameters:
data |
holds private internal data |
control |
is a struct containing control information (see glrt_control_type) |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are (currently):
|
void glrt_read_specfile( struct glrt_control_type* control, const char specfile[] )
Read the content of a specification file, and assign values associated with given keywords to the corresponding control parameters. An in-depth discussion of specification files is available, and a detailed list of keywords with associated default values is provided in $GALAHAD/src/glrt/GLRT.template. See also Table 2.1 in the Fortran documentation provided in $GALAHAD/doc/glrt.pdf for a list of how these keywords relate to the components of the control structure.
Parameters:
control |
is a struct containing control information (see glrt_control_type) |
specfile |
is a character string containing the name of the specification file |
void glrt_import_control( struct glrt_control_type* control, void **data, ipc_ *status )
Import control parameters prior to solution.
Parameters:
control |
is a struct whose members provide control paramters for the remaining prcedures (see glrt_control_type) |
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are (currently):
|
void glrt_solve_problem( void **data, ipc_ *status, ipc_ n, const rpc_ power, const rpc_ weight, rpc_ x[], rpc_ r[], rpc_ vector[] )
Solve the regularized-quadratic problem using reverse communication.
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the entry and exit status from the package. This must be set to
Possible exit values are:
|
n |
is a scalar variable of type ipc_, that holds the number of variables |
power |
is a scalar of type rpc_, that holds the egularization power, \(p \geq 2\) |
weight |
is a scalar of type rpc_, that holds the positive regularization weight, \(\sigma\) |
x |
is a one-dimensional array of size n and type rpc_, that holds the solution \(x\). The j-th component of x, j = 0, … , n-1, contains \(x_j\). |
r |
is a one-dimensional array of size n and type rpc_, that that must be set to \(c\) on entry (status = 1) and re-entry (status = 4, 5). On exit, r contains the resiual \(H x + c\). |
vector |
is a one-dimensional array of size n and type rpc_, that should be used and reset appropriately when status = 2 and 3 as directed. |
void glrt_information(void **data, struct glrt_inform_type* inform, ipc_ *status)
Provides output information
Parameters:
data |
holds private internal data |
inform |
is a struct containing output information (see glrt_inform_type) |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are (currently):
|
void glrt_terminate( void **data, struct glrt_control_type* control, struct glrt_inform_type* inform )
Deallocate all internal private storage
Parameters:
data |
holds private internal data |
control |
is a struct containing control information (see glrt_control_type) |
inform |
is a struct containing output information (see glrt_inform_type) |
available structures#
glrt_control_type structure#
#include <galahad_glrt.h> struct glrt_control_type { // fields bool f_indexing; ipc_ error; ipc_ out; ipc_ print_level; ipc_ itmax; ipc_ stopping_rule; ipc_ freq; ipc_ extra_vectors; ipc_ ritz_printout_device; rpc_ stop_relative; rpc_ stop_absolute; rpc_ fraction_opt; rpc_ rminvr_zero; rpc_ f_0; bool unitm; bool impose_descent; bool space_critical; bool deallocate_error_fatal; bool print_ritz_values; char ritz_file_name[31]; char prefix[31]; };
detailed documentation#
control derived type as a C struct
components#
bool f_indexing
use C or Fortran sparse matrix indexing
ipc_ error
error and warning diagnostics occur on stream error
ipc_ out
general output occurs on stream out
ipc_ print_level
the level of output required is specified by print_level
ipc_ itmax
the maximum number of iterations allowed (-ve = no bound)
ipc_ stopping_rule
the stopping rule used (see below). Possible values are:
1 stopping rule = norm of the step.
2 stopping rule is norm of the step / \(\sigma\).
other. stopping rule = 1.0.
ipc_ freq
frequency for solving the reduced tri-diagonal problem
ipc_ extra_vectors
the number of extra work vectors of length n used
ipc_ ritz_printout_device
the unit number for writing debug Ritz values
rpc_ stop_relative
the iteration stops successfully when the gradient in the \(M^{-1}\) norm is smaller than max( stop_relative \* min( 1, stopping_rule ) \* norm initial gradient, stop_absolute )
rpc_ stop_absolute
see stop_relative
rpc_ fraction_opt
an estimate of the solution that gives at least .fraction_opt times the optimal objective value will be found
rpc_ rminvr_zero
the smallest value that the square of the M norm of the gradient of the objective may be before it is considered to be zero
rpc_ f_0
the constant term, f0, in the objective function
bool unitm
is M the identity matrix ?
bool impose_descent
is descent required i.e., should \(c^T x < 0\)?
bool space_critical
if .space_critical true, every effort will be made to use as little space as possible. This may result in longer computation time
bool deallocate_error_fatal
if .deallocate_error_fatal is true, any array/pointer deallocation error will terminate execution. Otherwise, computation will continue
bool print_ritz_values
should the Ritz values be written to the debug stream?
char ritz_file_name[31]
name of debug file containing the Ritz values
char prefix[31]
all output lines will be prefixed by .prefix(2:LEN(TRIM(.prefix))-1) where .prefix contains the required string enclosed in quotes, e.g. “string” or ‘string’
glrt_inform_type structure#
#include <galahad_glrt.h> struct glrt_inform_type { // fields ipc_ status; ipc_ alloc_status; char bad_alloc[81]; ipc_ iter; ipc_ iter_pass2; rpc_ obj; rpc_ obj_regularized; rpc_ multiplier; rpc_ xpo_norm; rpc_ leftmost; bool negative_curvature; bool hard_case; };
detailed documentation#
inform derived type as a C struct
components#
ipc_ status
return status. See glrt_solve_problem for details
ipc_ alloc_status
the status of the last attempted allocation/deallocation
char bad_alloc[81]
the name of the array for which an allocation/deallocation error occurred
ipc_ iter
the total number of iterations required
ipc_ iter_pass2
the total number of pass-2 iterations required
rpc_ obj
the value of the quadratic function
rpc_ obj_regularized
the value of the regularized quadratic function
rpc_ multiplier
the multiplier, \(\sigma \|x\|^{p-2}\)
rpc_ xpo_norm
the value of the norm \(\|x\|_M\)
rpc_ leftmost
an estimate of the leftmost generalized eigenvalue of the pencil \((H,M)\)
bool negative_curvature
was negative curvature encountered ?
bool hard_case
did the hard case occur ?
example calls#
This is an example of how to use the package to solve a regularization subproblem; the code is available in $GALAHAD/src/glrt/C/glrtt.c .
The floating-point type rpc_
is set in galahad_precision.h
to double
by default, but to float
if the preprocessor variable SINGLE
is defined. Similarly, the integer
type ipc_
from galahad_precision.h
is set to int
by default,
but to int64_t
if the preprocessor variable INTEGER_64
is defined.
/* glrtt.c */
/* Full test for the GLRT C interface */
#include <stdio.h>
#include <math.h>
#include "galahad_precision.h"
#include "galahad_cfunctions.h"
#include "galahad_glrt.h"
int main(void) {
// Derived types
void *data;
struct glrt_control_type control;
struct glrt_inform_type inform;
// Set problem data
ipc_ n = 100; // dimension
ipc_ status;
rpc_ weight;
rpc_ power = 3.0;
rpc_ x[n];
rpc_ r[n];
rpc_ vector[n];
rpc_ h_vector[n];
// Initialize glrt
glrt_initialize( &data, &control, &status );
// use a unit M ?
for( ipc_ unit_m=0; unit_m <= 1; unit_m++){
if ( unit_m == 0 ){
control.unitm = false;
} else {
control.unitm = true;
}
glrt_import_control( &control, &data, &status );
// resolve with a larger weight ?
for( ipc_ new_weight=0; new_weight <= 1; new_weight++){
if ( new_weight == 0 ){
weight = 1.0;
status = 1;
} else {
weight = 10.0;
status = 6;
}
for( ipc_ i = 0; i < n; i++) r[i] = 1.0;
// iteration loop to find the minimizer
while(true){ // reverse-communication loop
glrt_solve_problem( &data, &status, n, power, weight, x, r, vector );
if ( status == 0 ) { // successful termination
break;
} else if ( status < 0 ) { // error exit
break;
} else if ( status == 2 ) { // form the preconditioned vector
for( ipc_ i = 0; i < n; i++) vector[i] = vector[i] / 2.0;
} else if ( status == 3 ) { // form the Hessian-vector product
h_vector[0] = 2.0 * vector[0] + vector[1];
for( ipc_ i = 1; i < n-1; i++){
h_vector[i] = vector[i-1] + 2.0 * vector[i] + vector[i+1];
}
h_vector[n-1] = vector[n-2] + 2.0 * vector[n-1];
for( ipc_ i = 0; i < n; i++) vector[i] = h_vector[i];
} else if ( status == 4 ) { // restart
for( ipc_ i = 0; i < n; i++) r[i] = 1.0;
}else{
printf(" the value %1" i_ipc_ " of status should not occur\n",
status);
break;
}
}
glrt_information( &data, &inform, &status );
printf("MR = %1" i_ipc_ "%1" i_ipc_
" glrt_solve_problem exit status = %" i_ipc_ ", f = %.2f\n",
unit_m, new_weight, inform.status, inform.obj_regularized );
}
}
// Delete internal workspace
glrt_terminate( &data, &control, &inform );
}