airoldilab / sgd

An R package for large scale estimation with stochastic gradient descent
62 stars 18 forks source link

sgd gives different output on each run (should be deterministic given seed, either in R or C) #69

Closed dustinvtran closed 9 years ago

dustinvtran commented 9 years ago
library(sgd)

# Dimensions
N <- 1e4
d <- 1e2

# Generate data.
set.seed(42)
X <- matrix(rnorm(N*d), ncol=d)
theta <- rep(5, d+1)
eps <- rnorm(N)
y <- cbind(1, X) %*% theta + eps
dat <- data.frame(y=y, x=X)

sgd.theta <- sgd(y ~ ., data=dat, model="lm")
mean((sgd.theta$coefficients - theta)^2) # MSE