Skip to content

Instantly share code, notes, and snippets.

View bquast's full-sized avatar
:octocat:

Bastiaan Quast bquast

:octocat:
View GitHub Profile
@bquast
bquast / LSTM.R
Last active October 13, 2016 17:08
set.seed(1)
# define some functions
## convert integer to binary
i2b <- function(integer, length=8)
as.numeric(intToBits(integer))[1:length]
## apply
int2bin <- function(integer, length=8)
#### OLS by hand
solve(qr.R(qr(freeny.x)))%*%t(qr.Q(qr(freeny.x)))%*%freeny.y
QR1<- qr(freeny.x)
solve(qr.R(QR1))%*%t(qr.Q(QR1))%*%freeny.y
solve(qr.R(QR1))%*%crossprod(qr.Q(QR1),freeny.y)
backsolve(qr.R(QR1),crossprod(qr.Q(QR1),freeny.y))
coef(lm(freeny.y~freeny.x -1))
library(ggplot2)
library(scales)
library(gridExtra)
darkRed <- rgb(199,35,28, maxColorValue = 255)
darkGray <- rgb(128,128,128, maxColorValue = 255)
darkOLDblue <- rgb(0,15,118, maxColorValue = 255)
lightgray <- rgb(200,200,200, maxColorValue = 255)
els <- function(formula, data, ...){
first_stage <- lm(formula,data=data, ...)
lm(update(formula, fitted(first_stage)~.), data, ...)
}
# https://designdatadecisions.wordpress.com/2016/05/05/manipulated-regression/
# Jyothi Subramanian, Ph. D.
library(manipulate)
## First define a custom function that fits a linear regression line
## to (x,y) points and overlays the regression line in a scatterplot.
## The plot is then 'manipulated' to change as y values change.
linregIllustrate <- function(x, y, e, h.max, h.med){
# create explore function
# to be applied to data.frames created by importing using the haven package
# https://cran.r-project.org/package=haven
# also available in the explore package:
# https://github.com/bquast/explore
explore <- function(data) {
description <- sapply(data, attr, "label")
variables <- names(description)
@bquast
bquast / dropout.py
Last active October 2, 2015 12:28
extended version of the Hilton's dropout code from http://iamtrask.github.io/2015/07/28/dropout/
import numpy as np
alpha = 0.1
hidden_dim = 4
dropout_percent = 0.05
do_dropout = True
# compute sigmoid nonlinearity
def sigmoid(x):
output = 1/(1+np.exp(-x))