Skip to content

Instantly share code, notes, and snippets.

View breuderink's full-sized avatar

Boris Reuderink breuderink

View GitHub Profile
@breuderink
breuderink / lagged.py
Created May 21, 2020 18:05
Filling missing values with lagged observations
import numpy as np
def lag(x, n=0):
observed = np.isnan(x) == False
observed[0] = True
offsets = np.flatnonzero(observed)
return offsets[np.maximum(np.cumsum(observed) - 1 - n, 0)]
@breuderink
breuderink / Dockerfile
Created January 15, 2020 09:23
LiNGAM docker image
FROM jupyter/datascience-notebook
USER root
RUN apt-get update && apt-get install -yq graphviz
USER $NB_USER
RUN pip install lingam graphviz
@breuderink
breuderink / fx.c
Created November 30, 2019 20:19
SORF
#include "fx.h"
#include <stddef.h>
#include <stdint.h>
#include <math.h>
#include <assert.h>
void static inline wht_butterfly(float * const s, float * const d) {
float temp = *s;
*s += *d;
*d = temp - *d;
@breuderink
breuderink / expander.c
Last active September 9, 2019 14:17
expander graph
// Generate expander graph. See https://mathoverflow.net/q/124714.
// cc expander.c -o expander && ./expander | \
// neato -Tpng -o expander.png -Goverlap=false -Gsplines=true
// From https://rosettacode.org/wiki/Modular_inverse#C
int mod_inv(int a, int b) {
int b0 = b, t, q;
int x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a > 1) {
@breuderink
breuderink / idw.c
Last active July 7, 2019 14:41
Inverse distance weighting
#include <assert.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
typedef struct {
size_t size[2];
size_t stride[2];
float *elements;
@breuderink
breuderink / cartpolev1.tsv
Last active February 23, 2018 21:17
Dump SARS from AI Gym
-0.044 -0.15 0.013 0.28 1 1 -0.047 0.046 0.018 -0.013
-0.047 0.046 0.018 -0.013 1 1 -0.046 0.24 0.018 -0.3
-0.046 0.24 0.018 -0.3 0 1 -0.041 0.046 0.012 -0.0013
-0.041 0.046 0.012 -0.0013 1 1 -0.04 0.24 0.012 -0.29
-0.04 0.24 0.012 -0.29 1 1 -0.035 0.44 0.0063 -0.58
-0.035 0.44 0.0063 -0.58 1 1 -0.026 0.63 -0.0053 -0.87
-0.026 0.63 -0.0053 -0.87 1 1 -0.014 0.83 -0.023 -1.2
-0.014 0.83 -0.023 -1.2 1 1 0.0027 1 -0.046 -1.5
0.0027 1 -0.046 -1.5 1 1 0.023 1.2 -0.075 -1.8
0.023 1.2 -0.075 -1.8 1 1 0.047 1.4 -0.11 -2.1
@breuderink
breuderink / Makefile
Created October 3, 2017 11:29
Calling C from Python
libsum.so: sum.c
cc -shared -o libsum.so sum.c
@breuderink
breuderink / tdc.c
Created September 22, 2017 10:53
Linear TD with gradient correction
// [1] Sutton, Richard S., et al. "Fast gradient-descent methods for
// temporal-difference learning with linear function approximation."
// Proceedings of the 26th Annual International Conference on Machine
// Learning. ACM, 2009.
#define TDC_NFEAT 4
typedef struct {
float gamma;
float theta[TDC_NFEAT], w[TDC_NFEAT];
@breuderink
breuderink / most_normal.py
Last active September 19, 2017 18:51
The hunt for the most normal scrambler for SORM features.
from scipy import linalg, stats
import numpy as np
from functools import reduce
N = 16
def eval_scrambler(pat, reps=1):
pat = np.atleast_1d(pat)
D = np.diag(np.where(pat==1, -1, 1))
H = linalg.hadamard(pat.size)
@breuderink
breuderink / halton.go
Created April 24, 2017 19:59
halton.go
package main
import (
"fmt"
)
func main() {
// Implementation of baseline fixed-point algorithm in [1].
//
// [1] Kolář, Miroslav, and Seamus F. O'Shea. "Fast, portable, and