This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| /* MLFlow interaction */ | |
| #include <string> | |
| #include <chrono> | |
| #include <cpr/cpr.h> | |
| #include <nlohmann/json.hpp> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |