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
| 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 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
| @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 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
| % 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 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
| # Majority of credit goes to Chris Holdgraf, @choldgraf, and this StackOverflow | |
| # post: http://stackoverflow.com/questions/5320205/matplotlib-text-dimensions | |
| import pylab as plt | |
| import numpy as np | |
| def plot_equation(eq, fontsize=50, outfile=None, padding=0.1, **kwargs): | |
| """Plot an equation as a matplotlib figure. | |
| 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
| 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) |
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
| # 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) |
NewerOlder