Skip to content

Instantly share code, notes, and snippets.

Avatar

Bastiaan Quast bquast

View GitHub Profile
@bquast
bquast / dropout.py
Last active Oct 2, 2015
extended version of the Hilton's dropout code from http://iamtrask.github.io/2015/07/28/dropout/
View dropout.py
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))
View explore.R
# 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)
View manipulate-lm-outliers.R
# 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){
View packages.R
install.packages('broom') # use tidy() to format output to data.frame
install.packages('caret')
install.packages('neuralnet')
install.packages('NeuralNetTools')
install.packages('devtools') # develop packages / install from github
install.packages('ggvis')
install.packages('ggplot2')
install.packages('dplyr')
install.packages('corr')
install.packages('covr') # coveralls
View Extraordaniary-Least-Squares.R
els <- function(formula, data, ...){
first_stage <- lm(formula,data=data, ...)
lm(update(formula, fitted(first_stage)~.), data, ...)
}
View ggplot2-IHEID.R
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)
View QR-OLS.R
#### 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))
View ggplot2-default-palette.R
# * `set_default_scale` has been removed. If you want to change the default
# scale for an aesthetic, just create a function called
# `scale_aesthetic_continuous` or `scale_aesthetic_discrete` that returns the
# scale that you want. For example:
p <- qplot(mpg, wt, data = mtcars, colour = factor(cyl))
p
scale_colour_discrete <- scale_colour_brewer
p
View LSTM.R
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)
View RNN.R
# define some functions
## convert integer to binary
i2b <- function(integer, length=8)
as.numeric(intToBits(integer))[1:length]
## apply
int2bin <- function(integer, length=8)
t(sapply(integer, i2b, length=length))