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.spatial.distance import pdist, squareform | |
from scipy.sparse import coo_matrix | |
from scipy.sparse.csgraph import laplacian | |
import matplotlib.pyplot as plt | |
def symmetric_knn_graph(X, k): | |
""" | |
Parameters | |
---------- |
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
""" | |
NOTE: This code has not been rigorously tested. | |
""" | |
import matplotlib.pyplot as plt | |
import jax.numpy as jnp | |
import jax | |
from tqdm import trange | |
def elliptical_slice_update(x, log_density, sigmas, key): |
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 matplotlib.pyplot as plt | |
import numpy as np | |
def raised_cos(t, loc, scale, amp): | |
""" | |
Raised, 1d-cosine basis functions tiling [0, 2 * pi) | |
These functions have the property of summing to a | |
constant amplitude at all points (i.e. uniform | |
tiling of space). |
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 numba | |
import numpy as np | |
from scipy.spatial.distance import pdist, squareform | |
from math import comb | |
@numba.jit(nopython=True) | |
def index(n, i, j): | |
""" | |
Computes linear index of (i, j) from the (n x n) distance matrix. | |
""" |
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.spatial.distance import cdist, pdist | |
def mmd_two_sample_test(X, Y): | |
""" | |
Implements Gretton's test for equality of | |
distributions in high-dimensional settings | |
using concentration bounds on the maximum | |
mean discrepancy (MMD). This function uses | |
the unbiased estimator of the MMD (see |
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.optimize import linear_sum_assignment | |
from sklearn.utils import check_random_state | |
import scipy.sparse | |
def perm_alignment(X, Y): | |
""" | |
Given two matrix X and Y. Returns sparse matrix P, holding permutation | |
matrix that minimizes norm(X @ P - Y). |
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
""" | |
Supervised PCA model. | |
Ritchie, A., Balzano, L., Kessler, D., Sripada, C. S., & Scott, C. | |
(2020). Supervised PCA: A Multiobjective Approach. arXiv:2011.05309. | |
""" | |
import numpy as onp | |
import autograd.numpy as np | |
from pymanopt.manifolds import Grassmann, Euclidean, Product |
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 | |
import torch | |
import matplotlib.pyplot as plt | |
from torch_nonneg_linesearch import nonneg_projected_gradient_step | |
# Data dimensions | |
m, n = 100, 101 | |
rank = 3 | |
# Data matrix, detached from the graph. |
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
""" | |
Python code to generate M-splines. | |
References | |
---------- | |
Ramsay, J. O. (1988). Monotone regression splines in action. | |
Statistical science, 3(4), 425-441. | |
""" | |
import numpy as np |
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
from matplotlib.colors import LinearSegmentedColormap, colorConverter | |
def simple_cmap(colors, name='none'): | |
"""Create a colormap from a sequence of rgb values. | |
cmap = simple_cmap([(1,1,1), (1,0,0)]) # white to red colormap | |
cmap = simple_cmap(['w', 'r']) # white to red colormap | |
cmap = simple_cmap(['r', 'b', 'r']) # red to blue to red | |
""" | |
# check inputs |
NewerOlder