All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ojalgo.matrix.decomposition.Cholesky Maven / Gradle / Ivy

Go to download

oj! Algorithms - ojAlgo - is Open Source Java code that has to do with mathematics, linear algebra and optimisation.

There is a newer version: 55.0.1
Show newest version
/*
 * Copyright 1997-2022 Optimatika
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.ojalgo.matrix.decomposition;

import org.ojalgo.array.DenseArray;
import org.ojalgo.matrix.store.MatrixStore;
import org.ojalgo.scalar.ComplexNumber;
import org.ojalgo.scalar.Quaternion;
import org.ojalgo.scalar.RationalNumber;
import org.ojalgo.structure.Access2D;
import org.ojalgo.type.context.NumberContext;

/**
 * 

* Cholesky: [A] = [L][L]H (or [R]H[R]) *

*

* [A]H = [A] = [L][L]H *

*

* If [A] is symmetric and positive definite then the general LU decomposition - [P][L][D][U] - becomes * [I][L][D][L]T (or [I][U]T[D][U]). [I] can be left out and [D] is normally split in * halves and merged with [L] (and/or [U]). We'll express it as [A] = [L][L]T. *

*

* A cholesky decomposition is still/also an LU decomposition where [P][L][D][U] => [L][L]T. *

* * @author apete */ public interface Cholesky> extends LDU, MatrixDecomposition.Hermitian { interface Factory> extends MatrixDecomposition.Factory> { } Factory COMPLEX = typical -> new CholeskyDecomposition.Complex(); Factory PRIMITIVE = typical -> { if ((32L < typical.countColumns()) && (typical.count() <= DenseArray.MAX_ARRAY_SIZE)) { return new CholeskyDecomposition.Primitive(); } else { return new RawCholesky(); } }; Factory QUATERNION = typical -> new CholeskyDecomposition.Quat(); Factory RATIONAL = typical -> new CholeskyDecomposition.Rational(); static > boolean equals(final MatrixStore matrix, final Cholesky decomposition, final NumberContext context) { boolean retVal = false; final MatrixStore tmpL = decomposition.getL(); retVal = Access2D.equals(tmpL.multiply(tmpL.conjugate()), matrix, context); return retVal; } /** * Must implement either {@link #getL()} or {@link #getR()}. */ default MatrixStore getL() { return this.getR().conjugate(); } /** * Must implement either {@link #getL()} or {@link #getR()}. */ default MatrixStore getR() { return this.getL().conjugate(); } /** * To use the Cholesky decomposition rather than the LU decomposition the matrix must be symmetric and * positive definite. It is recommended that the decomposition algorithm checks for this during * calculation. Possibly the matrix could be assumed to be symmetric (to improve performance) but tests * should be made to assure the matrix is positive definite. * * @return true if the tests did not fail. */ boolean isSPD(); default MatrixStore reconstruct() { final MatrixStore mtrxL = this.getL(); return mtrxL.multiply(mtrxL.conjugate()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy