Skip to content

Instantly share code, notes, and snippets.

View vvanirudh's full-sized avatar
💭
I may be slow to respond.

Anirudh Vemula vvanirudh

💭
I may be slow to respond.
View GitHub Profile
@vvanirudh
vvanirudh / gan_1d.py
Created April 26, 2017 20:07
GAN to model a 1D gaussian distribution
# Drawn from https://gist.github.com/rocknrollnerd/06bfed6b9d1bce612fd6 (in theano)
# This is implemented in PyTorch
# Author : Anirudh Vemula
import numpy as np
import torch
import torch.nn as nn
from torch.autograd import Variable
from scipy.stats import norm
import matplotlib.pyplot as plt
@vvanirudh
vvanirudh / bayes_by_backprop.py
Last active July 25, 2022 11:26
Bayes by Backprop in PyTorch (introduced in the paper "Weight uncertainty in Neural Networks", Blundell et. al. 2015)
# Drawn from https://gist.github.com/rocknrollnerd/c5af642cf217971d93f499e8f70fcb72 (in Theano)
# This is implemented in PyTorch
# Author : Anirudh Vemula
import torch
import torch.nn as nn
from torch.autograd import Variable
import numpy as np
from sklearn.datasets import fetch_mldata
@vvanirudh
vvanirudh / random_fourier_features.py
Created February 6, 2018 19:39
Random fourier features using both sines and cosines embedding for Gaussian kernel
from sklearn.base import BaseEstimator
from sklearn.exceptions import NotFittedError
import numpy as np
class IRFF(BaseEstimator):
'''
Random fourier features using the improved embedding
https://www.cs.cmu.edu/~schneide/DougalRandomFeatures_UAI2015.pdf
'''
@vvanirudh
vvanirudh / sliding_mean.py
Created February 6, 2018 21:47
Computing sliding mean to smooth curves
import numpy as np
def sliding_mean(data_array, window=5):
data_array = np.array(data_array)
new_list = []
for i in range(len(data_array)):
indices = range(max(i - window + 1, 0),
min(i + window + 1, len(data_array)))
avg = 0
for j in indices:
@vvanirudh
vvanirudh / Keeping a fork up to date
Last active February 28, 2018 01:13 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date
### 1. Clone your fork:
git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git
### 2. Add remote from original repository in your forked repository:
cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
"""
Copyright (c) 2017, Gavin Weiguang Ding
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
@vvanirudh
vvanirudh / runningstat.py
Created March 30, 2018 19:24
Running mean and standard deviation
# From https://www.johndcook.com/blog/standard_deviation/
# and https://github.com/modestyachts/ARS
class RunningStat(object):
def __init__(self, shape=None):
self._n = 0
self._M = np.zeros(shape, dtype = np.float64)
self._S = np.zeros(shape, dtype = np.float64)
self._M2 = np.zeros(shape, dtype = np.float64)
@vvanirudh
vvanirudh / natural_grad.py
Created February 15, 2019 15:48
Natural Gradient Demo
import numpy as np
from sklearn.utils import shuffle
import random
import argparse
import matplotlib.pyplot as plt
import time
parser = argparse.ArgumentParser()
parser.add_argument('--ng', action='store_true')
parser.add_argument('--seed', type=int, default=10)
@vvanirudh
vvanirudh / test_pr2_pick.py
Created July 3, 2020 00:06
Example of PR2 grasping an object using ss-pybullet
#!/usr/bin/env python
from __future__ import print_function
import numpy as np
import pybullet as p
from pybullet_tools.utils import (connect, disable_real_time,
set_default_camera, wait_for_user,
disconnect, load_pybullet, TABLE_URDF, add_data_path,
create_box, FLOOR_URDF, set_point, load_model,
HideOutput, set_base_values, get_unit_vector, WorldSaver,
@vvanirudh
vvanirudh / auto_git_file.md
Created February 6, 2021 17:33 — forked from darencard/auto_git_file.md
Automatic file git commit/push upon change

Automatically push an updated file whenever it is changed

Linux

  1. Make sure inotify-tools is installed (https://github.com/rvoicilas/inotify-tools)
  2. Configure git as usual
  3. Clone the git repository of interest from github and, if necessary, add file you want to monitor
  4. Allow username/password to be cached so you aren't asked everytime
git config credential.helper store