Skip to content

Instantly share code, notes, and snippets.

View philastrophist's full-sized avatar

Shaun Read philastrophist

View GitHub Profile
from __future__ import division
import pymc3 as pm
import numpy as np
from theano import tensor as T
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import seaborn as sns
@philastrophist
philastrophist / models.py
Last active January 20, 2019 13:18
EM with low cutoff
from functools import partial
from itertools import cycle
import numpy as np
from astroML.density_estimation import XDGMM
import pytest
from matplotlib.patches import Ellipse
def no_selection(x):
@philastrophist
philastrophist / estimation.py
Last active April 26, 2022 13:07
HPD estimation
#! encoding=<utf8>
from __future__ import division
import numpy as np
from fastkde import fastKDE
from warnings import warn
__all__ = ['find_mode']
def make_indices(dimensions):
@philastrophist
philastrophist / fit_carma.py
Last active October 17, 2019 12:27
CARMA(2, 1) model for reprocessed Kepler lightcurves
import os
import sys
import kali.carma
from kali.kepler import keplerLC
import math as math
import numpy as np
import matplotlib
matplotlib.rcParams['text.usetex'] = False
@philastrophist
philastrophist / fetch_tree.adoc
Created September 21, 2020 14:52 — forked from jexp/fetch_tree.adoc
Fetch a Tree with Neo4j

Fetch a Tree with Neo4j

Today I came across a really interesting StackOverflow question:

Given a forest of trees in a Neo4j REST server, I`m trying to return a single tree given the root vertex. Being each tree quite large, I need a de-duplicated list of all vertices and edges in order to be able to reconstruct the full tree on the client side.

import emcee
from sklearn.mixture import GaussianMixture
import vegas
from astropy.cosmology import Planck15
import numpy as np
from scipy import stats
from astropy import units as u
import matplotlib.pyplot as plt
jy_factor = (u.W / u.Hz / u.m / u.m).to(u.Jy)
@philastrophist
philastrophist / fraction_uncertainties.py
Last active April 1, 2022 11:07
fraction_uncertainties
def asymmetric_fractional_error_bars(n, total, mass=0.68, centre='peak'):
"""
returns the error bar for the fraction $x = n/total$ ($f^{+upper}_{-lower}$)
Use `mass` to specify the errorbar width
n: number of successes
total: total number of trials
:mass: the desired probability mass contained with the error bar
default=68%, which is ~equivalent to 1 sigma
:centre: return either the 'mean', 'median', or most likely of the probability distribution.
Probably you want 'peak' which is equivalent to n / total