Skip to content

Instantly share code, notes, and snippets.

View chausies's full-sized avatar

Ajay Shanker Tripathi chausies

View GitHub Profile
@chausies
chausies / pytorch_log_norm_cdf.py
Last active June 30, 2021 11:24
Numerically stable and accurate PyTorch implementation of the log of the CDF of the standard normal distribution
# Numerically stable and accurate implementation of the natural logarithm
# of the cumulative distribution function (CDF) for the standard
# Normal/Gaussian distribution in PyTorch.
import matplotlib.pylab as P # replace this with numpy if you want
import torch as T
def norm_cdf(x):
return (1 + T.erf(x/P.sqrt(2)))/2
@chausies
chausies / torch_cubic_spline_interp.py
Last active December 19, 2023 15:50
Simple Hermite Cubic Spline Interpolation and Integration implemented in Pytorch (with autograd support and fast runtime)
import torch as T
def h_poly_helper(tt):
A = T.tensor([
[1, 0, -3, 2],
[0, 1, -2, 1],
[0, 0, 3, -2],
[0, 0, -1, 1]
], dtype=tt[-1].dtype)
return [
@chausies
chausies / simple_plot.py
Last active March 19, 2019 23:43
A very simple example showing you how to make more or less nice plots in python
from __future__ import division, print_function # Always do this just to
# ensure compatability
# between python 2.7 and 3
import matplotlib.pylab as P
# Always do these next to lines to enable LaTeX to be used on the
# matplotlib plots
P.rc('text', usetex=True)
P.rc('font', family='serif')
@chausies
chausies / VimFX preferences.json
Created January 30, 2017 00:52
vimFX preferences
{
"smoothScroll.pages.spring-constant": "800",
"smoothScroll.other.spring-constant": "800",
"mode.normal.focus_search_bar": "",
"mode.normal.scroll_page_down": "D",
"mode.normal.scroll_page_up": "U",
"mode.normal.scroll_half_page_down": "<space> d",
"mode.normal.scroll_half_page_up": "<s-space> u",
"mode.normal.tab_new_after_current": "T O",
"mode.normal.tab_move_backward": "<",
set smoothscroll
let scrollstep = 100
map O t
@chausies
chausies / youtube_history.py
Last active August 29, 2015 14:27
This python script gets all of your youtube viewing history into a convenient text file.
#---------------------------------------------------------------#
# This script manually goes through youtube and collects all #
# of your viewing history into a convenient text file. This #
# might take about 30min to an hour, depending on your #
# computer's RAM, processing speed, and internet connection. #
# Note that this program requires the splinter module to work. #
# Run 'pip install splinter' to get it. #
#---------------------------------------------------------------#
print "Making sure you're not using python 3..."
from splinter import Browser
@chausies
chausies / tourney.py
Last active August 29, 2015 14:27
Making good single-elimination tourney brackets based on seeds. Optimally orders the bracket so that worse seeds get knocked out first by people as close as possible to their skill level.
def tourney_in_order(k):
"""
Tells you the bracket for a tourney with n=2^k competitors 1-n, where 1
is the best. The bracket is such that competitors lose in the order of
their skill to the person with a level of skill as close to theirs as
possible.
>>> bracket = tourney_in_order(4)
>>> print bracket
[16, 8, 15, 4, 14, 7, 13, 2, 12, 6, 11, 3, 10, 5, 9, 1]
@chausies
chausies / banner.vim
Last active August 29, 2015 14:25
Banner the current line/selection in vim. Uses tcomment plugin once to find the correct comment-style for the filetype.
" banner comments
fu! Banner(opt)
let l:l1 = line("'<")
let l:l2 = line("'>")
let l:spac = indent(line("."))-1
let l:lines = getline(l:l1, l:l2)
exe substitute(
\ substitute('%1d%2', "%1", l:l1, ""),
\ "%2", l:l2-l:l1+1, "")
let l:maxim = 0