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
# Thanks to Joe Kington | |
# http://stackoverflow.com/questions/7941207/is-there-a-function-to-make-scatterplot-matrices-in-matplotlib | |
using PyPlot | |
function pairs(data) | |
(nobs, nvars) = size(data) | |
(fig, ax) = subplots(nvars, nvars, figsize=(8,8)) | |
subplots_adjust(hspace=0.05, wspace=0.05) |
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
@userplot DTWPlot | |
@recipe function f(h::DTWPlot) | |
seq1, seq2 = h.args | |
i1,i2 = collect(1:length(seq1)),collect(1:length(seq2)) | |
# set up the subplots | |
seriestype := :line | |
legend --> false | |
link := :both |
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 Optim | |
# low-dimensional data embedded in high-dimension | |
data = randn(100,5)*randn(5,100); | |
# a container for the parameters we fit | |
immutable PCA{T<:Real} | |
X::Matrix{T} | |
Y::Matrix{T} | |
end |
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 tensorflow as tf # works on version 1.0.0 | |
import numpy as np | |
from tqdm import trange | |
# create fake data (low-rank matrix X) | |
A = np.random.randn(100, 3).astype(np.float32) | |
B = np.random.randn(3, 100).astype(np.float32) | |
X = np.dot(A, B) | |
# create tensorflow variables to predict low-rank decomposition |
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 | |
from tqdm import tqdm | |
# N, size of matrix. R, rank of data | |
N = 100 | |
R = 5 | |
# generate data | |
W_true = np.random.randn(N,R).astype(np.float32) |
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
def reverse_segment(path, n1, n2): | |
"""Reverse the nodes between n1 and n2. | |
""" | |
q = path.copy() | |
if n2 > n1: | |
q[n1:(n2+1)] = path[n1:(n2+1)][::-1] | |
return q | |
else: | |
seg = np.hstack((path[n1:], path[:(n2+1)]))[::-1] | |
brk = len(q) - n1 |
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 tqdm import trange | |
import matplotlib.pyplot as plt | |
# TODO: subclass np.ndarray? | |
class ShiftMatrix(object): | |
""" | |
Thin wrapper around a numpy matrix to support shifting along the second | |
axis and padding with zeros. |
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
% quad % | |
\[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \] | |
% optimization % | |
\usepackage{amsmath} | |
\begin{equation*} | |
\begin{aligned} | |
& \underset{x}{\text{minimize}} | |
& & f_0(x) \\ | |
& \text{subject to} |
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 Poisson regression. | |
""" | |
import numpy as np | |
from scipy.optimize import minimize | |
n = 1000 # number of datapoints | |
p = 5 # number of features |
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
""" | |
Computing hessian-vector products in tensorflow. | |
For simplicity, we demonstrate the idea on a Poisson regression model. | |
""" | |
import tensorflow as tf | |
import numpy as np | |
from scipy.optimize import minimize |
OlderNewer