Skip to content

Instantly share code, notes, and snippets.

View breuderink's full-sized avatar

Boris Reuderink breuderink

View GitHub Profile
@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 / 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 / ttls.m
Created June 17, 2026 19:38
Gemini TTLS
function [beta, beta0] = truncated_tls(X, y, k)
% TRUNCATED_TLS Computes the Truncated Total Least Squares solution.
%
% Inputs:
% X : Matrix of predictors (n x p)
% y : Target column vector (n x 1)
% k : Truncation rank (number of singular values to KEEP)
% Must satisfy: 1 <= k <= p
%
% Outputs: