ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
PHPExcel_Shared_JAMA_QRDecomposition Class Reference
+ Collaboration diagram for PHPExcel_Shared_JAMA_QRDecomposition:

Public Member Functions

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

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

◆ __construct()

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.

54  {
55  if($A instanceof PHPExcel_Shared_JAMA_Matrix) {
56  // Initialize.
57  $this->QR = $A->getArrayCopy();
58  $this->m = $A->getRowDimension();
59  $this->n = $A->getColumnDimension();
60  // Main loop.
61  for ($k = 0; $k < $this->n; ++$k) {
62  // Compute 2-norm of k-th column without under/overflow.
63  $nrm = 0.0;
64  for ($i = $k; $i < $this->m; ++$i) {
65  $nrm = hypo($nrm, $this->QR[$i][$k]);
66  }
67  if ($nrm != 0.0) {
68  // Form k-th Householder vector.
69  if ($this->QR[$k][$k] < 0) {
70  $nrm = -$nrm;
71  }
72  for ($i = $k; $i < $this->m; ++$i) {
73  $this->QR[$i][$k] /= $nrm;
74  }
75  $this->QR[$k][$k] += 1.0;
76  // Apply transformation to remaining columns.
77  for ($j = $k+1; $j < $this->n; ++$j) {
78  $s = 0.0;
79  for ($i = $k; $i < $this->m; ++$i) {
80  $s += $this->QR[$i][$k] * $this->QR[$i][$j];
81  }
82  $s = -$s/$this->QR[$k][$k];
83  for ($i = $k; $i < $this->m; ++$i) {
84  $this->QR[$i][$j] += $s * $this->QR[$i][$k];
85  }
86  }
87  }
88  $this->Rdiag[$k] = -$nrm;
89  }
90  } else {
92  }
93  } // function __construct()
if(! $in) print Initializing normalization quick check tables n
PHPExcel root directory.
Definition: Matrix.php:27
hypo($a, $b)
Definition: Maths.php:14
+ Here is the call graph for this function:

Member Function Documentation

◆ getH()

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.

116  {
117  for ($i = 0; $i < $this->m; ++$i) {
118  for ($j = 0; $j < $this->n; ++$j) {
119  if ($i >= $j) {
120  $H[$i][$j] = $this->QR[$i][$j];
121  } else {
122  $H[$i][$j] = 0.0;
123  }
124  }
125  }
126  return new PHPExcel_Shared_JAMA_Matrix($H);
127  } // function getH()
PHPExcel root directory.
Definition: Matrix.php:27

◆ getQ()

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.

156  {
157  for ($k = $this->n-1; $k >= 0; --$k) {
158  for ($i = 0; $i < $this->m; ++$i) {
159  $Q[$i][$k] = 0.0;
160  }
161  $Q[$k][$k] = 1.0;
162  for ($j = $k; $j < $this->n; ++$j) {
163  if ($this->QR[$k][$k] != 0) {
164  $s = 0.0;
165  for ($i = $k; $i < $this->m; ++$i) {
166  $s += $this->QR[$i][$k] * $Q[$i][$j];
167  }
168  $s = -$s/$this->QR[$k][$k];
169  for ($i = $k; $i < $this->m; ++$i) {
170  $Q[$i][$j] += $s * $this->QR[$i][$k];
171  }
172  }
173  }
174  }
175  /*
176  for($i = 0; $i < count($Q); ++$i) {
177  for($j = 0; $j < count($Q); ++$j) {
178  if(! isset($Q[$i][$j]) ) {
179  $Q[$i][$j] = 0;
180  }
181  }
182  }
183  */
184  return new PHPExcel_Shared_JAMA_Matrix($Q);
185  } // function getQ()
if(! $in) print Initializing normalization quick check tables n
PHPExcel root directory.
Definition: Matrix.php:27

◆ getR()

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.

135  {
136  for ($i = 0; $i < $this->n; ++$i) {
137  for ($j = 0; $j < $this->n; ++$j) {
138  if ($i < $j) {
139  $R[$i][$j] = $this->QR[$i][$j];
140  } elseif ($i == $j) {
141  $R[$i][$j] = $this->Rdiag[$i];
142  } else {
143  $R[$i][$j] = 0.0;
144  }
145  }
146  }
147  return new PHPExcel_Shared_JAMA_Matrix($R);
148  } // function getR()
PHPExcel root directory.
Definition: Matrix.php:27

◆ isFullRank()

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().

101  {
102  for ($j = 0; $j < $this->n; ++$j) {
103  if ($this->Rdiag[$j] == 0) {
104  return false;
105  }
106  }
107  return true;
108  } // function isFullRank()
+ Here is the caller graph for this function:

◆ solve()

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, isFullRank(), PHPExcel_Shared_JAMA_Matrix\MatrixDimensionException, and MatrixRankException.

194  {
195  if ($B->getRowDimension() == $this->m) {
196  if ($this->isFullRank()) {
197  // Copy right hand side
198  $nx = $B->getColumnDimension();
199  $X = $B->getArrayCopy();
200  // Compute Y = transpose(Q)*B
201  for ($k = 0; $k < $this->n; ++$k) {
202  for ($j = 0; $j < $nx; ++$j) {
203  $s = 0.0;
204  for ($i = $k; $i < $this->m; ++$i) {
205  $s += $this->QR[$i][$k] * $X[$i][$j];
206  }
207  $s = -$s/$this->QR[$k][$k];
208  for ($i = $k; $i < $this->m; ++$i) {
209  $X[$i][$j] += $s * $this->QR[$i][$k];
210  }
211  }
212  }
213  // Solve R*X = Y;
214  for ($k = $this->n-1; $k >= 0; --$k) {
215  for ($j = 0; $j < $nx; ++$j) {
216  $X[$k][$j] /= $this->Rdiag[$k];
217  }
218  for ($i = 0; $i < $k; ++$i) {
219  for ($j = 0; $j < $nx; ++$j) {
220  $X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k];
221  }
222  }
223  }
224  $X = new PHPExcel_Shared_JAMA_Matrix($X);
225  return ($X->getMatrix(0, $this->n-1, 0, $nx));
226  } else {
228  }
229  } else {
231  }
232  } // function solve()
isFullRank()
Is the matrix full rank?
PHPExcel root directory.
Definition: Matrix.php:27
const MatrixRankException
Definition: Error.php:57
+ Here is the call graph for this function:

Field Documentation

◆ $m

PHPExcel_Shared_JAMA_QRDecomposition::$m
private

Definition at line 33 of file QRDecomposition.php.

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

◆ $n

PHPExcel_Shared_JAMA_QRDecomposition::$n
private

Definition at line 39 of file QRDecomposition.php.

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

◆ $QR

PHPExcel_Shared_JAMA_QRDecomposition::$QR = array()
private

Definition at line 27 of file QRDecomposition.php.

◆ $Rdiag

PHPExcel_Shared_JAMA_QRDecomposition::$Rdiag = array()
private

Definition at line 45 of file QRDecomposition.php.

◆ MatrixRankException

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: