Skip to content

Instantly share code, notes, and snippets.

⚓️
ahoy

Vlad Niculae vene

⚓️
ahoy
Block or report user

Report or block vene

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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>
@vene
vene / gen_csparsemax.py
Created Nov 17, 2018
Generalized constrained projection onto simplex
View gen_csparsemax.py
# Author: vlad niculae <vlad@vene.ro>
# License: 3-clause BSD
import numpy as np
import cvxpy as cx
def fw_affine(theta, A, b, ineq=True, max_iter=100, beta_init=.01):
""" minimize ||p, theta||^2
st p in simplex
@vene
vene / pardalos_kovoor.py
Last active May 31, 2018
Pardalos & Kovoor's O(n) solver for singly-constrained bounded QPs
View pardalos_kovoor.py
import numpy as np
try:
from numba import jit
except ImportError:
print("numba not available")
def jit(nopython):
def id(f):
return f
return id
@vene
vene / Makefile
Created Nov 22, 2017
test cpu-only node with multi-device dynet
View Makefile
DYNET_PATH ?= /home/vlad/code/dynet
EIGEN_PATH ?= /home/vlad/code/eigen
CC = g++
DEBUG = -g
INCLUDES = -I$(DYNET_PATH) -I$(EIGEN_PATH)
LIBS = -L$(DYNET_PATH)/build-cuda/dynet/
CFLAGS = -O3 -Wall -Wno-sign-compare -Wno-int-in-bool-context -c -fmessage-length=0 $(INCLUDES) -DEIGEN_FAST_MATH -fPIC -fno-finite-math-only -Wno-missing-braces -std=c++11 -funroll-loops
LFLAGS = $(LIBS) -ldynet
View generate_data.py
import numpy as np
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.utils import shuffle
# get shuffled iris data
X, y = load_iris(return_X_y=True)
X, y = shuffle(X, y, random_state=0)
View ap.py
import numpy as np
from sklearn.metrics import precision_recall_curve, average_precision_score
def naive_interpolated_precision(y_true, y_scores):
precisions, recalls, _ = precision_recall_curve(y_true, y_scores)
interp_precisions = []
# the final point
precisions = precisions[:-1]
@vene
vene / check.py
Last active Jun 9, 2017
lightning multiprocessing failure in python 3.6
View check.py
import sys
import numpy as np
import sklearn
import lightning
print("python", sys.version)
print("numpy", np.__version__)
print("scikit-learn", sklearn.__version__)
print("lightning", lightning.__version__)
@vene
vene / check_if_delegate_has_method.py
Created Jun 7, 2017
if_delegate_has_method adds explicit self
View check_if_delegate_has_method.py
from sklearn.utils.metaestimators import if_delegate_has_method
from sklearn.utils.fixes import signature
class Test(object):
def hi(self, what):
return 1 + what
class Kid(object):
You can’t perform that action at this time.