This file contains hidden or 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 hidden or 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 hidden or 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 | |
| ---------- |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |