Skip to content

Instantly share code, notes, and snippets.

View frbl's full-sized avatar
🎯
Focusing

Frank Blaauw frbl

🎯
Focusing
View GitHub Profile
@frbl
frbl / gist:cae79f708cae75a20614
Created September 10, 2014 09:42
Copy all sty from a latex project to a directory single (depends om latexmk)
cat index.fdb_latexmk | grep .sty | awk -F' ' '{print $1}' | awk -F'"' '{print $2}' | xargs -J % cp % ~/test
@frbl
frbl / keybase.md
Created November 16, 2016 22:13
keybase.md

Keybase proof

I hereby claim:

  • I am frbl on github.
  • I am frbl (https://keybase.io/frbl) on keybase.
  • I have a public key whose fingerprint is 8756 D347 8013 8489 9210 FDD0 1BC7 5A3E 743F 90E1

To claim this, I am signing this object:

@frbl
frbl / sample_runif.R
Last active March 28, 2017 23:24
Sample from uniform distribution given a list of intervals
data <- c(1,2,1,3,2,1,2,3)
intervals <- c(0.1, 0.3, 0.6,1)
runif(data, intervals[data], intervals[data+1])
# Test if the output is correct:
check <- all(unlist(lapply(1:length(data), function(i) {res[i] >= intervals[data[i]] & res[i] <= intervals[data[i] + 1]})))
expect_true(check)
@frbl
frbl / notebook.sh
Created May 17, 2017 22:01
General script to run a notebook server in the current directory (uses docker)
#!/usr/bin/env sh
lib_dir=~/.R/lib/notebooks
mkdir -p $lib_dir
`sleep 3; open http://127.0.0.1:8888` &
docker run --rm -it \
-p 127.0.0.1:8888:8888 \
-v `pwd`:/home/jovyan/work \
-v $lib_dir:/usr/local/spark-2.1.0-bin-hadoop2.7/R/lib \
frbl/docker-notebook \
start-notebook.sh \
@frbl
frbl / data_export.html
Created June 11, 2017 09:12
Simpel voorbeeldje voor het lezen van de JSON
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
</head>
<body>
<ul id='data'>
</ul>
@frbl
frbl / bounded_logistic_regression.R
Last active November 3, 2017 16:55
Logistic regression with predicted probabilities constrained / capped / thresholded
#!/usr/bin/env Rscript
## Constrained logistic regression
## In this gist we create a regression for which the predicted probabilities are contstrained. That is, they can not be
## less than a minimum of delta, or a maxiumum of 1 - delta.
## Based on:
## - https://stats.idre.ucla.edu/r/dae/logit-regression/
## - https://github.com/achambaz/tsml.cara.rct/blob/2b2aa282d4a11c601b37cacb368b67d03f6e8fc9/R/misc.R#L440
## - https://github.com/achambaz/tsml.cara.rct/blob/fd426c2a6f91b692d379b4765d9900151d09daa6/R/targetGstar.R#L1
@frbl
frbl / glm_logistic_treatment.R
Last active October 19, 2017 17:20
Delta - A Treatment example
Osample_p_full <- read.csv('http://frbl.eu/files/gist_ac602828fedba735b4d1e4cb16472cbe.csv')
formula <- Delta ~ W + A
glm_pred <- glm(formula = formula(formula), data = Osample_p_full, family= binomial())
print(glm_pred)
# Call: glm(formula = formula(formula), family = binomial(), data = Osample_p_full)
#
# Coefficients:
# (Intercept) A W
# 18.378 -19.241 0.379
@frbl
frbl / difference_between_rbind_rbindlist.R
Created October 24, 2017 09:24
Difference between rbind and rbindlist in terms of time, for appending a single row
library(microbenchmark)
library(data.table)
rbindlist_time <- function() {
data <- data.table(a=c(1),b=c(2))
for (item in 1:10000) {
data <- rbindlist(data, data.table(a=c(1),b=c(2)))
}
}
@frbl
frbl / xgboost_failing_update.R
Created October 24, 2017 21:38
Example of the update of XGBoost not working.
set.seed(12345)
library('data.table')
library('xgboost')
## Create simulation function
give_me_data <- function(nobs, delta = 0.05) {
X_mat <- data.table(A = rnorm(nobs, 0, 1), B = rnorm(nobs, 0, 1))
probs <- pmax(as.numeric(X_mat$A > 0) - 2*delta, 0) + delta
X_mat <- as.matrix(X_mat)
Y_vals <- rbinom(nobs, 1, probs)
@frbl
frbl / eduroam
Created June 5, 2018 07:02
RUG / University of Groningen - Eduroam configuration for Linux /etc/NetworkManager/system-connections/eduroam
[connection]
id=eduroam
uuid=<THIS_CAN_BE_AUTOGENERATED>
type=wifi
permissions=user:<PC_USERNAME>:;
[wifi]
mac-address=<MACADDRESS_OF_YOUR_WLAN_CARD>
mac-address-blacklist=
mode=infrastructure