hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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 XX by minimizing (1/2)GX212G-X2 where GG is an approximate correlation matrix.
The norm can either be the Frobenius norm or the weighted Frobenius norm (1/2) W(1/2)(GX)W(1/2)F2 12 W12 (G-X) W12 F 2 .
You can optionally specify a lower bound on the eigenvalues, αα, of the computed correlation matrix, forcing the matrix to be positive definite, 0 < α < 10<α<1.
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:     g(ldg,n) – double array
ldg, the first dimension of the array, must satisfy the constraint ldgnldgn.
GG, the initial matrix.
2:     opt – string (length ≥ 1)
Indicates the problem to be solved.
opt = 'A'opt='A'
The lower bound problem is solved.
opt = 'W'opt='W'
The weighted norm problem is solved.
opt = 'B'opt='B'
Both problems are solved.
Constraint: opt = 'A'opt='A', 'W''W' or 'B''B'.
3:     alpha – double scalar
The value of αα.
If opt = 'W'opt='W', alpha need not be set.
Constraint: 0.0 < alpha < 1.00.0<alpha<1.0.
4:     w(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0n>0.
The square roots of the diagonal elements of WW, that is the diagonal of W(1/2)W12.
If opt = 'A'opt='A', w need not be set.
Constraint: w(i) > 0.0wi>0.0, for i = 1,2,,ni=1,2,,n.

Optional Input Parameters

1:     n – 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 GG.
Constraint: n > 0n>0.
2:     errtol – double scalar
The termination tolerance for the Newton iteration. If errtol0.0errtol0.0 then n × sqrt(machine precision)n×machine precision is used.
Default: 0.00.0 
3:     maxits – int64int32nag_int scalar
Specifies the maximum number of iterations to be used by the iterative scheme to solve the linear algebraic equations at each Newton step.
If maxits0maxits0, 2 × n2×n is used.
Default: 00 
4:     maxit – int64int32nag_int scalar
Specifies the maximum number of Newton iterations.
If maxit0maxit0, 200200 is used.
Default: 00 

Input Parameters Omitted from the MATLAB Interface

ldg ldx

Output Parameters

1:     g(ldg,n) – double array
ldgnldgn.
A symmetric matrix (1/2)(G + GT)12(G+GT) with the diagonal set to II.
2:     w(n) – double array
If opt = 'W'opt='W' or 'B''B', the array is scaled so 0 < w(i)10<wi1, for i = 1,2,,ni=1,2,,n.
3:     x(ldx,n) – double array
ldxnldxn.
Contains the nearest correlation matrix.
4:     iter – int64int32nag_int scalar
The number of Newton steps taken.
5:     feval – int64int32nag_int scalar
The number of function evaluations of the dual problem.
6:     nrmgrd – double scalar
The norm of the gradient of the last Newton step.
7:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 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.

  ifail = 1ifail=1
Constraint: 0.0 < alpha < 1.00.0<alpha<1.0.
Constraint: ldgnldgn.
Constraint: ldxnldxn 
Constraint: n > 0n>0.
On entry, all elements of w were not positive.
On entry, opt'A'opt'A', 'W''W' or 'B''B'.
  ifail = 2ifail=2
Newton iteration fails to converge in __ iterations. Increase maxit or check the call to the function.
W ifail = 3ifail=3
The machine precision is limiting convergence. In this instance the returned matrix XX may be useful.
W ifail = 4ifail=4
Failure to solve intermediate eigenproblem.
  ifail = 999ifail=-999
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 12 × n + 3 × n × n + max (2 × n × n + 6 × n + 1,120 + 9 × n)12×n+3×n×n+max(2×n×n+6×n+1,120+9×n) double elements and 5 × n + 35×n+3 integer elements. All allocated memory is freed before return of nag_correg_corrmat_nearest_bounded (g02ab).

Example

function nag_correg_corrmat_nearest_bounded_example
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];

% Calculate nearest correlation matrix
[g, w, x, iter, feval, nrmgrd, ifail] = nag_correg_corrmat_nearest_bounded(g, opt, alpha, w);

if (ifail == 0)
  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);

  [xOut, eig, info] = nag_lapack_dsyev('n', 'u', x);
  fprintf('\n Eigenvalues of x:\n');
  disp(transpose(eig));
end
 

 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


function g02ab_example
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];

% Calculate nearest correlation matrix
[g, w, x, iter, feval, nrmgrd, ifail] = g02ab(g, opt, alpha, w);

if (ifail == 0)
  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);

  [xOut, eig, info] = f08fa('n', 'u', x);
  fprintf('\n Eigenvalues of x:\n');
  disp(transpose(eig));
end
 

 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)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013