frho.para <- xdim <- 1 ##predictor dimension
frho <- 'additive' ###truth is a sum of absolute functions
type <- 'cosine' ###use cosine functions as the basis functions
#generate training data
TrainData <- GenSamples(s.size = 1e3, xdim = xdim,
frho.para = frho.para,
frho = frho, noise.para = 0.1)
#preprocess the model
sieve.model <- sieve.sgd.preprocess(X = TrainData[,2:(xdim+1)],
type = type,
s = c(1,2),
r0 = c(0.5, 2, 4),
J = c(1, 4, 8))
##train the model
sieve.model <- sieve.sgd.solver(sieve.model = sieve.model,
X = TrainData[,2:(xdim+1)],
Y = TrainData[,1])
##sieve-SGD can do multiple passes over the data, just like other SGD methods.
##usually a second pass can still improve the prediction accuracy
##watch out overfitting when performing multiple passes!
sieve.model <- sieve.sgd.solver(sieve.model = sieve.model,
X = TrainData[,2:(xdim+1)],
Y = TrainData[,1])
Run the code above in your browser using DataLab