Skip to content

Instantly share code, notes, and snippets.

View aminnj's full-sized avatar

Nick Amin aminnj

  • Austin, TX
View GitHub Profile
@aminnj
aminnj / capacity.py
Created April 10, 2019 19:36
nn capacity
import numpy as np
# number of nodes per layer
nodes = np.array([2,3,4])
# upper bound on capacity according to eq 1.1 of https://arxiv.org/pdf/1901.00434.pdf
# pairwise product of nodes weighted by the minimum layer width up to that point
capacity = np.sum(np.minimum.accumulate(nodes)[:-1]*nodes[:-1]*nodes[1:])
print(capacity)
# a fully connected arch with equal number of nodes per layer will have a capacity
# that scales linearly with the total matrix multiplication time (is this true?)
@aminnj
aminnj / character_widths.html
Last active November 22, 2018 00:07
javascript to measure character widths in semi-hacky way
<html>
<head>
<style>
body {
font: small/1.5 Arial,Helvetica,sans-serif;
letter-spacing: normal;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
@aminnj
aminnj / parse_takeout.py
Last active October 29, 2018 01:59
Parse most of google takeout data into a single dataframe
import json
import numpy as np
import pandas as pd
pd.set_option('display.width', None)
def get_dfs(which=["android","assistant","chrome","gmail","playstore","image","maps","search","voice","location"]):
dfs = {}
def get_fname(name):
if "Location History" in name:
return "Takeout/Location History/Location History.json"
@aminnj
aminnj / excel.py
Last active September 30, 2018 22:28
excel-themed matplotlib plots
import os
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
# matplotlib.font_manager._rebuild() # after installing calibri
from matplotlib import rcParams
from cycler import cycler
@aminnj
aminnj / install_gpuxgboost.sh
Created September 23, 2018 00:41
installing xgboost with gpu support on uaf-1
# main instructions from https://xgboost.readthedocs.io/en/latest/build.html#building-with-gpu-support
# first install cmake somewhere
curl -O -L https://cmake.org/files/v3.12/cmake-3.12.0-Linux-x86_64.tar.gz
tar xf cmake*.tar.gz
cd cmake*/
export CMAKE_ROOT=`pwd`
# get 10X environment for slc7
cd /cvmfs/cms.cern.ch/slc7_amd64_gcc630/cms/cmssw/CMSSW_10_2_0_pre6/ ; cmsenv ; cd -
@aminnj
aminnj / xgboost_dump.py
Created September 22, 2018 08:53
dump xgboost to json/cfunc
# in some versions of xgboost, can't easily dump to json, so dump to the "plaintext"
# format, and then do some string parsing to make a dictionary and then json
# next, convert the json to a c++ function (nested ternary statements for the tree branching)
# and don't forget the sigmoid at the end to get probabilities!
# let's say you have
# ...
# bst = xgb.train( param.items(), dtrain, num_round, evallist, early_stopping_rounds=20 )
# feature_names = ["njets", "nbtags", "met"]
@aminnj
aminnj / dygan.ipynb
Created September 18, 2018 22:10
dygan
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aminnj
aminnj / UserTarball.py
Created September 10, 2018 03:19
CRAB tarring script with bz2/xz
from __future__ import print_function
"""
stolen from https://github.com/dmwm/CRABClient/blob/master/src/python/CRABClient/JobType/UserTarball.py
"""
import os
import glob
import tarfile
import tempfile
import sys
import time
import numba
import numpy as np
import awkward
from awkward import JaggedArray
@numba.jit(nopython=True,cache=True)
def numba_min(content,offsets):
result = np.zeros(len(offsets)-1,dtype=content.dtype)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.