bamlss (version 1.1-2)

dl.bamlss: Deep Learning BAMLSS

Description

This function interfaces keras infrastructures for high-level neural networks. The function can be used as a standalone model fitting engine such as bamlss or as an on top model engine to capture special features in the data that could not be captures by other model fitting engines.

Usage

## Deep learning bamlss.
dl.bamlss(object, offset = NULL, weights = NULL,
  eps = .Machine$double.eps^0.25, maxit = 100,
  force.stop = TRUE, epochs = 30, optimizer = NULL,
  batch_size = NULL, keras.model = NULL,
  verbose = TRUE, digits = 4, ...)

## Predict method. # S3 method for dl.bamlss predict(object, newdata, model = NULL, drop = TRUE, ...)

Arguments

object

An object of class "bamlss" or a bamlss.formula.

offset

A list or data.frame. Can be used to supply model offsets for use in fitting, e.g., fitted values from an initial model fit.

weights

Prior weights on the data.

eps

The relative convergence tolerance of the algorithm.

maxit

Integer, maximum number of iterations of the algorithm.

force.stop

Logical. should the algorithm stop if relative change is smaller than eps.

epochs

Number of times to iterate over the training data arrays, see fit.

optimizer

Character or call to optimizer functions to be used within fit. For character, options are: "adam" "sgd", "rmsprop", "adagrad", "adadelta", "adamax", "nadam". The default is optimizer_rmsprop with learning rate set to 1e-04.

batch_size

Number of samples per gradient update, see fit.

keras.model

A compiled model using keras, e.g., using keras_model_sequential and compile. Note that the last layer only has one unit with linear activation function.

verbose

Print information during runtime of the algorithm.

digits

Set the digits for printing when verbose = TRUE.

newdata

A list or data.frame that should be used for prediction.

model

Character or integer specifying for which distributional parameter predictions should be computed.

drop

If predictions for only one model are returned, the list structure is dropped.

For function dl.boost(), arguments passed to bamlss.frame.

Value

For function dl.bamlss() an object of class "dl.bamlss". Note that extractor functions fitted and residuals.bamlss can be applied. For function predict.dl.bamlss() a list or vector of predicted values.

WARNINGS

The BAMLSS deep learning infrastructure is still experimental!

Details

The default keras model is a sequential model with two hidden layers with "relu" activation function and 100 units in each layer. Between each layer is a dropout layer with 0.1 dropout rate.

See Also

bamlss.frame, bamlss

Examples

Run this code
# NOT RUN {
## Simulate data.
set.seed(123)
n <- 300
x <- runif(n, -3, 3)
fsigma <- -2 + cos(x)
y <- sin(x) + rnorm(n, sd = exp(fsigma))

## Setup model formula.
f <- list(
  y ~ x,
  sigma ~ x
)

## Fit neural network.
library("keras")
b <- dl.bamlss(f)

## Plot estimated functions.
par(mfrow = c(1, 2))
plot(x, y)
plot2d(fitted(b)$mu ~ x, add = TRUE)
plot2d(fitted(b)$sigma ~ x,
  ylim = range(c(fitted(b)$sigma, fsigma)))
plot2d(fsigma ~ x, add = TRUE, col.lines = "red")

## Another example identifying structures that are
## not captured by the initial model.
set.seed(123)
d <- GAMart()
b1 <- bamlss(num ~ s(x1) + s(x2) + s(x3), data = d, sampler = FALSE)
b2 <- dl.bamlss(num ~ lon + lat, data = d, offset = fitted(b1))
p <- predict(b2, model = "mu")
par(mfrow = c(1, 1))
plot3d(p ~ lon + lat, data = d, symmetric = FALSE)
# }

Run the code above in your browser using DataLab