ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
PHPExcel_Shared_JAMA_QRDecomposition Class Reference
+ Collaboration diagram for PHPExcel_Shared_JAMA_QRDecomposition:

Public Member Functions

 __construct ($A)
 QR Decomposition computed by Householder reflections.
 isFullRank ()
 Is the matrix full rank?
 getH ()
 Return the Householder vectors.
 getR ()
 Return the upper triangular factor.
 getQ ()
 Generate and return the (economy-sized) orthogonal factor.
 solve ($B)
 Least squares solution of A*X = B.

Data Fields

const MatrixRankException = "Can only perform operation on full-rank matrix."

Private Attributes

 $QR = array()
 $m
 $n
 $Rdiag = array()

Detailed Description

Definition at line 19 of file QRDecomposition.php.

Constructor & Destructor Documentation

PHPExcel_Shared_JAMA_QRDecomposition::__construct (   $A)

QR Decomposition computed by Householder reflections.

Parameters
matrix$ARectangular matrix
Returns
Structure to access R and the Householder vectors and compute Q.

Definition at line 54 of file QRDecomposition.php.

References $m, $n, PHPExcel_Shared_JAMA_Matrix\ArgumentTypeException, hypo(), and n.

{
if($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Initialize.
$this->QR = $A->getArrayCopy();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
// Main loop.
for ($k = 0; $k < $this->n; ++$k) {
// Compute 2-norm of k-th column without under/overflow.
$nrm = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$nrm = hypo($nrm, $this->QR[$i][$k]);
}
if ($nrm != 0.0) {
// Form k-th Householder vector.
if ($this->QR[$k][$k] < 0) {
$nrm = -$nrm;
}
for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$k] /= $nrm;
}
$this->QR[$k][$k] += 1.0;
// Apply transformation to remaining columns.
for ($j = $k+1; $j < $this->n; ++$j) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $this->QR[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
$this->Rdiag[$k] = -$nrm;
}
} else {
}
} // function __construct()

+ Here is the call graph for this function:

Member Function Documentation

PHPExcel_Shared_JAMA_QRDecomposition::getH ( )

Return the Householder vectors.

Returns
Matrix Lower trapezoidal matrix whose columns define the reflections

Definition at line 116 of file QRDecomposition.php.

References $m, and $n.

{
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i >= $j) {
$H[$i][$j] = $this->QR[$i][$j];
} else {
$H[$i][$j] = 0.0;
}
}
}
} // function getH()
PHPExcel_Shared_JAMA_QRDecomposition::getQ ( )

Generate and return the (economy-sized) orthogonal factor.

Returns
Matrix orthogonal factor

Definition at line 156 of file QRDecomposition.php.

References $m, $n, and n.

{
for ($k = $this->n-1; $k >= 0; --$k) {
for ($i = 0; $i < $this->m; ++$i) {
$Q[$i][$k] = 0.0;
}
$Q[$k][$k] = 1.0;
for ($j = $k; $j < $this->n; ++$j) {
if ($this->QR[$k][$k] != 0) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $Q[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$Q[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
}
/*
for($i = 0; $i < count($Q); ++$i) {
for($j = 0; $j < count($Q); ++$j) {
if(! isset($Q[$i][$j]) ) {
$Q[$i][$j] = 0;
}
}
}
*/
} // function getQ()
PHPExcel_Shared_JAMA_QRDecomposition::getR ( )

Return the upper triangular factor.

Returns
Matrix upper triangular factor

Definition at line 135 of file QRDecomposition.php.

References $n.

{
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i < $j) {
$R[$i][$j] = $this->QR[$i][$j];
} elseif ($i == $j) {
$R[$i][$j] = $this->Rdiag[$i];
} else {
$R[$i][$j] = 0.0;
}
}
}
} // function getR()
PHPExcel_Shared_JAMA_QRDecomposition::isFullRank ( )

Is the matrix full rank?

Returns
boolean true if R, and hence A, has full rank, else false.

Definition at line 101 of file QRDecomposition.php.

References $n.

Referenced by solve().

{
for ($j = 0; $j < $this->n; ++$j) {
if ($this->Rdiag[$j] == 0) {
return false;
}
}
return true;
} // function isFullRank()

+ Here is the caller graph for this function:

PHPExcel_Shared_JAMA_QRDecomposition::solve (   $B)

Least squares solution of A*X = B.

Parameters
Matrix$BA Matrix with as many rows as A and any number of columns.
Returns
Matrix Matrix that minimizes the two norm of Q*R*X-B.

Definition at line 194 of file QRDecomposition.php.

References $m, $n, $X, isFullRank(), PHPExcel_Shared_JAMA_Matrix\MatrixDimensionException, and MatrixRankException.

{
if ($B->getRowDimension() == $this->m) {
if ($this->isFullRank()) {
// Copy right hand side
$nx = $B->getColumnDimension();
$X = $B->getArrayCopy();
// Compute Y = transpose(Q)*B
for ($k = 0; $k < $this->n; ++$k) {
for ($j = 0; $j < $nx; ++$j) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $X[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$X[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
// Solve R*X = Y;
for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->Rdiag[$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k];
}
}
}
return ($X->getMatrix(0, $this->n-1, 0, $nx));
} else {
}
} else {
}
} // function solve()

+ Here is the call graph for this function:

Field Documentation

PHPExcel_Shared_JAMA_QRDecomposition::$m
private

Definition at line 33 of file QRDecomposition.php.

Referenced by __construct(), getH(), getQ(), and solve().

PHPExcel_Shared_JAMA_QRDecomposition::$n
private

Definition at line 39 of file QRDecomposition.php.

Referenced by __construct(), getH(), getQ(), getR(), isFullRank(), and solve().

PHPExcel_Shared_JAMA_QRDecomposition::$QR = array()
private

Definition at line 27 of file QRDecomposition.php.

PHPExcel_Shared_JAMA_QRDecomposition::$Rdiag = array()
private

Definition at line 45 of file QRDecomposition.php.

const PHPExcel_Shared_JAMA_QRDecomposition::MatrixRankException = "Can only perform operation on full-rank matrix."

Definition at line 21 of file QRDecomposition.php.


The documentation for this class was generated from the following file: