fit_ontram: Function for estimating the model

View source: R/fit_ontram.R

fit_ontramR Documentation

Function for estimating the model

Description

Function for estimating the model

Usage

fit_ontram(
  model,
  history = FALSE,
  x_train = NULL,
  y_train,
  img_train = NULL,
  x_test = NULL,
  y_test = NULL,
  img_test = NULL,
  verbose = FALSE,
  early_stopping = FALSE,
  patience = 1,
  min_delta = 0,
  stop_train = FALSE,
  save_best = FALSE,
  filepath = NULL,
  warm_start = FALSE,
  weights = NULL,
  eval_batchwise = TRUE,
  img_augmentation = FALSE,
  aug_params = list(horizontal_flip = TRUE, vertical_flip = TRUE, zoom_range = 0.2,
    rotation_range = 30, width_shift_range = 0.15, height_shift_range = 0.15, fill_mode =
    "nearest")
)

Arguments

model

an object of class ontram.

history

logical. If TRUE train and test loss are returned as a list.

x_train, y_train, img_train

data used for training the model.

x_test, y_test, img_test

data used for evaluating the model.

verbose

logical. Whether to print current training loss when history = TRUE).

early_stopping

logical. Whether to use early stopping (requires history = TRUE).

patience

number of epochs with no improvement after which training will be stopped.

min_delta

minimum increase in test loss considered as no improvement.

stop_train

logical. Whether model should be trained for all epochs.

save_best

logical. Whether best model should be saved as HDF file.

filepath

path where to save best model if save_best = TRUE.

warm_start

logical. Whether initial weights should be non-random.

weights

output output of get_weights_ontram or list of similar structure;

eval_batchwise

logical.

img_augmentation

logical. Whether to augment training images.

aug_params

list with arguments used for image_data_generator.

Examples

data("wine", package = "ordinal")
fml <- rating ~ temp + contact
x_train <- model.matrix(fml, data = wine)[, -1L]
y_train <- model.matrix(~ 0 + rating, data = wine)
x_valid <- x_train[1:20,]
y_valid <- y_train[1:20,]

mo1 <- ontram_polr(x_dim = ncol(x_train), y_dim = ncol(y_train),
                   method = "logit", n_batches = 10, epochs = 50)
mo1hist <- fit_ontram(mo1, x_train = x_train, y_train = y_train, history = TRUE,
                      x_test = x_valid, y_test = y_valid)
plot(mo1hist)

mbl <- keras_model_sequential() %>%
          layer_dense(units = 16, activation = "relu", input_shape = ncol(x_train)) %>%
          layer_dense(units = 16, activation = "relu") %>%
          layer_dense(units = 16, activation = "relu") %>%
          layer_dense(units = 16, activation = "relu") %>%
          layer_dense(units = ncol(y_train) - 1L)
mo2 <- ontram(mod_bl = mbl, mod_sh = NULL, mod_im = NULL, y_dim = ncol(y_train),
              x_dim = NULL, img_dim = NULL, method = "logit",
              epochs = 50, response_varying = TRUE)
mo2hist <- fit_ontram(mo2, x_train = NULL, y_train = y_train, img_train = x_train,
                      x_test = NULL, y_test = y_valid, img_test = x_valid,
                      history = TRUE, early_stopping = TRUE, stop_train = FALSE)
plot(mo2hist, add_best = TRUE, ylim = c(0, 2.5))

LucasKookUZH/ontram-pkg documentation built on March 27, 2023, 6:05 p.m.