Created
November 24, 2016 01:09
-
-
Save felipecruz/cd86e4e03b55f9c9c9225014b8ccefdf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func MatrixCholeskyDecomposition(matrix Matrix) Matrix { | |
columns := matrix.cols() | |
rows := matrix.rows() | |
result_matrix := DenseZeros(rows, columns) | |
var val float64 | |
for i := 0; i < rows; i++ { | |
for j := 0; j <= i; j++ { | |
accumulator := 0. | |
for k := 0; k < j; k++ { | |
accumulator += result_matrix.at(i, k) * result_matrix.at(j, k) | |
} | |
if i == j { | |
val = math.Sqrt(matrix.at(i, j) - accumulator) | |
} else if j < i { | |
val = (matrix.at(i, j) - accumulator) / result_matrix.at(j, j) | |
} | |
result_matrix.set(i, j, val) | |
} | |
} | |
return result_matrix | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment