Skip to content

SENATOROVAI/cholesky-decomposition-solver-course

Repository files navigation

Cholesky Decomposition Solver β€” Course & Implementation

License Python Website PRs Welcome DOI Code Style Pre-commit

πŸš€ Professional course project for understanding and implementing Cholesky Decomposition from scratch in Python.


πŸ”₯ Project Overview

This repository provides a complete implementation and mathematical explanation of Cholesky Decomposition for symmetric positive definite matrices.

It includes:

  • Mathematical derivation
  • Algorithm explanation
  • Python implementation from scratch
  • Numerical stability discussion
  • Practical applications in linear systems

Keywords


cholesky decomposition
cholesky factorization
cholesky solver python
matrix decomposition
numerical linear algebra
positive definite matrix
linear system solver
linalg cholesky from scratch
least squares optimization
python cholesky implementation


πŸ“š Mathematical Definition

For a symmetric positive definite matrix:

$$ A \in \mathbb{R}^{n \times n} $$

Cholesky decomposition states:

$$ A = LL^T $$

Where:

  • $$L$$ β€” lower triangular matrix
  • $$L^T$$ β€” transpose of $$L$$

Condition:

$$ A = A^T $$

and

$$ x^T A x > 0 \quad \forall x \neq 0 $$


🧠 Elementwise Formula

The elements of matrix $$L$$ are computed as:

For diagonal:

$$ L_{ii} = \sqrt{A_{ii} - \sum_{k=1}^{i-1} L_{ik}^2} $$

For off-diagonal:

$$ L_{ij} = \frac{1}{L_{jj}} \left( A_{ij} - \sum_{k=1}^{j-1} L_{ik} L_{jk} \right) $$


⚑ Applications

Cholesky decomposition is used in:

  • Solving linear systems
  • Gaussian processes
  • Bayesian statistics
  • Optimization
  • Covariance matrix factorization
  • Machine learning models

It is computationally cheaper than LU for SPD matrices.


πŸ— Project Structure


cholesky-decomposition-solver/
β”‚
β”œβ”€β”€ README.md
β”œβ”€β”€ LICENSE
β”œβ”€β”€ requirements.txt
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ cholesky.py
β”‚   β”œβ”€β”€ solver.py
β”‚
β”œβ”€β”€ examples/
β”‚   └── demo.py
β”‚
β”œβ”€β”€ docs/
β”‚   └── theory.md
β”‚
β”œβ”€β”€ images/
β”‚   └── factorization.png
β”‚
└── index.html

Clean structure improves:

βœ” Professional appearance
βœ” Search visibility
βœ” Educational clarity


🐍 Example Implementation

Basic Cholesky Algorithm

import numpy as np

def cholesky_decomposition(A):
    A = A.astype(float)
    n = A.shape[0]
    L = np.zeros_like(A)

    for i in range(n):
        for j in range(i + 1):
            s = sum(L[i, k] * L[j, k] for k in range(j))

            if i == j:
                L[i, j] = np.sqrt(A[i, i] - s)
            else:
                L[i, j] = (A[i, j] - s) / L[j, j]

    return L

πŸš€ Installation

pip install -r requirements.txt

Run example:

python examples/demo.py

About

Cholesky decomposition is a matrix factorization method that decomposes a symmetric, positive-definite matrix into the product of a lower triangular matrix and its transpose (i.e., ). LU decomposition for solving linear equations and is widely used in Monte Carlo simulations, Kalman filters, and econometrics. Solver

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

17 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages