Skip to content

Instantly share code, notes, and snippets.

View DannyArends's full-sized avatar

Danny Arends DannyArends

View GitHub Profile
@DannyArends
DannyArends / PCA.R
Created July 10, 2024 19:01
Code for the YouTube lecture "Principal Component Analysis from Scratch" (https://www.youtube.com/live/y9zS7Xm0iEU)
# Unit-Variance Scaling or Autoscaling
autoscale <- function(X) {
return(apply(X,2, function(x){ (x- mean(x)) / sd(x) }))
}
# Compute the covariance matrix
covariance <- function(X) {
cM <- matrix(NA, ncol(X), ncol(X), dimnames = list(colnames(X), colnames(X)))
for(x in colnames(X)) {
@DannyArends
DannyArends / microGPT.d
Created February 21, 2026 10:51
Andrej Karpathy's microgpt.py translated into the D programming language
/*
The most atomic way to train and run inference for a GPT in pure, dependency-free D.
This file is the complete algorithm,
Everything else is just efficiency.
@karpathy
Translation by @DannyArends
*/
import std.algorithm : countUntil, fold, joiner, map, maxElement, min, sort, sum, uniq;