Skip to content

Instantly share code, notes, and snippets.

View abrazhe's full-sized avatar

Alexey Brazhe abrazhe

  • Moscow State University; Copenhagen University
View GitHub Profile
@panisson
panisson / ncp.py
Last active June 9, 2020 01:44
Nonnegative Tensor Factorization, based on the Matlab source code available at Jingu Kim's home page: https://sites.google.com/site/jingukim/home#ntfcode Requires the installation of Numpy and Scikit-Tensor (https://github.com/mnick/scikit-tensor). For examples, see main() function.
# Copyright (C) 2013 Istituto per l'Interscambio Scientifico I.S.I.
# You can contact us by email (isi@isi.it) or write to:
# ISI Foundation, Via Alassio 11/c, 10126 Torino, Italy.
#
# This work is licensed under a Creative Commons 4.0
# Attribution-NonCommercial-ShareAlike License
# You may obtain a copy of the License at
# http://creativecommons.org/licenses/by-nc-sa/4.0/
#
# This program was written by Andre Panisson <panisson@gmail.com> at
import numpy as np
from scipy import linalg
from sklearn.utils import array2d, as_float_array
from sklearn.base import TransformerMixin, BaseEstimator
class ZCA(BaseEstimator, TransformerMixin):
def __init__(self, regularization=10**-5, copy=False):
self.regularization = regularization
@hamishmorgan
hamishmorgan / gist:3342260
Created August 13, 2012 16:14
A quick demo of how to produce a loglog histogram plot of very large amounts of data, by using log-histogram bins.
# A quick demo of how to produce a loglog histogram plot of very large
# amounts of data, by using log-histogram bins
import numpy as np
import matplotlib.pyplot as plt
import itertools as it
# We shall draw millions of samples from a Zipf distribution. Using linear
# bins this is too much data for a fast and attactive plot.
@alextp
alextp / fast_svd.py
Created November 4, 2010 13:12
Gunnar Martinsson's fast svd
import numpy as np, numpy.linalg as linalg
def fast_svd(M, k):
p = k+5
Y = np.dot(M, np.random.normal(size=(M.shape[1],p)))
Q,r = linalg.qr(Y)
B = np.dot(Q.T,M)
Uhat, s, v = linalg.svd(B, full_matrices=False)
U = np.dot(Q, Uhat)
return U.T[:k].T, s[:k], v[:k]