Skip to content

Instantly share code, notes, and snippets.

View Chechgm's full-sized avatar

Sergio Garrido Chechgm

View GitHub Profile
@Chechgm
Chechgm / LinearIterations.py
Created February 18, 2026 08:47
Linear iteration methods to find solutions to systems of linear equations based on Banach's fixed point Theorem
"""
Simple script implementing the Banach fixed point Theorem applied to iterations in linear equation models.
In particular, I implement the Jacobi iteration and the Gauss-Seidel iteration.
The implementation of this script follows the theory in Chapter 5.2 of Kreyszig's "Introductory functional analysis with applications".
The architecture is based on a super class "LinearIteration" which implements the methods common to all linear iteration
methods, and then we have the JacobiIteration and GaussSeidelIteration which simply implements the initialisation
of the iteration matrix and vector.
@Chechgm
Chechgm / HMC.py
Last active February 17, 2026 13:39
Implementation for advanced MCMC methods: HMC and particle MCMC
""" Short script showcasing Hamiltonian Monte Carlo (HMC)
I used JAX as a backend to estimate the negative log posterior,
and the gradients of it with respect to our parameters of interest.
In addition, I added a function to validate the inference from the method:
bayesian_fraction_missing_information which estimates the E-BFMI.
The assumed model is a simple linear regression:
beta_i ~ Normal(0,1)