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 / trollplot.ipynb
Created August 4, 2016 15:02
The Trolliest Plot Ever
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vene
vene / check_if_delegate_has_method.py
Created June 7, 2017 08:33
if_delegate_has_method adds explicit self
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):
@vene
vene / check.py
Last active June 9, 2017 08:32
lightning multiprocessing failure in python 3.6
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 / ap.py
Last active June 9, 2017 16:33
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]
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)
@vene
vene / Makefile
Created November 22, 2017 23:25
test cpu-only node with multi-device dynet
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
@vene
vene / pardalos_kovoor.py
Last active May 5, 2021 17:53
Pardalos & Kovoor's O(n) solver for singly-constrained bounded QPs
# Author: Vlad Niculae <vlad@vene.ro>
# License: Simplified BSD
import numpy as np
try:
from numba import jit
except ImportError:
print("numba not available")
def jit(nopython):
@vene
vene / gen_csparsemax.py
Last active October 21, 2020 09:33
Generalized constrained projection onto simplex
# Author: vlad niculae <vlad@vene.ro>
# License: 3-clause BSD
import numpy as np
import cvxpy as cx
from copt.constraint import SimplexConstraint
from copt.splitting import minimize_primal_dual
@vene
vene / crayon.h
Last active April 12, 2019 15:10
mlflow and crayon from cpp
#pragma once
/* MLFlow interaction */
#include <string>
#include <chrono>
#include <cpr/cpr.h>
#include <nlohmann/json.hpp>
@vene
vene / check_grad_max_softmax.py
Created May 23, 2019 19:16
Relationship between (soft)max and (soft)argmax
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