R: Deep Learning BAMLSS

dl.bamlss {bamlss} | R Documentation

## 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, optimizer = "adam",
      epochs = 30, batch_size = NULL,
      nlayers = 2, units = 100, activation = "sigmoid",
      l1 = NULL, l2 = NULL,
      verbose = TRUE, ...)

    ## Predict method.
    ## S3 method for class 'dl.bamlss'
    predict(object, newdata,
      model = NULL, type = c("link", "parameter"),
      drop = TRUE, ...)

### Arguments

`object` | An object of class `"bamlss"` or a `bamlss.formula`.
`optimizer` | Character or call to optimizer functions to be used within `fit`. For character, options are: `"adam"` `"sgd"`, `"rmsprop"`, `"adagrad"`, `"adadelta"`, `"adamax"`, `"adam"`. The default is `optimizer_rmsprop` with learning rate set to `1e-04`.
`epochs` | Number of times to iterate over the training data arrays, see `fit`.
`batch_size` | Number of samples per gradient update, see `fit`.
`nlayers` | Number of hidden layers.
`units` | Number of nodes per hidden layer, can be a vector.
`activation` | Activation functions used for the hidden layers, can be a vector.
`l1` | Shrinkage parameter for L1 penalty.
`l2` | Shrinkage parameter for L2 penalty.
`verbose` | Print information during runtime of the algorithm.
`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.
`type` | If `type = "link"` the predictor of the corresponding `model` is returned. If `type = "parameter"` predictions on the distributional parameter scale are returned.
`drop` | If predictions for only one `model` are returned, the list structure is dropped.
`...` | For function `dl.boost()`, arguments passed to `bamlss.frame`.

### 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.

### 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!

### See Also

`bamlss.frame`, `bamlss`

### Examples

    ## 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, epochs = 2000)

    ## 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")

    ## Predict with newdata.
    nd <- data.frame(x = seq(-6, 6, length = 100))
    nd$p <- predict(b, newdata = nd, type = "link")

    par(mfrow = c(1, 2))
    plot(x, y, xlim = c(-6, 6), ylim = range(c(nd$p$mu, y)))
    plot2d(p$mu ~ x, data = nd, add = TRUE)
    plot2d(p$sigma ~ x, data = nd,
      ylim = range(c(nd$p$sigma, fsigma)))
    plot2d(fsigma ~ x, add = TRUE, col.lines = "red")

    ## Plot quantile residuals.
    e <- residuals(b)
    plot(e)

    ## End(Not run)

[Package bamlss version 1.1-6 Index]