nlesolver-fortran

Nonlinear Equation Solver with Modern Fortran.
A basic Newton-Raphson type nonlinear equation solver for sparse or dense systems with m functions of n input variables.
Status

Features
- Is object-oriented.
- Works with square, under-determined, or over-determined systems.
- Can use different methods to solve the linear system:
- LAPACK routines (
dgesv or dgels) for dense systems: If n=m, uses dgesv (LU decomposition). If n/=m, uses dgels (if m>n uses QR factorization, if m<n uses LQ factorization).
- lsqr -- a conjugate-gradient type method for solving sparse linear equations and sparse least-squares problems.
- lusol -- A sparse LU factorization for square and rectangular matrices, with Bartels-Golub-Reid updates for column replacement and other rank-1 modifications.
- lsmr -- a conjugate-gradient type method for solving sparse linear equations and sparse least-squares problems
- The user can also provide a custom linear solver.
- CRAIG -- a built-in conjugate-gradient type method (based on Golub-Kahan bidiagonalization) for the minimum-norm solution of sparse linear systems. It is intended for large, sparse, under-determined systems (
n>m), but works for any compatible system. It has no external dependencies, and uses only products with A and A^T computed directly from the sparse Jacobian, so the dense matrix is never formed. A damp option solves a regularized version of the problem, for use when the Jacobian is rank deficient.
- Sparse Cholesky -- a built-in sparse direct method for the minimum-norm solution of sparse linear systems (
x = A^T y, (A A^T) y = b). It has no external dependencies, and never forms the dense matrix. The rows are reordered once with the reverse Cuthill-McKee algorithm (so the Jacobian does not have to be numbered in banded order), A A^T is formed directly in envelope ("skyline") storage and factored with a Cholesky factorization, and iterative refinement is used to recover the accuracy lost by forming A A^T. This is much faster than the iterative methods for banded or "mostly banded" Jacobians (for a 500,000 variable banded test problem, about 5x faster than CRAIG; see the technical note in docs). For general sparse matrices with large fill-in, a nested-dissection based solver such as qr_mumps can be used via the custom linear solver option. The damp option is also supported.
- Has a Broyden update option (sparse and dense versions).
- Has various line search options.
- use a specified constant step size (0,1]
- backtracking linesearch method
- exact linesearch method using fmin minimizer
- evaluate function at specified fixed points
- Has four options for variable bounds (
xlow<=x<=xupp):
- Ignore bounds
- Scalar mode: The Newton search direction is changed by checking each
x component individually. If a component is on a bound, its value is set to the bound. The result is the new line search direction.
- Vector mode: The Newton search direction is not changed, but, the magnitude is walked back so that no variable violates their bounds.
- "Wall" mode: Similar to scalar mode, except after modifying the search direction vector, each line search step keeps any values constant that were put on the bounds.
- Has three options for computing the function vector norm:
- 2-norm (
norm2(fvec))
- Infinity-norm (
maxval(abs(fvec)))
- 1-norm (
sum(abs(fvec)))
Compiling
- A Fortran Package Manager file is also included, so that the library and tests cases can be compiled with FPM. For example:
fpm build --profile release
fpm test --profile release
By default, the library is built with double precision (real64) real values. Explicitly specifying the real kind can be done using the following preprocessor flags:
| Preprocessor flag |
Kind |
Number of bytes |
REAL32 |
real(kind=real32) |
4 |
REAL64 |
real(kind=real64) |
8 |
REAL128 |
real(kind=real128) |
16 |
For example, to build a single precision version of the library, use:
fpm build --profile release --flag "-DREAL32"
To use nlesolver within your fpm project, add the following to your fpm.toml file:
[dependencies]
nlesolver-fortran = { git="https://github.com/jacobwilliams/nlesolver-fortran.git" }
Or to use a specific version:
[dependencies]
nlesolver-fortran = { git="https://github.com/jacobwilliams/nlesolver-fortran.git", tag="1.1.0" }
Note that LAPACK is required to build. The fmin, lsqr, lusol, and lsmr libraries are also dependencies (which will be automatically downloaded by fpm).
Documentation
- The API documentation for the current
master branch can be found here. This is generated by processing the source files with FORD.
- A technical note describing the theory behind the solver, its options, their performance, and recommended settings for different use cases is in
docs (PDF).
License
- The NLESolver-Fortran source code and related files and documentation are distributed under a permissive free software license (BSD-3).
References
- C. G. Broyden, "A Class of Methods for Solving Nonlinear Simultaneous Equations", Math. Comp. 19 (1965), 577-593
- L. K. Schubert, "Modification of a Quasi-Newton Method for Nonlinear Equations with a Sparse Jacobian", Mathematics of Computation, Vol. 24, No. 109 (Jan., 1970), pp. 27-30.
- C. C. Paige and M. A. Saunders, "LSQR: An Algorithm for Sparse Linear Equations and Sparse Least Squares", ACM Transactions on Mathematical Software, Vol. 8, No. 1 (1982), pp. 43-71.
- M. A. Saunders, "Solution of Sparse Rectangular Systems Using LSQR and CRAIG", BIT Numerical Mathematics, Vol. 35 (1995), pp. 588-604.
- A. George and J. W. H. Liu, "Computer Solution of Large Sparse Positive Definite Systems", Prentice-Hall, 1981.
- E. Cuthill and J. McKee, "Reducing the Bandwidth of Sparse Symmetric Matrices", Proceedings of the 24th ACM National Conference (1969), pp. 157-172.
See also
- MINPACK -- Modernized Minpack: for solving nonlinear equations and nonlinear least squares problems
- LUSOL Stanford University Systems Optimization Laboratory
- qr_mumps -- a software package for the solution of sparse, linear
systems on multicore computers.
Developer Info
Jacob Williams