Skip to content

Instantly share code, notes, and snippets.

ahoy

Vlad Niculae vene

ahoy
View GitHub Profile
@vene
vene / check_berthet_gradients.py
Created Jun 22, 2020
check mc perturbed gradients (Berthet et at)
View check_berthet_gradients.py
# 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 Jun 17, 2020
merge slideslive
View merge.sh
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 \
View binary_kbest.h
// 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 Apr 16, 2020
Sum-and-sample estimator for learning a stochastic Bernoulli.
View bernoulli.py
"""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 Apr 6, 2020
barycenter on sphere
View sphere_barycenter.py
# 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
View sample_seq_crf.py
"""
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
View check_fy_vs_likelihood.py
# 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):
@vene
vene / generate_latent_clf.py
Created Sep 10, 2019
Generate samples from a discrete latent variable classification model
View generate_latent_clf.py
"""
Generate data triples (x, y, z) for deterministic classification p(y | x; z)
Generative story:
Given: n_clusters; for each cluster:
- a cluster center (mean) center[z]
- a linear model y=sign(w[z] * x + b[z])
pick z from uniform Categorical(n_clusters)
@vene
vene / check_grad_max_softmax.py
Created May 23, 2019
Relationship between (soft)max and (soft)argmax
View check_grad_max_softmax.py
import numpy as np
def numeric_grad(f, x, eps=1e-3):
grad = np.zeros_like(x)
for i in range(x.shape[0]):
v = np.zeros_like(x)
v[i] = 1
@vene
vene / crayon.h
Last active Apr 12, 2019
mlflow and crayon from cpp
View crayon.h
#pragma once
/* MLFlow interaction */
#include <string>
#include <chrono>
#include <cpr/cpr.h>
#include <nlohmann/json.hpp>
You can’t perform that action at this time.