x <- as.matrix(iris[,"Petal.Length",drop=FALSE])
y <- as.matrix(iris[,"Petal.Width",drop=FALSE])
cases <- order(x)
x <- x[cases,,drop=FALSE]
y <- y[cases,,drop=FALSE]
set.seed(1)
## MCQRNN model w/ 2 hidden layers for simultaneous estimation of
## multiple non-crossing quantile functions
fit.mcqrnn <- mcqrnn.fit(x, y, tau=seq(0.1, 0.9, by=0.1),
n.hidden=2, n.hidden2=2, n.trials=1,
iter.max=500)
pred.mcqrnn <- mcqrnn.predict(x, fit.mcqrnn)
## Estimate the full quantile regression process by specifying
## the number of samples/random values of tau used in training
fit.full <- mcqrnn.fit(x, y, tau=1000L, n.hidden=3, n.hidden2=3,
n.trials=1, iter.max=300, eps.seq=1e-6,
method="adam", minibatch=64, print.level=100)
# Show how to initialize from previous weights
fit.full <- mcqrnn.fit(x, y, tau=1000L, n.hidden=3, n.hidden2=3,
n.trials=1, iter.max=300, eps.seq=1e-6,
method="adam", minibatch=64, print.level=100,
init.range=fit.full$weights)
pred.full <- mcqrnn.predict(x, fit.full, tau=seq(0.1, 0.9, by=0.1))
par(mfrow=c(1, 2))
matplot(x, pred.mcqrnn, col="blue", type="l")
points(x, y)
matplot(x, pred.full, col="blue", type="l")
points(x, y)
Run the code above in your browser using DataLab