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 pandas as pd | |
from sklearn.linear_model import LinearRegression | |
N = 10_000 | |
np.random.seed(42) | |
df = pd.DataFrame(index=np.arange(N)) | |
df['x2'] = np.random.choice([1,2,3], size=N) |
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 collections import deque | |
def dist_to(game_map, sources): | |
dist = np.empty_like(game_map.owners) | |
dist.fill(-1) | |
for sx, sy in sources: | |
dist[sx, sy] = 0 |
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
M1 <- matrix(seq(16), nrow = 4, ncol = 4) | |
M2 <- matrix(seq(16), nrow = 4, ncol = 4) | |
M1 * M2 | |
M1 %*% M2 | |
`*` <- function(lhs, rhs) { | |
if (is.matrix(lhs) & is.matrix(rhs)) { | |
return(lhs %*% rhs) | |
} |
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
library("randomForest") | |
data(mtcars) | |
rf <- randomForest(mpg ~ ., data = mtcars, ntree = 10) | |
preds <- predict(rf, newdata = mtcars, predict.all = TRUE) | |
# Aggregate predictions | |
preds$aggregate | |
# Invididual tree predictions | |
preds$individual |
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
for (i in 2:ncol(my_data)) { | |
varname <- colnames(my_data)[i] | |
# if you want to change varname somehow | |
# varname <- paste0(varname, "new") | |
my_data[[varname]] <- my_data[,i]/sd(my_data[,i]) | |
} |
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
# Make a 3D transition matrix T where z-dimension is time | |
T_states <- 3 | |
T_terms <- 4 | |
T <- array(runif(T_states * T_states * Tz)/1.5, dim = c(T_states, T_states, Tz)) | |
# Normalise by rows | |
for (z in seq(Tz)) { | |
T[, , z] <- T[, , z] / apply(T[, , z], 1, sum) | |
} |
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
generate_fks <- function(N) { | |
fki <- log(N + 1) | |
fks <- c(fki) | |
for (i in seq(N)) { | |
fki <- log(exp(fki) - fki) | |
fks <- c(fks, fki) | |
} | |
fks |
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
# Instantiate local CRAN | |
localCRAN <- path.expand("QRAN") | |
dir.create(localCRAN) | |
contribDir <- file.path(localCRAN, "src", "contrib") | |
dir.create(contribDir, recursive = TRUE) | |
rVersion <- paste(unlist(getRversion())[1:2], collapse = ".") | |
binPaths <- list( |
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
library("mlbench") | |
library("ggplot2") | |
library("mxnet") | |
plot_mxmodel <- function(model, data) { | |
x <- seq(from = min(data), to = max(data), length.out = 500) | |
d2 <- as.matrix(expand.grid(x, x)) | |
mx_pred <- predict(model, d2) |
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
sudo apt-get update | |
sudo apt-get install -y build-essential git libatlas-base-dev libopencv-dev | |
git clone --recursive https://github.com/dmlc/mxnet | |
cd mxnet; | |
cp make/config.mk . | |
#add CUDA options | |
echo "USE_CUDA=1" >>config.mk |
NewerOlder