Skip to content

Instantly share code, notes, and snippets.

@ibab
ibab / minitensor.cc
Last active November 19, 2016 11:33
#include <array>
#include <iostream>
#include <vector>
template <typename T,
// Number of dimensions of tensor.
int D>
class Tensor {
public:
template <typename... T2,
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ibab
ibab / Balanced and Unbalanced Datasets.ipynb
Last active February 21, 2016 10:14 — forked from betatim/Balanced and Unbalanced Datasets.ipynb
Balanced or unbalanced? Does it make a difference for a tree based classifier if the two classes are balanced or not?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ibab
ibab / simple_fit.py
Created February 10, 2016 17:19
Simple fit with tensorflow
import numpy as np
import tensorflow as tf
from scipy.optimize import minimize
import matplotlib
matplotlib.use('PDF')
import matplotlib.pyplot as plt
# Generate dataset
data = np.random.normal(0, 1, 1000)
@ibab
ibab / mle_tf.py
Created February 2, 2016 10:01
TensorFlow simple MLE example
import numpy as np
import tensorflow as tf
sess = tf.Session()
TYPE=np.float64
N = 1000000
data = np.random.normal(0, 1, N).astype(TYPE)
@ibab
ibab / grid.py
Last active January 13, 2016 17:40
Faster grid submission using async
from __future__ import print_function
import gevent
import gevent.queue
import gevent.pool
import gevent.subprocess
import gevent.monkey
gevent.monkey.patch_all()
@ibab
ibab / mergelists.hs
Last active August 29, 2015 14:15
Merge sorted sublists into sorted list
merge [] ys = ys
merge xs [] = xs
merge xs@(x:xt) ys@(y:yt) | x <= y = x : merge xt ys
| otherwise = y : merge xs yt
mergeLists [] = []
mergeLists [x] = [x]
mergeLists (x:y:rest) = mergeLists $ (merge x y) : mergeLists rest
ll = [[1,2,3], [1,3,6], [1, 10], [3,3,3], [1], [1,1,1,5]]
@ibab
ibab / root_pandas.py
Created January 16, 2015 13:12
Convenience wrappers for loading a ROOT file into a pandas DataFrame
def get_matching_variables(fname, tree, patterns):
from fnmatch import fnmatch
from root_numpy import list_branches
branches = list_branches(fname, tree)
selected = []
for p in patterns:
for b in branches:
@ibab
ibab / oscillation.py
Last active August 29, 2015 14:11
Plot of neutrino oscillation probabilities using newest NuFit data.
import numpy as np
# normal ordering values from NuFit 2.0, JHEP 11 (2014) 052 [arXiv:1409.5439]
θ_12 = np.deg2rad(33.48)
θ_23 = np.deg2rad(42.3)
θ_13 = np.deg2rad(8.50)
δ_CP = np.deg2rad(306)
Δm21 = np.sqrt(7.50e-5) # eV^2
Δm31 = np.sqrt(2.449e-3) # eV^2
@ibab
ibab / enum_strings.h
Created June 18, 2014 18:52
A macro that allows you to create an enum with toString and fromString conversion functions defined automatically for you.
#ifndef ENUMS_H
#define ENUMS_H
#include <boost/preprocessor.hpp>
#include <string>
/*
* The following macros allow you to define an enum and get `toString`
* and `fromString` functions generated automatically.
* If you use