// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // // Copyright (c) 2009-2013 Math.NET // // 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. // using System; namespace IStation.Numerics.LinearAlgebra.Factorization { /// /// A class which encapsulates the functionality of a Cholesky factorization. /// For a symmetric, positive definite matrix A, the Cholesky factorization /// is an lower triangular matrix L so that A = L*L'. /// /// /// The computation of the Cholesky factorization is done at construction time. If the matrix is not symmetric /// or positive definite, the constructor will throw an exception. /// /// Supported data types are double, single, , and . public abstract class Cholesky : ISolver where T : struct, IEquatable, IFormattable { protected Cholesky(Matrix factor) { Factor = factor; } /// /// Gets the lower triangular form of the Cholesky matrix. /// public Matrix Factor { get; private set; } /// /// Gets the determinant of the matrix for which the Cholesky matrix was computed. /// public abstract T Determinant { get; } /// /// Gets the log determinant of the matrix for which the Cholesky matrix was computed. /// public abstract T DeterminantLn { get; } /// /// Calculates the Cholesky factorization of the input matrix. /// /// The matrix to be factorized. public abstract void Factorize(Matrix matrix); /// /// Solves a system of linear equations, AX = B, with A Cholesky factorized. /// /// The right hand side , B. /// The left hand side , X. public virtual Matrix Solve(Matrix input) { var x = Matrix.Build.SameAs(input, input.RowCount, input.ColumnCount, fullyMutable: true); Solve(input, x); return x; } /// /// Solves a system of linear equations, AX = B, with A Cholesky factorized. /// /// The right hand side , B. /// The left hand side , X. public abstract void Solve(Matrix input, Matrix result); /// /// Solves a system of linear equations, Ax = b, with A Cholesky factorized. /// /// The right hand side vector, b. /// The left hand side , x. public virtual Vector Solve(Vector input) { var x = Vector.Build.SameAs(input, input.Count); Solve(input, x); return x; } /// /// Solves a system of linear equations, Ax = b, with A Cholesky factorized. /// /// The right hand side vector, b. /// The left hand side , x. public abstract void Solve(Vector input, Vector result); } }