This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
els <- function(formula, data, ...){ | |
first_stage <- lm(formula,data=data, ...) | |
lm(update(formula, fitted(first_stage)~.), data, ...) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sigmoid function | |
sigmoid <- function(x) | |
1 / (1 + exp(-x) ) | |
# sigmoid derivative | |
sigmoid_output_to_derivative <- function(x) | |
x*(1-x) | |
# hidden layer size | |
hidden_dim = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## sigmoid function | |
sigmoid <- function(x, k=1, x0=0) | |
1 / (1+exp( -k*(x-x0) )) | |
## tanh^2 function | |
tanhsq <- function(x) | |
((exp(2*x)-1)^2)/((exp(2*x)+1)^2) | |
# define weights | |
Wa = matrix( c(0.45, 0.25), nrow=1 ); Ua = matrix(0.15); ba = matrix(0.20) |
OlderNewer