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 / dump_xgb.py
Created April 19, 2017 19:56
XGB model to C++ function
########################################
## # Train BDT and output model .json ##
########################################
import numpy as np
from sklearn.model_selection import train_test_split
import sys
import os
import xgboost as xgb
### Define test and train matrices somehow
@aminnj
aminnj / make_hv_summary.py
Last active October 31, 2017 13:05
Make CSCDOC HV summary table
import os
import sys
import commands
import datetime
import time
"""
1. Visit this exact URL in Google Chrome
https://cmswbm.cern.ch/cmsdb/servlet/ConditionBrowser?DISPLAY=1&SUBMIT=1D&OPTION=vs_time&STEP=3&BEGIN=2017.10.29_09:50:16&END=2017.10.31_09:50:16&PRESCALER=1&cms_omds_lb.CMS_CSC_PVSS_COND.CSC_HV.CURRENT..M13_C03..10=1&cms_omds_lb.CMS_CSC_PVSS_COND.CSC_HV.CURRENT..M13_C03..11=1&
@aminnj
aminnj / .vimrc
Created January 21, 2018 23:26
.vimrc
let g:pathogen_disabled = [] " disable certain pathogen plugins ... useful to debug
" load plugins before screwing with settings
" https://github.com/tpope/vim-commentary
" https://github.com/tpope/vim-surround
" https://github.com/tpope/vim-fugitive
" https://github.com/scrooloose/nerdtree
" https://github.com/haya14busa/incsearch.vim
" https://github.com/haya14busa/incsearch-fuzzy.vim # z/ to fuzzy search
@aminnj
aminnj / draw_model.py
Created February 20, 2018 00:00
Less verbose keras network architecture drawing
import os
import pickle
import pydot
import keras
from keras.models import load_model
"""
brew install graphviz
pip install pydot
@aminnj
aminnj / install_vim.md
Created July 9, 2018 01:50
installing vim8.1 on slc7 computers

Execute the commands chunk by chunk because I haven't tested this as a whole

# setup environment
cd /cvmfs/cms.cern.ch/slc7_amd64_gcc630/cms/cmssw/CMSSW_10_2_0_pre6/ ; cmsenv ; cd -

# make containment folder somewhere and get vi
mkdir vim8
cd vim8
git clone https://github.com/vim/vim
@aminnj
aminnj / bookmarklet.js
Last active July 21, 2018 07:48
CSC run registry table bookmarklet
/*
Copy this content as a bookmarklet.
Visit https://cmswbmoffshift.web.cern.ch/cmswbmoffshift/api/query and make sure you're authenticated (should say "Query ID missing?")
Execute the bookmark.
???
Profit.
Note: will need to search for and update the following strings below (whenever conditions change): "PromptReco-v3", "Run2018", "319750"
The queries will return at most 1k rows (usually 4k runs or so) so make sure the run number threshold isn't too small!
Well, this won't be useful after 2018...
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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)
@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
@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"]