Skip to content

Instantly share code, notes, and snippets.

View matt-graham's full-sized avatar

Matt Graham matt-graham

View GitHub Profile
@matt-graham
matt-graham / adaptive_rwm.py
Created January 26, 2024 10:59
Adaptive Gaussian random-walk Metropolis with Mici
import numpy as np
import mici
def get_rwm_sampler_and_adapters(
neg_log_posterior_density, rng, target_accept_stat=0.234
):
"""Get a Mici sampler and adapters for adaptive Gaussian random-walk Metropolis proposals."""
system = mici.systems.EuclideanMetricSystem(
neg_log_dens=neg_log_posterior_density,
grad_neg_log_dens=lambda q: q * 0,
@matt-graham
matt-graham / block_diagonal_kernel.py
Created December 13, 2023 16:16
Sketching out block diagonal kernel implementation in GPJax for Kennedy & O'Hagan calibration framework
from collections.abc import Iterator
from dataclasses import dataclass
from cola import PSD
from cola.ops import BlockDiag, LinearOperator
from gpjax.base import static_field
from gpjax.kernels import AbstractKernel
from gpjax.kernels.computations.base import AbstractKernelComputation, Kernel
from gpjax.kernels.computations import DenseKernelComputation
from gpjax.typing import Array, ScalarFloat
@matt-graham
matt-graham / sparse_summation_benchmarks.py
Last active July 1, 2021 15:40
Comparison of different approaches to summing dict values with 'sparse' keys.
"""Comparison of different approaches to summing dict values with 'sparse' keys.
Sparse here means the keys of all dicts are drawn from a common set but only a few
keys (compared to the total number) are present in each.
"""
import pandas as pd
import numpy as np
import timeit
from string import ascii_lowercase
@matt-graham
matt-graham / Visualising-UKCP18-Probabilistic-Projections-data.ipynb
Last active June 1, 2021 10:18
Interactive visualisation of UKCP18 Probabilistic Projections
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matt-graham
matt-graham / generate_nag_subroutine_list.py
Created April 15, 2021 15:26
Print formatted Markdown list of all NAG subroutines in a source tree
"""Print formatted Markdown list of all NAG subroutines in a source tree"""
import re
import argparse
import pathlib
from itertools import groupby
parser = argparse.ArgumentParser(
description="Generate Markdown list of NAG subroutines used in source tree."
)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matt-graham
matt-graham / Reversibility-of-constrained-integrators.ipynb
Created July 5, 2020 17:48
Notebook showing time-reversibility of constrained integrators
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matt-graham
matt-graham / Is_the_NUTS_algorithm_correct_Sanz-Serna_2020.ipynb
Last active May 6, 2020 08:56
Follow up to experiments in 'Is the NUTS algorithm correct?' (Sanz-Serna, 2020; arXiv 2005.01336)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matt-graham
matt-graham / data_providers.py
Created January 22, 2017 15:20
CIFAR data providers
import cPickle
import gzip
import numpy as np
import os
DEFAULT_SEED = 1234
class DataProvider(object):
"""Generic data provider."""
@matt-graham
matt-graham / student-t-conditioned-on-loc-param-mle.ipynb
Last active November 17, 2016 17:40
Jupyter notebook running constrained HMC to sample from joint Student-t density conditioned on a fixed MLE of location parameter.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.