Skip to content

Instantly share code, notes, and snippets.

View vene's full-sized avatar
🏴
ahoy

Vlad Niculae vene

🏴
ahoy
View GitHub Profile
@vene
vene / energy.py
Created October 19, 2020 12:22
energy model with langevin dynamics
# Density estimation with energy-based models
# Langevin sampling, contrastive divergence training.
# Author: Vlad Niculae <vlad@vene.ro>
# License: MIT
import numpy as np
import torch
from sklearn import datasets
import matplotlib.pyplot as plt
# Geometric intepretation of the gradient of the mapping:
# f : (0, inf) x Sphere(k-1) -> R^k
# f(r, u) -> r*u
# The *catch*: R can vary on (0, inf) but u may only vary on the
# k-1--dimensional tangent plane!
import numpy as np
def main():
# linearity of expectation under mixture model
# license: mit
# author: vlad niculae
from scipy.stats import norm
import numpy as np
def main():
rng = np.random.RandomState(42)
@vene
vene / check_berthet_gradients.py
Created June 22, 2020 16:47
check mc perturbed gradients (Berthet et at)
# https://arxiv.org/abs/2002.08676
# code by vlad niculae
# license: mit
import numpy as np
import matplotlib.pyplot as plt
def main():
@vene
vene / merge.sh
Created June 17, 2020 16:21
merge slideslive
ffmpeg \
-i slideslive-recorder_[...].364Z_user.webm \
-i slideslive-recorder_[...].364Z_display.webm \
-filter_complex \
'[0:v]scale=640:360,pad=640:720[left];[1:v]crop=1680:945:0:0,scale=1280:720[right];[left][right]hstack[v]' \
-map [v] \
-map 0:a \
-c:v libx264 \
-preset veryslow \
-crf 18 \
// k-best assignments for independent binary variables
// (optimized version of zeroth order viterbi)
// author: vlad niculae <vlad@vene.ro>
// license: mit
#pragma once
#include <vector>
#include <algorithm>
#include <cassert>
#include <bitset>
@vene
vene / bernoulli.py
Last active April 16, 2020 15:13
Sum-and-sample estimator for learning a stochastic Bernoulli.
"""Sum-and-sample estimator for learning a stochastic Bernoulli.
Reproduces Experiment 1 from
Liu et al, Rao-Blackwellized Stochastic Gradients for Discrete Distributions
https://arxiv.org/abs/1810.04777
"""
# author: vlad niculae <vlad@vene.ro>
# license: mit
@vene
vene / sphere_barycenter.py
Created April 6, 2020 19:56
barycenter on sphere
# author: vlad niculae <vlad@vene.ro>
# license: mit
import numpy as np
from scipy.special import softmax
from mayavi import mlab
def barycenter(X, w):
# riemannian opt
"""
Check sampling from a sequential CRF model.
- Code is for n_states=2 but the strategy is general.
- TODO; cythonize or numbaize
- TODO; write general impl for clarity
"""
# author: vlad niculae <vlad@vene.ro>
# license: MIT
# compare FY entmax losses with (log)-likelihood objectives
# author: vlad niculae
import numpy as np
import torch
import matplotlib.pyplot as plt
from entmax import entmax_bisect, entmax_bisect_loss
def main(alpha=1.5):