Skip to content

Instantly share code, notes, and snippets.

View kbarbary's full-sized avatar

Kyle Barbary kbarbary

View GitHub Profile
@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
# 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 / 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 / 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 / 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
@kbarbary
kbarbary / animate_source.py
Last active November 14, 2016 03:45
animate_source function for sncosmo
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Animate one or more sncosmo Source spectral time series."""
from __future__ import division
import math
import numpy as np
from astropy.utils.misc import isiterable
from astropy.extern import six
@kbarbary
kbarbary / sample-and-plot.ipynb
Created December 9, 2013 22:15
sncosmo lightcurve MCMC example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kbarbary
kbarbary / simulation.py
Created October 15, 2013 16:30
sncosmo simulation function example. This is just a preliminary working function that simulates SN data.
"""Tools for simulation of transients."""
import sys
import math
from copy import deepcopy
import numpy as np
from scipy.interpolate import InterpolatedUnivariateSpline as Spline1d
from astropy.table import Table
from astropy import cosmology
{
"metadata": {
"name": "Introduction"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{