Before the course starts you should make sure that you have installed the latest version of:
R.
An integrated development environment like R Studio is also highly recommended but is not necessary.
We will be using a few specialized R packages that you need to install prior to arriving. Those are necessary for us to run the exercises. The code below should be run in R (e.g. by opening RStudio and copying them into the console) to install the packages that we will need. You need to be connected to the internet to install the packages.
If you are a Windows user, you may need to run RStudio as an administrator in order to install the packages. This can be done by right-clicking the RStudio program icon and choosing “Run as administrator”.
Follow this installation guide:
To get keras
working, you first need to install the
R package:
install.packages("keras")
If the installation succeeds without any errors, you must continue to run the final two lines:
library("keras")
install_keras()
This may take a while and you may be prompted for further installation choices along the way.
Finally, you can test your installation by running the following code:
library(keras)
mnist <- dataset_mnist()
x_train <- mnist$train$x
y_train <- mnist$train$y
x_test <- mnist$test$x
y_test <- mnist$test$y
# reshape
x_train <- array_reshape(x_train, c(nrow(x_train), 784))
x_test <- array_reshape(x_test, c(nrow(x_test), 784))
# rescale
x_train <- x_train / 255
x_test <- x_test / 255
y_train <- to_categorical(y_train, 10)
y_test <- to_categorical(y_test, 10)
model <- keras_model_sequential()
model %>%
layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>%
layer_dropout(rate = 0.4) %>%
layer_dense(units = 128, activation = 'relu') %>%
layer_dropout(rate = 0.3) %>%
layer_dense(units = 10, activation = 'softmax')
model %>% compile(
loss = 'categorical_crossentropy',
optimizer = optimizer_rmsprop(),
metrics = c('accuracy')
)
history <- model %>% fit(
x_train, y_train,
epochs = 3, batch_size = 128,
validation_split = 0.2
)
cat("Testing done! \n \n")
cat("Results: \n")
print(history)
If your installation was successful, the output should end with the following information (maybe with slightly different numbers):
Results:
Trained on 48,000 samples (batch_size=128, epochs=3)
Final epoch (plot to see history):
loss: 0.1509
accuracy: 0.9561
val_loss: 0.1148
val_accuracy: 0.9649
If not, try running each step again and see if it helps.
Finally you should install the following bunch of R packages:
install.packages(c("tidyverse", "modelr", "broom", "forcats",
"glmnet", "caret", "gglasso", "MESS",
"boot", "corrr", "here", "patchwork",
"patchwork", "equatiomatic",
"selectiveInference",
"doParallel",
"MASS", "devtools",
"knitr", "rmarkdown",
"ranger", "party", "partykit",
"yardstick",
"stabs", "hal9001",
"pcalg", "SuperLearner"))
as well as these packages
install.packages(c("BiocManager", "devtools", "pdftools", "dagitty"))
# Install libraries from BioConductor
BiocManager::install("graph")
BiocManager::install("RBGL")
BiocManager::install("Rgraphviz")
install.packages(c("micd", "pcalg"))
devtools::install_github("annennenne/causalDisco")
We will use a LaTeX backend for some of the plotting. If you do not have LaTeX installed already, you may install it from R using the tinytex package:
install.packages("tinytex")
library(tinytex)
install_tinytex()
Claus Thorn Ekstrøm and Mikkel Meyer Andersen 2024