PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_correg_corrmat_nearest_bounded (g02ab)
Purpose
nag_correg_corrmat_nearest_bounded (g02ab) 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.
Syntax
[
g,
w,
x,
iter,
feval,
nrmgrd,
ifail] = g02ab(
g,
opt,
alpha,
w, 'n',
n, 'errtol',
errtol, 'maxits',
maxits, 'maxit',
maxit)
[
g,
w,
x,
iter,
feval,
nrmgrd,
ifail] = nag_correg_corrmat_nearest_bounded(
g,
opt,
alpha,
w, 'n',
n, 'errtol',
errtol, 'maxits',
maxits, 'maxit',
maxit)
Description
Finds the nearest correlation matrix by minimizing where is an approximate correlation matrix.
The norm can either be the Frobenius norm or the weighted Frobenius norm .
You can optionally specify a lower bound on the eigenvalues, , of the computed correlation matrix, forcing the matrix to be positive definite, .
Note that if the weights vary by several orders of magnitude from one another the algorithm may fail to converge.
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.
- 2:
– string (length ≥ 1)
-
Indicates the problem to be solved.
- The lower bound problem is solved.
- The weighted norm problem is solved.
- Both problems are solved.
Constraint:
, or .
- 3:
– double scalar
-
The value of
.
If
,
alpha need not be set.
Constraint:
.
- 4:
– double array
-
The square roots of the diagonal elements of
, that is the diagonal of
.
If
,
w is not referenced and need not be set.
Constraint:
, for .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
w and 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 order of the matrix .
Constraint:
.
- 2:
– double scalar
Default:
The termination tolerance for the Newton iteration. If then is used.
- 3:
– int64int32nag_int scalar
Default:
Specifies the maximum number of iterations to be used by the iterative scheme 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
-
- 2:
– double array
-
If or , the array is scaled so
, for .
- 3:
– double array
-
Contains the nearest correlation matrix.
- 4:
– int64int32nag_int scalar
-
The number of Newton steps taken.
- 5:
– int64int32nag_int scalar
-
The number of function evaluations of the dual problem.
- 6:
– double scalar
-
The norm of the gradient of the last Newton step.
- 7:
– 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: .
Constraint: .
On entry, all elements of
w were not positive.
On entry, , or .
-
-
Newton iteration fails to converge in
iterations. Increase
maxit or check the call to the function.
- W
-
The
machine precision is limiting convergence. In this instance the returned value of
x may be useful.
- W
-
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_bounded (g02ab). The total size of these arrays is double elements and integer elements. All allocated memory is freed before return of nag_correg_corrmat_nearest_bounded (g02ab).
Example
This example finds the nearest correlation matrix to:
weighted by
with minimum eigenvalue
.
Open in the MATLAB editor:
g02ab_example
function g02ab_example
fprintf('g02ab example results\n\n');
opt = 'b';
alpha = 0.02;
g = [2, -1, 0, 0;
-1, 2, -1, 0;
0, -1, 2, -1;
0, 0, -1, 2];
w = [100, 20, 20, 20];
[g, w, x, iter, feval, nrmgrd, ifail] = ...
g02ab(g, opt, alpha, w);
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);
fprintf('\n\n Alpha: %30.3f\n', alpha);
[x, eig, info] = f08fa('n', 'u', x);
fprintf('\n Eigenvalues of x:\n');
disp(transpose(eig));
g02ab example results
Nearest Correlation Matrix:
1.0000 -0.9187 0.0257 0.0086
-0.9187 1.0000 -0.3008 0.2270
0.0257 -0.3008 1.0000 -0.8859
0.0086 0.2270 -0.8859 1.0000
Number of Newton steps taken: 5
Number of function evaluations: 6
Alpha: 0.020
Eigenvalues of x:
0.0392 0.1183 1.6515 2.1910
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015