NLPDirect interface using finite differences.
More...
#include <NLPInterfacePack_NLPDirectTester.hpp>
Public Types | |
| enum | ETestingMethod |
| More... | |
Public Member Functions | |
| void | set_calc_fd_prod (const Teuchos::RefCountPtr< CalcFiniteDiffProd > &calc_fd_prod) |
| | |
| void | Gf_testing_method (const ETestingMethod &Gf_testing_method) |
Members for option Gf_testing_method(). | |
| void | Gc_testing_method (const ETestingMethod &Gc_testing_method) |
Members for option Gc_testing_method(). | |
| void | Gf_warning_tol (const value_type &Gf_warning_tol) |
Members for option Gf_warning_tol(). | |
| void | Gf_error_tol (const value_type &Gf_error_tol) |
Members for option Gf_error_tol(). | |
| void | Gc_warning_tol (const value_type &Gc_warning_tol) |
Members for option Gc_warning_tol(). | |
| void | Gc_error_tol (const value_type &Gc_error_tol) |
Members for option Gc_error_tol(). | |
| void | num_fd_directions (const size_type &num_fd_directions) |
Members for option num_fd_directions(). | |
| void | dump_all (const bool &dump_all) |
Members for option dump_all(). | |
| NLPDirectTester (const calc_fd_prod_ptr_t &calc_fd_prod=Teuchos::null, ETestingMethod Gf_testing_method=FD_DIRECTIONAL, ETestingMethod Gc_testing_method=FD_DIRECTIONAL, value_type Gf_warning_tol=1e-6, value_type Gf_error_tol=1e-1, value_type Gc_warning_tol=1e-6, value_type Gc_error_tol=1e-1, size_type num_fd_directions=1, bool dump_all=false) | |
| Constructor. | |
| bool | finite_diff_check (NLPDirect *nlp, const Vector &xo, const Vector *xl, const Vector *xu, const Vector *c, const Vector *Gf, const Vector *py, const Vector *rGf, const MatrixOp *GcU, const MatrixOp *D, const MatrixOp *Uz, bool print_all_warnings, std::ostream *out) const |
This function takes an NLP object and its computed derivatives and function values and validates the functions and the derivatives by evaluating them about the given point xo. | |
NLPDirect interface using finite differences.
There are two options for testing the derivatives by finite differences. Each option can be picked independently for the computations with the objective f(x) and its gradient Gf and for the constraints c(x) and its Jacobian Gc'. The tests involving the objective and the constraints will be discussed separatly.
For testing the gradient of the objective function, two options are available. The first option (Gf_testing_method==FD_COMPUTE_ALL) is to compute FDGf by brute force which requries 2*n evaluations of f(x) using central differences. Given FDGf the following comparison is then made:
(1) FDGf \approx Gf
Gf_testing_method==FD_DIRECTIONAL) is to compute random dot products of the form DFGf'*y where y is a randomly generated vector. Using central differences DFGf'*y can be computed using two evaluations of f(x) per random y. The number of random y's used is determined by the option num_fd_directions(). So the number of evaluations of f(x) for this option is 2*num_fd_directions().
The test for the quantity py = -inv(C)*c(con_decomp) is shown below:
(2) - FDC * (-inv(C)*c) \approx c(c_decomp)
\_________/
py
-FDC * py requires only two evaluations of c(x) using central differences. There is no other option needed for this test.
Lastly, we have to test D = -inv(C)*N. The first option (Gc_testing_method==FD_COMPUTE_ALL) is to directly compute N using central differences (2*(n-m) evaluations of c(x)) as FDN and then perform the comparison:
(3) - FDC * (-inv(C)*N) \approx FDN
\_________/
D
-FDC * D can be computed using 2*(n-m) evaluations with c(x) using central differences. Therefore, the total number of evaluations with c(x) for comparing (3) is 4*(n-m). If n-m is not too large then this is definitely the preferred method to use.
The other option for testing D = -inv(C)*N is to compute directional derivatives using finite differences. In this approach, for the random vector y, we can compute:
(4) - FDC * (-inv(C)*N) * y \approx FDN * y
\_________/
D
y's used is determined by the option num_fd_directions(). So the number of evaluations of c(x) for this option is 4*num_fd_directions().The client can pick a set of tolerances to measure if the values of the above comparisons are close enough to the finite difference values. Let's define the relative error between the computed value and the finite difference value to be:
err(i) = | (h(i) - fdh(i)) | / (||h||inf + ||fdh||inf + sqrt(epsilon))
1e-16 not comparing with zero.
All errors err(i) >= warning_tol are reported to *out if out != NULL. The first error err(i) >= error_tol that is found is reported to *out if out != NULL and immediatly finite_diff_check() returns false. If all errors err(i) < error_tol, then finite_diff_check() will return true.
Given these two tolerances the client can do many things:
1) Print out all the comparisons that are not equal by setting warning_tol <= epsilon and error_tol >> 1.
2) Print out all suspect comparisons by setting epsilon < warning_tol < 1 and error_tol >> 1.
3) Just validate that the quantities are approximatly equal and report the first discrepency if not by setting epsilon < error_tol < 1 and warning_tol >= error_tol.
4) Print out any suspect comparisons by setting epsilon < warning_tol < 1 but also quit if the error is too large by setting 1 > error_tol > warning_tol.
The tolerances Gf_warning_tol and Gf_error_tol are applied to the tests for Gf shown in (1) for instance. The tolerances Gc_warning_tol and Gc_error_tol are used for the comparisions (2), (3) and (4).
There is one minor hitch to this testing. For many NLPs, there is a * strict region of x where f(x) or c(x) are not defined. In order to help ensure that we stay out of these regions, variable bounds and a scalar max_var_bounds_viol can be included so that the testing software will never evaluate f(x) or c(x) outside the region:
xl - max_var_bounds_viol <= x <= xu + max_var_bounds_viol
Definition at line 154 of file NLPInterfacePack_NLPDirectTester.hpp.
|
|
Definition at line 158 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
||||||||||||||||||||||||||||||||||||||||
|
Constructor.
Definition at line 57 of file NLPInterfacePack_NLPDirectTester.cpp. |
|
|
Definition at line 164 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
|
Members for option
Definition at line 166 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
|
Members for option
Definition at line 168 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
|
Members for option
Definition at line 170 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
|
Members for option
Definition at line 172 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
|
Members for option
Definition at line 174 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
|
Members for option
Definition at line 176 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
|
Members for option
Definition at line 178 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
|
Members for option
Definition at line 180 of file NLPInterfacePack_NLPDirectTester.hpp. |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This function takes an NLP object and its computed derivatives and function values and validates the functions and the derivatives by evaluating them about the given point If all the checks as described in the intro checkout then this function will return true, otherwise it will return false. If the finite difference steps are limited by relaxed variable bounds then a warning message is printed and the derivatives computed could be very inaccurate.
Definition at line 82 of file NLPInterfacePack_NLPDirectTester.cpp. |
1.3.9.1