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
import numpy as np | |
import scipy.linalg | |
def elastic_net(A, B, x=None, l1=1, l2=1, lam=1, tol=1e-6, maxiter=10000): | |
"""Performs elastic net regression by ADMM | |
minimize ||A*x - B|| + l1*|x| + l2*||x|| | |
Args: | |
A (ndarray) : m x n 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 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 |
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 tensorflow as tf | |
# N, size of matrix. R, rank of data | |
N = 100 | |
R = 5 | |
# generate data | |
W_true = np.random.randn(N,R) | |
C_true = np.random.randn(R,N) |
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 |
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
""" | |
References: | |
- B. Plateau, On the stochastic structure of parallelism and synchronization models for distributed algorithms. | |
Perform. Eval. Rev., 13 (1985), pp. 147–154. | |
- Dayar, T., & Orhan, M. C. (2015). On vector-Kronecker product multiplication with rectangular factors. | |
SIAM Journal on Scientific Computing, 37(5), S526-S543. | |
""" |
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 | |
''' |
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
using PyPlot | |
using Distributions | |
function credible_interval(D::UnivariateDistribution; c=0.95, nx=1000) | |
# Discretize over the support | |
r = support(D) | |
lb,ub = r.lb,r.ub | |
# Histogram approximation of area under pdf | |
x = linspace(lb,ub,nx) |