Skip to content

Instantly share code, notes, and snippets.

@Alrecenk
Last active December 23, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alrecenk/6666615 to your computer and use it in GitHub Desktop.
Save Alrecenk/6666615 to your computer and use it in GitHub Desktop.
A basic LDL decomposition of a matrix X times its transpose.
double[][] L = new double[inputs][ inputs];
double D[] = new double[inputs] ;
//for each column j
for (int j = 0; j < inputs; j++){
D[j] = XTX[j][j];//calculate Dj
for (int k = 0; k < j; k++){
D[j] -= L[j][k] * L[j][k] * D[k];
}
//calculate jth column of L
L[j][j] = 1 ; // don't really need to save this but its a 1
for (int i = j + 1; i < inputs; i++){
L[i][j] = XTX[i][j];
for (int k = 0; k < j; k++){
L[i][j] -= L[i][k] * L[j][k] * D[k];
}
L[i][j] /= D[j];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment