Skip to content

Instantly share code, notes, and snippets.

@mattpitkin
mattpitkin / roqupdatetest.py
Last active December 22, 2017 15:30
Testing ROQ update
from __future__ import print_function, division
import numpy as np
from scipy.signal import fftconvolve
import subprocess as sp
import os
import sys
import gzip
import h5py
from time import time
@mattpitkin
mattpitkin / gsl_integrate_kde.pyx
Last active May 22, 2017 09:48
Using GSL integration functions in Cython when integrating a KDE function obtained from samples
"""
Example of integration of a function f(x) (for which a set of samples and integral estimate exist
e.g. through use of the Nested Sampling algorithm) multiplied by some other function g(x). NOTE: one
could use the expectatation value for this, but in some cases where there is sparse sampling over
the full allowed range of the function can cause problems.
The samples are passed through a KDE and then the kde object is passed to the GSL CQUAD
integration function
This requires the Cython, numpy, scikit-learn (v0.18 or greater) and the GSL library.
@mattpitkin
mattpitkin / plotoutside.py
Last active May 18, 2017 15:44
Example for producing a contour plot and also plotting the points outside the outer contour
import numpy as np
from matplotlib import pyplot as pl
x = np.random.randn(5000)
y = 0.2*np.random.randn(5000) + 3
xbins = 20
ybins = 20
H, xedges, yedges = np.histogram2d(x, y, bins=(xbins, ybins))