PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_correg_corrmat_nearest (g02aa)
Purpose
nag_correg_corrmat_nearest (g02aa) computes the nearest correlation matrix, in the Frobenius norm, to a given square, input matrix.
Syntax
[
g,
x,
iter,
feval,
nrmgrd,
ifail] = g02aa(
g, 'n',
n, 'errtol',
errtol, 'maxits',
maxits, 'maxit',
maxit)
[
g,
x,
iter,
feval,
nrmgrd,
ifail] = nag_correg_corrmat_nearest(
g, 'n',
n, 'errtol',
errtol, 'maxits',
maxits, 'maxit',
maxit)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Description
A correlation matrix may be characterised as a real square matrix that is symmetric, has a unit diagonal and is positive semidefinite.
nag_correg_corrmat_nearest (g02aa) applies an inexact Newton method to a dual formulation of the problem, as described by
Qi and Sun (2006). It applies the improvements suggested by
Borsdorf and Higham (2010).
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
Parameters
Compulsory Input Parameters
- 1:
– double array
-
ldg, the first dimension of the array, must satisfy the constraint
.
, the initial matrix.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the first dimension of the array
g and the second dimension of the array
g. (An error is raised if these dimensions are not equal.)
The size of the matrix .
Constraint:
.
- 2:
– double scalar
Default:
The termination tolerance for the Newton iteration. If then is used.
- 3:
– int64int32nag_int scalar
Default:
maxits specifies the maximum number of iterations used for the iterative scheme used to solve the linear algebraic equations at each Newton step.
If , is used.
- 4:
– int64int32nag_int scalar
Default:
Specifies the maximum number of Newton iterations.
If , is used.
Output Parameters
- 1:
– double array
-
A symmetric matrix with the diagonal set to .
- 2:
– double array
-
Contains the nearest correlation matrix.
- 3:
– int64int32nag_int scalar
-
The number of Newton steps taken.
- 4:
– int64int32nag_int scalar
-
The number of function evaluations of the dual problem.
- 5:
– double scalar
-
The norm of the gradient of the last Newton step.
- 6:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
Constraint: .
Constraint: .
Constraint: .
-
-
Newton iteration fails to converge in iterations.
- W
-
Machine precision is limiting convergence.
The array returned in
x may still be of interest.
-
-
An intermediate eigenproblem could not be solved. This should not occur. Please contact
NAG with details of your call.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The returned accuracy is controlled by
errtol and limited by
machine precision.
Further Comments
Arrays are internally allocated by nag_correg_corrmat_nearest (g02aa). The total size of these arrays is real elements and integer elements.
Example
This example finds the nearest correlation matrix to:
Open in the MATLAB editor:
g02aa_example
function g02aa_example
fprintf('g02aa example results\n\n');
g = [ 2, -1, 0, 0;
-1, 2, -1, 0;
0, -1, 2, -1;
0, 0, -1, 2];
[g, x, iter, feval, nrmgrd, ifail] = ...
g02aa(g);
fprintf('\n Nearest Correlation Matrix\n');
disp(x);
fprintf('\n Number of Newton steps taken: %d\n', iter);
fprintf(' Number of function evaluations: %d\n', feval);
if (nrmgrd > 4*x02aj)
fprintf(' Norm of gradient of last Newton step: %6.4f\n', nrmgrd);
end
g02aa example results
Nearest Correlation Matrix
1.0000 -0.8084 0.1916 0.1068
-0.8084 1.0000 -0.6562 0.1916
0.1916 -0.6562 1.0000 -0.8084
0.1068 0.1916 -0.8084 1.0000
Number of Newton steps taken: 3
Number of function evaluations: 4
Norm of gradient of last Newton step: 0.0000
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015