ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
CholeskyDecomposition Class Reference
+ Collaboration diagram for CholeskyDecomposition:

Public Member Functions

 __construct ($A=null)
 CholeskyDecomposition. More...
 
 isSPD ()
 Is the matrix symmetric and positive definite? More...
 
 getL ()
 getL More...
 
 solve ($B=null)
 Solve A*X = B. More...
 

Private Attributes

 $L = array()
 
 $m
 
 $isspd = true
 

Detailed Description

Definition at line 18 of file CholeskyDecomposition.php.

Constructor & Destructor Documentation

◆ __construct()

CholeskyDecomposition::__construct (   $A = null)

CholeskyDecomposition.

Class constructor - decomposes symmetric positive definite matrix

Parameters
mixedMatrix square symmetric positive definite matrix

Definition at line 48 of file CholeskyDecomposition.php.

References $i, $m, ArgumentTypeException, and JAMAError().

48  {
49  if ($A instanceof Matrix) {
50  $this->L = $A->getArray();
51  $this->m = $A->getRowDimension();
52 
53  for($i = 0; $i < $this->m; ++$i) {
54  for($j = $i; $j < $this->m; ++$j) {
55  for($sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; --$k) {
56  $sum -= $this->L[$i][$k] * $this->L[$j][$k];
57  }
58  if ($i == $j) {
59  if ($sum >= 0) {
60  $this->L[$i][$i] = sqrt($sum);
61  } else {
62  $this->isspd = false;
63  }
64  } else {
65  if ($this->L[$i][$i] != 0) {
66  $this->L[$j][$i] = $sum / $this->L[$i][$i];
67  }
68  }
69  }
70 
71  for ($k = $i+1; $k < $this->m; ++$k) {
72  $this->L[$i][$k] = 0.0;
73  }
74  }
75  } else {
77  }
78  } // function __construct()
JAMAError($errorNumber=null)
Custom error handler.
Definition: Error.php:70
const ArgumentTypeException
Definition: Error.php:29
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:

Member Function Documentation

◆ getL()

CholeskyDecomposition::getL ( )

getL

Return triangular factor.

Returns
Matrix Lower triangular matrix

Definition at line 97 of file CholeskyDecomposition.php.

97  {
98  return new Matrix($this->L);
99  } // function getL()

◆ isSPD()

CholeskyDecomposition::isSPD ( )

Is the matrix symmetric and positive definite?

Returns
boolean

Definition at line 86 of file CholeskyDecomposition.php.

References $isspd.

86  {
87  return $this->isspd;
88  } // function isSPD()

◆ solve()

CholeskyDecomposition::solve (   $B = null)

Solve A*X = B.

Parameters
$BRow-equal matrix
Returns
Matrix L * L' * X = B

Definition at line 108 of file CholeskyDecomposition.php.

References $i, $m, ArgumentTypeException, JAMAError(), MatrixDimensionException, and MatrixSPDException.

108  {
109  if ($B instanceof Matrix) {
110  if ($B->getRowDimension() == $this->m) {
111  if ($this->isspd) {
112  $X = $B->getArrayCopy();
113  $nx = $B->getColumnDimension();
114 
115  for ($k = 0; $k < $this->m; ++$k) {
116  for ($i = $k + 1; $i < $this->m; ++$i) {
117  for ($j = 0; $j < $nx; ++$j) {
118  $X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
119  }
120  }
121  for ($j = 0; $j < $nx; ++$j) {
122  $X[$k][$j] /= $this->L[$k][$k];
123  }
124  }
125 
126  for ($k = $this->m - 1; $k >= 0; --$k) {
127  for ($j = 0; $j < $nx; ++$j) {
128  $X[$k][$j] /= $this->L[$k][$k];
129  }
130  for ($i = 0; $i < $k; ++$i) {
131  for ($j = 0; $j < $nx; ++$j) {
132  $X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
133  }
134  }
135  }
136 
137  return new Matrix($X, $this->m, $nx);
138  } else {
140  }
141  } else {
143  }
144  } else {
146  }
147  } // function solve()
JAMAError($errorNumber=null)
Custom error handler.
Definition: Error.php:70
const MatrixDimensionException
Definition: Error.php:39
const MatrixSPDException
Definition: Error.php:49
const ArgumentTypeException
Definition: Error.php:29
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:

Field Documentation

◆ $isspd

CholeskyDecomposition::$isspd = true
private

Definition at line 39 of file CholeskyDecomposition.php.

Referenced by isSPD().

◆ $L

CholeskyDecomposition::$L = array()
private

Definition at line 25 of file CholeskyDecomposition.php.

◆ $m

CholeskyDecomposition::$m
private

Definition at line 32 of file CholeskyDecomposition.php.

Referenced by __construct(), and solve().


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