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
| # venv | |
| # usage: | |
| # $ venv .recsys | |
| function venv { | |
| default_envdir=".env" | |
| envdir=${1:-$default_envdir} | |
| if [ ! -d $envdir ]; then | |
| python3.7 -m virtualenv -p python3.7 $envdir | |
| echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m" |
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
| #!/bin/bash | |
| flag=$1 | |
| if [[ $flag == 'DL' ]]; then | |
| # ------------- | |
| # Deep Learning | |
| # ------------- | |
| echo "Configuring GPU for Deep Learning..." | |
| sudo apt-get install -y libnvidia-common-440 | |
| sudo apt-get install -y cuda | |
| sudo apt-get install -y cuda-drivers |
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
| #pragma once | |
| #include <algorithm> | |
| #include <functional> | |
| #include <future> | |
| #include <thread> | |
| #include <vector> | |
| // adapted from https://stackoverflow.com/a/49188371/2055486 |
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
| library(ggplot2) | |
| theme_set(theme_classic()) | |
| # Visualizing entropy --------------------------------------------------------- | |
| entropy <- function(p) -sum(p * log(p)) | |
| n <- 1e6 | |
| p <- runif(n) | |
| q <- 1 - p | |
| z <- matrix(c(p, q), ncol = 2) | |
| ent <- apply(z, 1, entropy) |
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
| li(ggplot2) | |
| theme_set(theme_classic()) | |
| entropy <- function(p) -sum(p * log(p)) | |
| n <- 1e6 | |
| p <- runif(n) | |
| q <- 1 - p | |
| z <- matrix(c(p, q), ncol = 2) | |
| ent <- apply(z, 1, entropy) | |
| qplot(q, ent, geom = "line") + |
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
| li(ggplot2) | |
| theme_set(theme_classic()) | |
| kld <- function(p, q) sum(p * log(p / q)) | |
| n <- 1e6 | |
| p <- c(0.6, 0.4) | |
| q1 <- runif(n) | |
| q2 <- 1 - q1 | |
| z <- matrix(c(q1, q2), ncol = 2) | |
| kl <- apply(z, 1, kld, p = p) |
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
| .First <- function() { | |
| # set TZ if unset | |
| if (is.na(Sys.getenv("TZ", unset = NA))) | |
| Sys.setenv(TZ = "America/New_York") | |
| # bail if revo R | |
| if (exists("Revo.version")) | |
| return() |
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
| library(tidyverse) | |
| y <- as.matrix(mtcars$mpg) | |
| X <- model.matrix(mpg ~ ., mtcars) | |
| # linear regression | |
| solve(crossprod(X)) %*% t(X) %*% y | |
| solve(crossprod(X) + 0 * diag(rep(1, ncol(X)))) %*% t(X) %*% y | |
| # ridge regression |
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
| library(gistr) | |
| # create | |
| gist_create(files='../create_gist.R', | |
| description='Create gist via R.') | |
| # update | |
| gists(what = "minepublic")[[1]] %>% | |
| update_files('../create_gist.R') %>% | |
| update() |
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
| library(purrr) | |
| # two regressions | |
| lm_fit <- lm(mpg ~ wt + cyl, data = mtcars) | |
| bayes_fit <- rstanarm::stan_glm(mpg ~ wt + cyl, data = mtcars) | |
| # design matrix [32 x 3] | |
| X <- model.matrix(lm_fit) | |
| # coefficient matrix [3 x 2] |