naginterfaces.library.opt.lsq_lincon_solve¶
- naginterfaces.library.opt.lsq_lincon_solve(bl, bu, x, comm, c=None, cvec=None, istate=None, kx=None, a=None, b=None, io_manager=None)[source]¶
lsq_lincon_solve
solves linearly constrained linear least squares problems and convex quadratic programming problems. It is not intended for large sparse problems.Note: this function uses optional algorithmic parameters, see also:
lsq_lincon_option_file()
,lsq_lincon_option_string()
,nlp1_init()
.For full information please refer to the NAG Library document for e04nc
https://support.nag.com/numeric/nl/nagdoc_30.1/flhtml/e04/e04ncf.html
- Parameters
- blfloat, array-like, shape
must contain the lower bounds for all the constraints
- bufloat, array-like, shape
must contain the upper bounds for all the constraints
- xfloat, array-like, shape
An initial estimate of the solution.
Note: that it may be best to avoid the choice .
- commdict, communication object, modified in place
Communication structure.
This argument must have been initialized by a prior call to
nlp1_init()
.- cNone or float, array-like, shape , optional
Note: the required extent for this argument in dimension 2 is determined as follows: if : ; otherwise: .
The th row of must contain the coefficients of the th general constraint, for .
- cvecNone or float, array-like, shape , optional
The coefficients of the explicit linear term of the objective function.
If the problem is of type FP, QP1, QP3, LS1 (the default) or LS3, is not referenced.
- istateNone or int, array-like, shape , optional
Need not be set if the (default) option ‘Cold Start’ is used.
If the option ‘Warm Start’ has been chosen, specifies the desired status of the constraints at the start of the feasibility phase.
More precisely, the first elements of refer to the upper and lower bounds on the variables, and the next elements refer to the general linear constraints (if any).
Possible values for are as follows:
Meaning
0
The constraint should not be in the initial working set.
1
The constraint should be in the initial working set at its lower bound.
2
The constraint should be in the initial working set at its upper bound.
3
The constraint should be in the initial working set as an equality. This value must not be specified unless .
The values , and are also acceptable but will be reset to zero by the function.
If
lsq_lincon_solve
has been called previously with the same values of and , already contains satisfactory information. (See also the description of the option ‘Warm Start’.) The function also adjusts (if necessary) the values supplied in to be consistent with .- kxNone or int, array-like, shape , optional
Need not be initialized for problems of type FP, LP, QP1, QP2, LS1 (the default) or LS2.
For problems QP3, QP4, LS3 or LS4, must specify the order of the columns of the matrix with respect to the ordering of .
Thus if column of is the column associated with the variable then .
- aNone or float, array-like, shape , optional
The matrix .
- bNone or float, array-like, shape , optional
The elements of the vector of observations.
- io_managerFileObjManager, optional
Manager for I/O in this routine.
- Returns
- istateint, ndarray, shape
The status of the constraints in the working set at the point returned in . The significance of each possible value of is as follows:
Meaning
The constraint violates its lower bound by more than the feasibility tolerance.
The constraint violates its upper bound by more than the feasibility tolerance.
The constraint is satisfied to within the feasibility tolerance, but is not in the working set.
This inequality constraint is included in the working set at its lower bound.
This inequality constraint is included in the working set at its upper bound.
The constraint is included in the working set as an equality. This value of can occur only when .
This corresponds to optimality being declared with being temporarily fixed at its current value.
- kxint, ndarray, shape
Defines the order of the columns of with respect to the ordering of , as described above.
- xfloat, ndarray, shape
The point at which
lsq_lincon_solve
terminated. If the function exits successfully or = 1 or 4, contains an estimate of the solution.- afloat, ndarray, shape
The matrix .
- bNone or float, ndarray, shape
The transformed residual vector of (0) (see Main Iteration).
If the problem is of type FP, LP, QP1, QP2, QP3 or QP4, is not referenced.
- iteraint
The total number of iterations performed.
- objfloat
The value of the objective function at if is feasible, or the sum of infeasibiliites at otherwise. If the problem is of type FP and is feasible, is set to zero.
- clamdafloat, ndarray, shape
The values of the Lagrange multipliers for each constraint with respect to the current working set. The first elements contain the multipliers for the bound constraints on the variables, and the next elements contain the multipliers for the general linear constraints (if any). If (i.e., constraint is not in the working set), is zero. If is optimal, should be non-negative if , non-positive if and zero if .
- Other Parameters
- ‘Cold Start’valueless
Default
This option specifies how the initial working set is chosen. With a ‘Cold Start’,
lsq_lincon_solve
chooses the initial working set based on the values of the variables and constraints at the initial point. Broadly speaking, the initial working set will include equality constraints and bounds or inequality constraints that violate or ‘nearly’ satisfy their bounds (to within ‘Crash Tolerance’).With a ‘Warm Start’, you must provide a valid definition of every element of the array .
lsq_lincon_solve
will override your specification of if necessary, so that a poor choice of the working set will not cause a fatal error. For instance, any elements of which are set to , or will be reset to zero, as will any elements which are set to when the corresponding elements of and are not equal. A warm start will be advantageous if a good estimate of the initial working set is available – for example, whenlsq_lincon_solve
is called repeatedly to solve related problems.- ‘Warm Start’valueless
This option specifies how the initial working set is chosen. With a ‘Cold Start’,
lsq_lincon_solve
chooses the initial working set based on the values of the variables and constraints at the initial point. Broadly speaking, the initial working set will include equality constraints and bounds or inequality constraints that violate or ‘nearly’ satisfy their bounds (to within ‘Crash Tolerance’).With a ‘Warm Start’, you must provide a valid definition of every element of the array .
lsq_lincon_solve
will override your specification of if necessary, so that a poor choice of the working set will not cause a fatal error. For instance, any elements of which are set to , or will be reset to zero, as will any elements which are set to when the corresponding elements of and are not equal. A warm start will be advantageous if a good estimate of the initial working set is available – for example, whenlsq_lincon_solve
is called repeatedly to solve related problems.- ‘Crash Tolerance’float
Default
This value is used in conjunction with the option ‘Cold Start’ (the default value) when
lsq_lincon_solve
selects an initial working set. If , the initial working set will include (if possible) bounds or general inequality constraints that lie within of their bounds. In particular, a constraint of the form will be included in the initial working set if . If or , the default value is used.- ‘Defaults’valueless
This special keyword may be used to reset all options to their default values.
- ‘Feasibility Phase Iteration Limit’int
Default
The scalars and specify the maximum number of iterations allowed in the feasibility and optimality phases. Option ‘Optimality Phase Iteration Limit’ is equivalent to option ‘Iteration Limit’. Setting and means that the workspace needed will be computed and printed, but no iterations will be performed. If or , the default value is used.
- ‘Optimality Phase Iteration Limit’int
Default
The scalars and specify the maximum number of iterations allowed in the feasibility and optimality phases. Option ‘Optimality Phase Iteration Limit’ is equivalent to option ‘Iteration Limit’. Setting and means that the workspace needed will be computed and printed, but no iterations will be performed. If or , the default value is used.
- ‘Feasibility Tolerance’float
Default
If , defines the maximum acceptable absolute violation in each constraint at a ‘feasible’ point. For example, if the variables and the coefficients in the general constraints are of order unity, and the latter are correct to about decimal digits, it would be appropriate to specify as . If , the default value is used.
Note that a ‘feasible solution’ is a solution that satisfies the current constraints to within the tolerance .
- ‘Hessian’str
Default
This option controls the contents of the upper triangular matrix (see the description of in Parameters).
lsq_lincon_solve
works exclusively with the transformed and reordered matrix (8), and hence extra computation is required to form the Hessian itself. If , contains the Cholesky factor of the matrix with columns ordered as indicated by (see Parameters). If , contains the Cholesky factor of the matrix , with columns ordered as indicated by .- ‘Infinite Bound Size’float
Default
If , defines the ‘infinite’ bound in the definition of the problem constraints. Any upper bound greater than or equal to will be regarded as (and similarly any lower bound less than or equal to will be regarded as ). If , the default value is used.
- ‘Infinite Step Size’float
Default
If , specifies the magnitude of the change in variables that will be considered a step to an unbounded solution. (Note that an unbounded solution can occur only when the Hessian is singular and the objective contains an explicit linear term.) If the change in during an iteration would exceed the value of , the objective function is considered to be unbounded below in the feasible region. If , the default value is used.
- ‘Iteration Limit’int
Default
See option ‘Feasibility Phase Iteration Limit’.
- ‘Iters’int
Default
See option ‘Feasibility Phase Iteration Limit’.
- ‘Itns’int
Default
See option ‘Feasibility Phase Iteration Limit’.
- ‘List’valueless
Option ‘List’ enables printing of each option specification as it is supplied. ‘Nolist’ suppresses this printing.
- ‘Nolist’valueless
Default
Option ‘List’ enables printing of each option specification as it is supplied. ‘Nolist’ suppresses this printing.
- ‘Monitoring File’int
Default
If and , monitoring information produced by
lsq_lincon_solve
at every iteration is sent to a file with logical unit number . If and/or , no monitoring information is produced.- ‘Print Level’int
Default
The value of controls the amount of printout produced by
lsq_lincon_solve
, as indicated below. A detailed description of the printed output is given in Further Comments (summary output at each iteration and the final solution) and Monitoring Information (monitoring information at each iteration).The following printout is sent to the file object associated with the advisory I/O unit (see
FileObjManager
):Output
No output.
The final solution only.
One line of summary output ( characters; see Further Comments) for each iteration (no printout of the final solution).
The final solution and one line of summary output for each iteration.
The following printout is sent to the unit number given by the option ‘Monitoring File’:
Output
No output.
One long line of output ( characters; see Monitoring Information) for each iteration (no printout of the final solution).
At each iteration, the Lagrange multipliers, the variables , the constraint values and the constraint status.
At each iteration, the diagonal elements of the matrix associated with the factorization (4) (see Definition of Search Direction) of the working set, and the diagonal elements of the upper triangular matrix .
If and the unit number defined by the option ‘Monitoring File’ is the advisory unit number, the summary output for each major iteration is suppressed.
- ‘Problem Type’str
Default LS1
This option specifies the type of objective function to be minimized during the optimality phase. The following are the nine optional keywords and the dimensions of the arrays that must be specified in order to define the objective function:
LP
and not referenced, length- ;
QP1
shape- symmetric, and not referenced;
QP2
shape- symmetric, not referenced, length- ;
QP3
shape- upper trapezoidal, length- , and not referenced;
QP4
shape- upper trapezoidal, length- , not referenced, length- ;
LS1
shape- , length- , not referenced;
LS2
shape- , length- , length- ;
LS3
shape- upper trapezoidal, length- , length- , not referenced;
LS4
shape- upper trapezoidal, length- , length- , length- .
For problems of type FP, the objective function is omitted and , and are not referenced.
The following keywords are also acceptable.
Option
Least
LS1
Quadratic
QP2
Linear
LP
In addition, the keywords LS and LSQ are equivalent to the default option LS1, and the keyword QP is equivalent to the option QP2.
If , i.e., the objective function is purely linear, the efficiency of
lsq_lincon_solve
may be increased by specifying as LP.- ‘Rank Tolerance’float
Default or (see below)
Note that this option does not apply to problems of type FP or LP.
The default value of depends on the problem type. If occurs as a least squares matrix, as it does in problem types QP1, LS1 and LS3, then the default value of is . In all other cases, is treated as the ‘square root’ of the Hessian matrix and has the default value .
This argument enables you to control the estimate of the triangular factor (see Main Iteration). If denotes the function , the rank of is defined to be smallest index i such that . If , the default value is used.
- Raises
- NagValueError
- (errno )
Too many iterations.
- (errno )
Too many iterations without changing .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, has not been supplied as a valid permutation.
- (errno )
On entry, the equal bounds on are infinite, because and , but : and .
- (errno )
On entry, the bounds on are inconsistent: and .
- (errno )
On entry with a Warm Start, .
- (errno )
On entry, the equal bounds on variable are infinite, because and , but : and .
- (errno )
On entry, the equal bounds on linear constraint are infinite, because and , but : and .
- (errno )
On entry, the equal bounds on nonlinear constraint are infinite, because and , but : and .
- (errno )
On entry, the bounds on variable are inconsistent: and .
- (errno )
On entry, the bounds on linear constraint are inconsistent: and .
- (errno )
On entry, the bounds on nonlinear constraint are inconsistent: and .
- (errno )
The problem to be solved is of type QP1 or QP2, but the Hessian matrix supplied in is not positive semidefinite.
- Warns
- NagAlgorithmicWarning
- (errno )
Weak solution.
- (errno )
solution is unbounded.
- (errno )
Cannot satisfy the linear constraints.
- Notes
In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.
lsq_lincon_solve
is designed to solve a class of quadratic programming problems of the following general form:where is an matrix and the objective function may be specified in a variety of ways depending upon the particular problem to be solved. The available forms for are listed in Table [label omitted], in which the prefixes FP, LP, QP and LS stand for ‘feasible point’, ‘linear programming’, ‘quadratic programming’ and ‘least squares’ respectively, is an -element vector, is an element vector and denotes the Euclidean length of .
Problem type
Matrix
FP
None
Not applicable
LP
Not applicable
QP1
symmetric positive semidefinite
QP2
symmetric positive semidefinite
QP3
upper trapezoidal
QP4
upper trapezoidal
LS1
LS2
LS3
upper trapezoidal
LS4
upper trapezoidal
In the standard LS problem will usually have the form LS1, and in the standard convex QP problem will usually have the form QP2. The default problem type is LS1 and other objective functions are selected by using the option ‘Problem Type’.
When is upper trapezoidal it will usually be the case that , so that is upper triangular, but full generality has been allowed for in the specification of the problem. The upper trapezoidal form is intended for cases where a previous factorization, such as a factorization, has been performed.
The constraints involving are called the general constraints. Note that upper and lower bounds are specified for all the variables and for all the general constraints. An equality constraint can be specified by setting . If certain bounds are not present, the associated elements of or can be set to special values that will be treated as or . (See the description of the option ‘Infinite Bound Size’.)
The defining feature of a quadratic function is that the second-derivative matrix (the Hessian matrix) is constant. For the LP case ; for QP1 and QP2, ; for QP3 and QP4, and for LS1 (the default), LS2, LS3 and LS4, .
Problems of type QP3 and QP4 for which is not in upper trapezoidal form should be solved as types LS1 and LS2 respectively, with .
For problems of type LS, we refer to as the least squares matrix, or the matrix of observations and to as the vector of observations.
You must supply an initial estimate of the solution.
If is nonsingular then
lsq_lincon_solve
will obtain the unique (global) minimum. If is singular then the solution may still be a global minimum if all active constraints have nonzero Lagrange multipliers. Otherwise the solution obtained will be either a weak minimum (i.e., with a unique optimal objective value, but an infinite set of optimal ), or else the objective function is unbounded below in the feasible region. The last case can only occur when contains an explicit linear term (as in problems LP, QP2, QP4, LS2 and LS4).The method used by
lsq_lincon_solve
is described in detail in Algorithmic Details.
- References
Gill, P E, Hammarling, S, Murray, W, Saunders, M A and Wright, M H, 1986, Users’ guide for LSSOL (Version 1.0), Report SOL 86-1, Department of Operations Research, Stanford University
Gill, P E, Murray, W, Saunders, M A and Wright, M H, 1984, Procedures for optimization problems with a mixture of bounds and general linear constraints, ACM Trans. Math. Software (10), 282–298
Gill, P E, Murray, W and Wright, M H, 1981, Practical Optimization, Academic Press
Stoer, J, 1971, On the numerical solution of constrained least squares problems, SIAM J. Numer. Anal. (8), 382–411