This file contains 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
class Base: | |
def say(self, val): | |
print("base says", val) | |
class A(Base): | |
def say(self, val): | |
print("say A") |
This file contains 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 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> | |
# Makes use of memory_profiler from Fabian Pedregosa | |
# available at https://github.com/fabianp/memory_profiler | |
from IPython.core.magic import Magics, line_magic, magics_class | |
class MemMagics(Magics): | |
@line_magic | |
def memit(self, line='', setup='pass'): |
This file contains 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 scipy.sparse import csr_matrix | |
from scipy.sparse import issparse | |
from sklearn.utils import atleast2d_or_csr | |
from sklearn.utils.extmath import safe_sparse_dot | |
from sklearn.metrics.pairwise import check_pairwise_arrays, euclidean_distances | |
from sklearn.metrics.euclidean_fast import dense_euclidean_distances, sparse_euclidean_distances | |
This file contains 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: mit | |
import torch | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.colors as colors | |
from entmax import sparsemax, entmax15 | |
from entmax.losses import sparsemax_loss, entmax15_loss |
This file contains 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: vn | |
import numpy as np | |
from scipy.optimize import root_scalar | |
import torch | |
import matplotlib.pyplot as plt | |
def entropy(y, a, b): |
This file contains 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 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
# 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 |
This file contains 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
# 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(): |
This file contains 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
# 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) |