Skip to content

Instantly share code, notes, and snippets.

View lukedeo's full-sized avatar

Luke de Oliveira lukedeo

View GitHub Profile
import rootpy
from rootpy.io import root_open
from rootpy.tree import Tree, TreeChain
# -- Let me real quick grab a nasty d3pd
f = root_open('user.dguest.050909._00001.skim-output.root')
# -- Yank that tree out of there...
T = f['physics']
@lukedeo
lukedeo / top-tagging-plots.py
Created April 9, 2014 05:18
Performance Plotting for Top Tagging
import numpy as np
import math
import matplotlib.pyplot as plt
import matplotlib.tri as tri
from matplotlib.mlab import griddata
from matplotlib import rc
import numpy.ma as ma
def data_load(filename):
data = np.genfromtxt(filename, delimiter = ',', names = True)
@lukedeo
lukedeo / TrainingHandler.py
Created May 12, 2015 23:43
Context based SIGINT handler
class TrainingHandler(object):
def __init__(self, sig=signal.SIGINT):
self.sig = sig
def __enter__(self):
self.interrupted = False
self.released = False
self.original_handler = signal.getsignal(self.sig)
def handler(signum, frame):
self.release()
@lukedeo
lukedeo / setup.py
Last active October 29, 2015 21:52
Setuptools Boilerplate
from setuptools import setup
from setuptools import find_packages
setup(
name='NewPackage',
version='0.0.1',
description='Library for doing a thing.',
author='Luke de Oliveira',
author_email='[email protected]',
url='https://github.com/lukedeo/repo',
@lukedeo
lukedeo / bootstrap.sh
Last active February 21, 2018 16:55
Bootstrap script for Ubuntu 14.04 EC2
#!/usr/bin/env bash
# bootstrap.sh
# author: Luke de Oliveira ([email protected])
# boostrap script for clean (CPU) EC2 instance setup for machine learning.
# -- get a basic build up
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install -y build-essential
# -- dev builds of key software
@lukedeo
lukedeo / savekeras.py
Created December 20, 2015 00:28
Saving a Keras model.
'''
hacked out deepdish.io style keras NN saving functionality
[credit] deepdish
'''
from __future__ import division, print_function, absolute_import
import numpy as np
import tables
import warnings
@lukedeo
lukedeo / jet.py
Created January 17, 2016 18:23
Better jet object
from rootpy.vector import LorentzVector
class Jet(object):
"""
Better Jet Class!
Example:
>>> j = Jet(100.1, 1.2, 1.0, 12)
>>> j.lv.Pt()
@lukedeo
lukedeo / ndweights.py
Created March 3, 2016 08:51
A class to do n-dimensional reweighting
import numpy as np
class NDWeights(object):
'''
An n-dimension reweighting object
'''
def __init__(self, bins):
'''
Constructor for weighting
@lukedeo
lukedeo / weight_init.py
Last active March 7, 2016 18:31
Custom initializer for Keras
import keras.backend as K
import numpy as np
def custom_uniform(shape, range=(-1, 1), name=None):
min_, max_ = range
return K.variable(np.random.uniform(low=min_, high=max_, size=shape), name=name)
net.add(Dense(10, input_dim=5, init=lambda shape, name: custom_uniform(shape, (-10, 5), name)))
@lukedeo
lukedeo / rcnnchar.py
Created April 22, 2016 17:22
heard u liek to cnn
# import csv
# import os
# import numpy as np
# from cervantes.box import WordVectorBox
# from cervantes.language import OneLevelEmbedding
# from cervantes.nn.models import RNNClassifier
# from cervantes.box import EnglishCharBox
from keras.models import Model, Sequential