NAG CL Interface
g02asc (corrmat_​fixed)

Settings help

CL Name Style:


1 Purpose

g02asc computes the nearest correlation matrix, in the Frobenius norm, while fixing elements and optionally with bounds on the eigenvalues, to a given square input matrix.

2 Specification

#include <nag.h>
void  g02asc (double g[], Integer pdg, Integer n, double alpha, const Integer h[], Integer pdh, double errtol, Integer maxit, Integer m, double x[], Integer pdx, Integer *its, double *fnorm, NagError *fail)
The function may be called by the names: g02asc or nag_correg_corrmat_fixed.

3 Description

g02asc finds the nearest correlation matrix, X, to a matrix, G, in the Frobenius norm. It uses an alternating projections algorithm with Anderson acceleration. Elements in the input matrix can be fixed by supplying the value 1 in the corresponding element of the matrix H. However, note that the algorithm may fail to converge if the fixed elements do not form part of a valid correlation matrix. You can optionally specify a lower bound, α, on the eigenvalues of the computed correlation matrix, forcing the matrix to be positive definite with 0α<1.

4 References

Anderson D G (1965) Iterative Procedures for Nonlinear Integral Equations J. Assoc. Comput. Mach. 12 547–560
Higham N J and Strabić N (2016) Anderson acceleration of the alternating projections method for computing the nearest correlation matrix Numer. Algor. 72 1021–1042

5 Arguments

1: g[pdg×n] double Input/Output
Note: the (i,j)th element of the matrix G is stored in g[(j-1)×pdg+i-1].
On entry: G~, the initial matrix.
On exit: the symmetric matrix G=12(G~+G~T) with the diagonal elements set to 1.0.
2: pdg Integer Input
On entry: the stride separating matrix row elements in the array g.
Constraint: pdgn.
3: n Integer Input
On entry: the order of the matrix G.
Constraint: n>0.
4: alpha double Input
On entry: the value of α.
If alpha<0.0, a value of 0.0 is used.
Constraint: alpha<1.0.
5: h[pdh×n] const Integer Input
Note: the (i,j)th element of the matrix H is stored in h[(j-1)×pdh+i-1].
On entry: the symmetric matrix H. If an element of H is 1 then the corresponding element in G is fixed in the output X. Only the strictly lower triangular part of H need be set.
6: pdh Integer Input
On entry: the stride separating matrix row elements in the array h.
Constraint: pdhn.
7: errtol double Input
On entry: the termination tolerance for the iteration.
If errtol0.0, machine precision is used. See Section 7 for further details.
8: maxit Integer Input
On entry: specifies the maximum number of iterations.
If maxit0, a value of 200 is used.
9: m Integer Input
On entry: the number of previous iterates to use in the Anderson acceleration. If m=0, Anderson acceleration is not used. See Section 7 for further details.
If m<0, a value of 4 is used.
Constraint: mn×n.
10: x[pdx×n] double Output
Note: the (i,j)th element of the matrix X is stored in x[(j-1)×pdx+i-1].
On exit: contains the matrix X.
11: pdx Integer Input
On entry: the stride separating matrix row elements in the array x.
Constraint: pdxn.
12: its Integer * Output
On exit: the number of iterations taken.
13: fnorm double * Output
On exit: the value of G-XF after the final iteration.
14: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALG_FAIL
Failure during Anderson acceleration.
Consider setting m=0 and recomputing.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_CONVERGENCE
Function failed to converge in value iterations.
A solution may not exist, however, try increasing maxit.
NE_INT
On entry, n=value.
Constraint: n>0.
NE_INT_2
On entry, m=value and n=value.
Constraint: mn×n.
On entry, pdg=value and n=value.
Constraint: pdgn.
On entry, pdh=value and n=value.
Constraint: pdhn.
On entry, pdx=value and n=value.
Constraint: pdxn.
The fixed element Gij, lies outside the interval [−1,1], for i=value and j=value.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL
On entry, alpha=value.
Constraint: alpha<1.0.

7 Accuracy

Alternating projections is an iterative process where at each iteration the new iterate, Xk, can be improved by using Anderson acceleration to reduce the overall number of iterations. The alternating projections algorithm terminates at the kth iteration when
Xk-Yk F Xk F errtol  
where Yk is the result of the first of two projections computed at each step.
Without Anderson acceleration this algorithm is guaranteed to converge. There is no theoretical guarantee of convergence of Anderson acceleration and, therefore, when it is used, no guarantee of convergence of g02asc. However, in practice it can be seen to significantly reduce the number of alternating projection iterations. Anderson acceleration is not used when m is set to zero. See c05mdc and Higham and Strabić (2016) and Anderson (1965) for further information.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g02asc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g02asc makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

Arrays are internally allocated by g02asc. The total size of these arrays does not exceed 12×n2 real elements. All allocated memory is freed before return of g02asc.

10 Example

This example finds the nearest correlation matrix, X, to the input, G, whilst fixing two diagonal blocks as given by H. The minimum eigenvalue of X is stipulated to be 0.04.
G = ( 1.0000 -0.0991 0.5665 -0.5653 -0.3441 -0.0991 1.0000 -0.4273 0.8474 0.4975 0.5665 -0.4273 1.0000 -0.1837 -0.0585 -0.5653 0.8474 -0.1837 1.0000 -0.2713 -0.3441 0.4975 -0.0585 -0.2713 1.0000 )  
and
H = ( 1 1 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 1 ) .  
Only the strictly lower half of H is supplied in the example.

10.1 Program Text

Program Text (g02asce.c)

10.2 Program Data

Program Data (g02asce.d)

10.3 Program Results

Program Results (g02asce.r)