NAG AD Library
g02ab (corrmat_nearest_bounded)

Settings help

AD Name Style:

AD Specification Language:

1 Purpose

g02ab is the AD Library version of the primal routine g02abf. Based (in the C++ interface) on overload resolution, g02ab can be used for primal, tangent and adjoint evaluation. It supports tangents and adjoints of first and second order.

2 Specification

Fortran Interface
Subroutine g02ab_AD_f ( g, ldg, n, opt, alpha, w, errtol, maxits, maxit, x, ldx, iter, feval, nrmgrd, ifail)
Integer, Intent (In) :: ldg, n, maxits, maxit, ldx
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: iter, feval
ADTYPE, Intent (In) :: alpha, errtol
ADTYPE, Intent (Inout) :: g(ldg,n), w(*), x(ldx,n)
ADTYPE, Intent (Out) :: nrmgrd
Character (1), Intent (In) :: opt
Type (c_ptr), Intent (Inout) :: ad_handle
Corresponding to the overloaded C++ function, the Fortran interface provides five routines with names reflecting the type used for active real arguments. The actual subroutine and type names are formed by replacing AD and ADTYPE in the above as follows:
when ADTYPE is Real(kind=nag_wp) then AD is p0w
when ADTYPE is Type(nagad_a1w_w_rtype) then AD is a1w
when ADTYPE is Type(nagad_t1w_w_rtype) then AD is t1w
when ADTYPE is Type(nagad_a1t1w_w_rtype) then AD is a1t1w
when ADTYPE is Type(nagad_t2w_w_rtype) then AD is t2w
C++ Interface
#include <dco.hpp>
#include <nagad.h>
namespace nag {
namespace ad {
void g02ab ( handle_t &ad_handle, ADTYPE g[], const Integer &ldg, const Integer &n, const char *opt, const ADTYPE &alpha, ADTYPE w[], const ADTYPE &errtol, const Integer &maxits, const Integer &maxit, ADTYPE x[], const Integer &ldx, Integer &iter, Integer &feval, ADTYPE &nrmgrd, Integer &ifail)
The function is overloaded on ADTYPE which represents the type of active arguments. ADTYPE may be any of the following types:
Note: this function can be used with AD tools other than dco/c++. For details, please contact NAG.

3 Description

g02ab is the AD Library version of the primal routine g02abf.
g02abf computes the nearest correlation matrix, in the Frobenius norm or weighted Frobenius norm, and optionally with bounds on the eigenvalues, to a given square, input matrix. For further information see Section 3 in the documentation for g02abf.

4 References

Borsdorf R and Higham N J (2010) A preconditioned (Newton) algorithm for the nearest correlation matrix IMA Journal of Numerical Analysis 30(1) 94–107
Qi H and Sun D (2006) A quadratically convergent Newton method for computing the nearest correlation matrix SIAM J. Matrix AnalAppl 29(2) 360–385

5 Arguments

In addition to the arguments present in the interface of the primal routine, g02ab includes some arguments specific to AD.
A brief summary of the AD specific arguments is given below. For the remainder, links are provided to the corresponding argument from the primal routine. A tooltip popup for all arguments can be found by hovering over the argument name in Section 2 and in this section.
1: ad_handlenag::ad::handle_t Input/Output
On entry: a configuration object that holds information on the differentiation strategy. Details on setting the AD strategy are described in AD handle object in the NAG AD Library Introduction.
2: g(ldg, n) – ADTYPE array Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
3: ldg – Integer Input
4: n – Integer Input
5: opt – character Input
6: alphaADTYPE Input
7: w(*) – ADTYPE array Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
8: errtolADTYPE Input
9: maxits – Integer Input
10: maxit – Integer Input
11: x(ldx, n) – ADTYPE array Output
12: ldx – Integer Input
13: iter – Integer Output
14: feval – Integer Output
15: nrmgrdADTYPE Output
16: ifail – Integer Input/Output

6 Error Indicators and Warnings

g02ab preserves all error codes from g02abf and in addition can return:
An unexpected AD error has been triggered by this routine. Please contact NAG.
See Error Handling in the NAG AD Library Introduction for further information.
The routine was called using a strategy that has not yet been implemented.
See AD Strategies in the NAG AD Library Introduction for further information.
A C++ exception was thrown.
The error message will show the details of the C++ exception text.
Dynamic memory allocation failed for AD.
See Error Handling in the NAG AD Library Introduction for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

g02ab is not threaded in any implementation.

9 Further Comments


10 Example

The following examples are variants of the example for g02abf, modified to demonstrate calling the NAG AD Library.
Description of the primal example.
This example finds the nearest correlation matrix to:
G = ( 2 −1 0 0 −1 2 −1 0 0 −1 2 −1 0 0 −1 2 )  
weighted by W12 = diag(100,20,20,20) with minimum eigenvalue 0.02.

10.1 Adjoint modes

Language Source File Data Results
Fortran g02ab_a1t1w_fe.f90 g02ab_a1t1w_fe.d g02ab_a1t1w_fe.r
Fortran g02ab_a1w_fe.f90 g02ab_a1w_fe.d g02ab_a1w_fe.r
C++ g02ab_a1_algo_dcoe.cpp None g02ab_a1_algo_dcoe.r
C++ g02ab_a1t1_algo_dcoe.cpp None g02ab_a1t1_algo_dcoe.r

10.2 Tangent modes

Language Source File Data Results
Fortran g02ab_t1w_fe.f90 g02ab_t1w_fe.d g02ab_t1w_fe.r
Fortran g02ab_t2w_fe.f90 g02ab_t2w_fe.d g02ab_t2w_fe.r
C++ g02ab_t1_dcoe.cpp None g02ab_t1_dcoe.r
C++ g02ab_t2_dcoe.cpp None g02ab_t2_dcoe.r

10.3 Passive mode

Language Source File Data Results
Fortran g02ab_p0w_fe.f90 g02ab_p0w_fe.d g02ab_p0w_fe.r
C++ g02ab_passive_dcoe.cpp None g02ab_passive_dcoe.r