This is the documentation for using the Methods & Statistics department compute server.
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
| # Pretty print list structures with the unicode stuff | |
| # using https://stackoverflow.com/questions/1649027/how-do-i-print-out-a-tree-structure | |
| str2 <- function(x, name = NULL, max.depth = 10L, indent = NULL, depth = 0L, last = TRUE) { | |
| cat(indent) | |
| if (last) { | |
| cat("\u2514\u2500") | |
| indent <- paste0(indent, " ") | |
| } else { | |
| cat("\u251c\u2500") | |
| indent <- paste0(indent, "\u2502 ") |
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
| // cheat on guessthecorrelation.com | |
| // don't actually do this to get the high-score. it would be sad. | |
| function get_the_cor() { | |
| // Get points from html | |
| var points = document.getElementsByClassName("nv-group")[0] | |
| // create dataset from transform attribute on the svg points | |
| var transs = Array.from(points.children).map(p => p.getAttribute("transform")) | |
| var data = transs.map(x => x.split(",").map(y => y.match(/[\d\.]+/g)).map(Number)) | |
| var tdata = data[0].map((col, i) => data.map(row => row[i])); |
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
| # Covariance matrix and random normal data | |
| Sigma <- matrix(c(1, .5, .5, 1), 2) | |
| X <- matrix(rnorm(1000), ncol = 2) | |
| S <- cov(X) | |
| # random multivariate normal sample | |
| R_mvn <- chol(Sigma) | |
| X_mvn <- X %*% R_mvn | |
| cov(X_mvn) |
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
| mkdir eps; for file in $(ls | grep .pdf); do pdf2ps $file eps/${file%.*}.eps; done |
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
| # Sparse coding for MNIST feature extraction using autodiff | |
| using Zygote: gradient | |
| using MLDatasets: MNIST | |
| using LinearAlgebra: Diagonal | |
| using ImageCore | |
| # Goodfellow page 629, equation 19.16, but per pixel | |
| function loss(H::Matrix{Float64}, W::Matrix{Float64}) | |
| (sum(abs.(H)) + sum((X - H*W).^2)) / L | |
| 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
| module Adamopt | |
| # This is a module implementing vanilla Adam (https://arxiv.org/abs/1412.6980). | |
| export Adam, step! | |
| # Struct containing all necessary info | |
| mutable struct Adam | |
| theta::AbstractArray{Float64} # Parameter array | |
| loss::Function # Loss function | |
| grad::Function # Gradient function |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| # script that outputs a graph | |
| library(tidyverse) | |
| library(firatheme) | |
| wine <- read_delim("https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data", | |
| delim = ",", | |
| col_names = c( | |
| "Cultivar", "Alcohol", "Malic acid", "Ash", "Alcalinity of ash", "Magnesium", | |
| "Total phenols", "Flavanoids", "Nonflavanoid phenols", "Proanthocyanins", | |
| "Color intensity", "Hue", "OD280/OD315", "Proline" | |
| ) |