mikera.matrixx.decompose.impl.chol.CholeskyHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vectorz Show documentation
Show all versions of vectorz Show documentation
Fast double-precision vector and matrix maths library for Java, supporting N-dimensional numeric arrays.
/*
* Copyright (c) 2009-2013, Peter Abeles. All Rights Reserved.
*
* This file is part of Efficient Java Matrix Library (EJML).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package mikera.matrixx.decompose.impl.chol;
import mikera.matrixx.AMatrix;
import mikera.matrixx.Matrix;
/**
* A specialized Cholesky decomposition algorithm that is designed to help out
* {@link CholeskyDecompositionBlock} perform its calculations. While decomposing
* the matrix it will modify its internal lower triangular matrix and the original
* that is being modified.
*
* @author Peter Abeles
*/
public class CholeskyHelper {
// the decomposed matrix
private Matrix L;
private double[] el;
/**
* Creates a CholeksyDecomposition capable of decomposing a matrix that is
* n by n, where n is the width.
*
* @param widthMax The maximum width of a matrix that can be processed.
*/
public CholeskyHelper(int widthMax ) {
this.L = Matrix.create(widthMax,widthMax);
this.el = L.data;
}
/**
* Decomposes a submatrix. The results are written to the submatrix
* and to its internal matrix L.
*
* @param mat A matrix which has a submatrix that needs to be inverted
* @param indexStart the first index of the submatrix
* @param n The width of the submatrix that is to be inverted.
* @return True if it was able to finish the decomposition.
*/
public boolean decompose( AMatrix mat , int indexStart , int n ) {
double m[] = mat.toMatrix().data;
double el_ii;
double div_el_ii=0;
for( int i = 0; i < n; i++ ) {
for( int j = i; j < n; j++ ) {
double sum = m[indexStart+i*mat.rowCount()+j];
int iEl = i*n;
int jEl = j*n;
int end = iEl+i;
// k = 0:i-1
for( ; iEl
* L*LT=A
*
* @return A lower triangular matrix.
*/
public AMatrix getL() {
return L;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy