14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7 Data Structures 161<br />

Matrices<br />

Another use of Cholesky() is in reordering matrices within Trace() expressions. Expressions such as<br />

Trace(A*B*A`) might involve huge operations counts if A has many rows. However, if B is small and can<br />

be factored into LL′ by Cholesky, then it can be reformulated to Trace(A*L*L`*A`). The resulting<br />

matrix is equal to Trace(L`A`*AL). This expression involves a much smaller number of operations,<br />

because it consists of only the sum of squares of the AL elements.<br />

Use the function Chol Update() to update a Cholesky decomposition. If L is the Cholesky root of a nxn<br />

matrix A, then after using cholUpdate(L, C, V), L will be replaced with the Cholesky root of<br />

A+V*C*V'. C is an mxm symmetric matrix and V is an nxm matrix.<br />

Examples<br />

Manually update the Cholesky decomposition, as follows:<br />

exS = [16 1 0 11 -1 12, 1 11 -1 1 -1 1, 0 -1 12 -1 1 0, 11 1 -1 11 -1 9, -1 -1<br />

1 -1 9 -1, 12 1 0 9 -1 12];<br />

// conducts the Cholesky decomposition<br />

exAchol = Cholesky( exS);<br />

// adds two column vectors to the design matrix<br />

exV = [1 1, 0 0, 0 1, 0 0, 0 0, 0 1];<br />

/* The first column vector is added to one of the rows in the design matrix.<br />

The second column vector is subtracted from one of the rows in the design<br />

matrix. */<br />

exC = [1 0, 0 -1];<br />

// updates the Cholesky decomposition manually<br />

exAnew = exS + exV * exC * exV`;<br />

exAcholnew = Cholesky( exAnew);<br />

Instead of manual updating, use Chol Update() to update the Cholesky decomposition, as follows:<br />

// updates the Cholesky decomposition more efficiently<br />

exAcholnew_test =<br />

Chol Update( exAchol, exV, exC );<br />

// results are the same as the manual process<br />

Show( exAcholnew_test );<br />

Show( exAcholnew );<br />

Singular Value Decomposition<br />

The SVD() function finds the singular value decomposition of a matrix. That is, for a matrix A, SVD()<br />

returns a list of three matrices U, M, and V, so that U*diag(M)*V`=A.<br />

Note the following:<br />

• When A is taller than it is wide, M is more compact, without extra zero diagonals.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!