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
# The MIT License (MIT) | |
# | |
# Copyright (c) Alex H. Williams | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation | |
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, | |
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the | |
# Software is furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the |
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 numpy.random as npr | |
from functools import reduce | |
# Goal | |
# ---- | |
# Compute (As[0] kron As[1] kron ... As[-1]) @ v | |
# ==== HELPER FUNCTIONS ==== # |
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
""" | |
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 numpy as np | |
from numpy.random import randn, rand | |
from scipy.optimize import minimize | |
import matplotlib.pyplot as plt | |
from nnls import nnlsm_blockpivot as nnlstsq | |
import itertools | |
from scipy.spatial.distance import cdist | |
def censored_lstsq(A, B, M): | |
"""Solves least squares problem with missing data in 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
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
from pca_crossval import * | |
from tqdm import tqdm | |
import itertools | |
np.random.seed(1111) | |
m, n, r = 100, 101, 3 | |
Utrue, Vtrue = rand(m,r), rand(r,n) | |
data = np.dot(Utrue, Vtrue) + .25*randn(m,n) | |
data[data < 0] = 0 | |
ranks = [] |
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 sklearn.datasets import make_biclusters | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
def resort_rows_hclust(U): | |
"""Sorts the rows of a matrix by hierarchical clustering | |
Parameters: | |
U (ndarray) : matrix of data |
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 |
NewerOlder