Skip to content

Instantly share code, notes, and snippets.

View kbarbary's full-sized avatar

Kyle Barbary kbarbary

View GitHub Profile
@kbarbary
kbarbary / deepnn.py
Created February 27, 2018 16:39
What does a minimal implementation of a multi-layer dense neural net (with backpropagation) look like?
"""A minimal implementation of a dense neural net with an arbitrary
number of layers, backpropagation, and a few different activation functions."""
import numpy as np
# Activation and cost functions (with gradients)
def sigmoid(x):
y = 1.0 / (1.0 + np.exp(-x))
return y, y * (1.0 - y)
@kbarbary
kbarbary / cpptest.pyx
Created May 11, 2017 15:29
Example: Using cython, convert numpy.ndarray to C++ std::valarray and back (using copies)
"""example of converting a numpy array to a C++ valarray and back in cython
using copies.
Compile with `python setup.py build_ext --inplace`
Example
-------
>>> import cpptest, numpy as np
>>> x = np.array([0., 1., 2.])
@kbarbary
kbarbary / dm15source.py
Created March 3, 2017 21:00
SN Ia model from Sako et al (2008)
"""sncosmo Source implementing the "dm15" model from Sako et al (2008).
Example::
>>> import sncosmo
>>> import dm15source
>>> model = sncosmo.Model(source='dm15')
>>> model.set(z=0.5, t0=55000., amplitude=1e-10, dm15=0.9)
>>> model.bandmag('sdssi', 'ab', 55011.5)
24.661108429127694
# Split MIRI transmissions into separate files. Original file was
# http://ircamera.as.arizona.edu/MIRI/ImPCE_TN-00072-ATC-Iss2.xlsx
# saved as CSV.
import numpy as np
data = np.loadtxt("ImPCE_TN-00072-ATC-Iss2.csv", skiprows=2)
bands = ("F560W F770W F1000W F1280W F1130W F1500W F1800W F2100W F2550W"
.lower().split())
@kbarbary
kbarbary / simd-vmv.c
Created October 8, 2016 18:29
Vector-matrix-vector multiplication with SIMD (AVX) intrinsics
// Doing the operation:
//
// | a a a a | | y |
// x * A * y = [ x x x x ] | a a a a | | y |
// | a a a a | | y |
// | a a a a | | y |
//
// with SIMD intrinics (specifically AVX).
//
// adapted from https://gist.github.com/rygorous/4172889
@kbarbary
kbarbary / estimated_ellipsoid_test.ipynb
Created November 3, 2015 13:41
Testing bounding ellipsoid in nestle
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kbarbary
kbarbary / rubin_pgm.py
Created September 23, 2015 00:36
PGM for Rubin et al 2015 (http://arxiv.org/abs/1507.01602)
#!/usr/bin/env python
from matplotlib import rc
from daft import PGM, Node, Plate
rc("font", family="serif", size=12)
rc("text", usetex=True)
pgm = PGM([7.65, 5.3], origin=[0., -0.2], observed_style='inner')
@kbarbary
kbarbary / refine_ellipsoids.py
Last active September 8, 2015 17:26
Ellipsoid refinement code for Nestle
def ellipsoid_dist_sq(x, ell):
"""Return the square of each point's distance from the ellipsoid center,
relative to ellipsoid boundary.
Refered to in Feroz, Hobson & Bridges (2009) as the Mahalanobis distance.
Parameters
----------
x : `~numpy.ndarray`
Points, array with shape (npoints, ndim).
@kbarbary
kbarbary / for_owen.ipynb
Created May 18, 2015 19:32
Some calculus for Owen
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kbarbary
kbarbary / sep-demo.ipynb
Created April 21, 2015 10:30
Quick demo of SEP
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.