View mmd_test.py
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 |
View multi_set_perm_match.py
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). |
View supervised_pca.py
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 |
View pytorch_nmf.py
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. |
View msplines.py
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 |
View simple_cmap.py
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 |
View permtest.py
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
""" | |
A simple implementation of a permutation test among two | |
independent samples. | |
""" | |
import numpy as np | |
from sklearn.utils.validation import check_random_state | |
from more_itertools import distinct_permutations | |
from scipy.stats import percentileofscore | |
from math import factorial |
View matlab.py
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 scipy.io as spio | |
import numpy as np | |
def loadmat(filename): | |
''' | |
this function should be called instead of direct spio.loadmat | |
as it cures the problem of not properly recovering python dictionaries | |
from mat files. It calls the function check keys to cure all entries | |
which are still mat-objects | |
''' |
View hclust_sort.py
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 |
View cca.py
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 sklearn.utils.extmath import randomized_svd | |
def partial_whiten(X, alpha, eigval_tol=1e-7): | |
""" | |
Return regularized whitening transform for a matrix X. | |
Parameters | |
---------- |
NewerOlder