continue_training: Continues training of a model generated with 'dnn', 'cnn' or...

View source: R/continue_training.R

continue_trainingR Documentation

Continues training of a model generated with dnn, cnn or mmn for additional epochs.

Description

If the training/validation loss is still decreasing at the end of the training, it is often a sign that the NN has not yet converged. You can use this function to continue training instead of re-training the entire model.

Usage

continue_training(model, ...)

## S3 method for class 'citodnn'
continue_training(
  model,
  epochs = 32,
  data = NULL,
  device = NULL,
  changed_params = NULL,
  init_optimizer = TRUE,
  X = NULL,
  Y = NULL,
  weights = NULL,
  ...
)

## S3 method for class 'citodnnBootstrap'
continue_training(
  model,
  epochs = 32,
  data = NULL,
  device = NULL,
  changed_params = NULL,
  parallel = FALSE,
  init_optimizer = TRUE,
  X = NULL,
  Y = NULL,
  ...
)

## S3 method for class 'citocnn'
continue_training(
  model,
  epochs = 32,
  X = NULL,
  Y = NULL,
  weights = NULL,
  device = NULL,
  changed_params = NULL,
  init_optimizer = TRUE,
  ...
)

## S3 method for class 'citommn'
continue_training(
  model,
  epochs = 32,
  dataList = NULL,
  device = NULL,
  changed_params = NULL,
  init_optimizer = TRUE,
  weights = NULL,
  ...
)

Arguments

model

a model created by dnn, cnn or mmn

...

class-specific arguments

epochs

additional epochs the training should continue for

data

matrix or data.frame. If not provided data from original training will be used

device

can be used to overwrite device used in previous training

changed_params

list of arguments to change compared to original training setup, see dnn which parameter can be changed

init_optimizer

re-initialize optimizer or not

X

Predictor data. If not provided X from original training will be used

Y

Target data. If not provided Y from original training will be used

weights

observation weights (vector or matrix) passed to the likelihood. If not provided, the weights from the original training are reused when continuing on the original data

parallel

train bootstrapped model in parallel

dataList

A list containing the data for training the model. The list should contain all variables used in the formula. If not provided dataList from original training will be used

Value

a model of class citodnn, citodnnBootstrap, citocnn or citommn created by dnn, cnn or mmn

Examples


if(torch::torch_is_installed()){
library(cito)

set.seed(222)
validation_set<- sample(c(1:nrow(datasets::iris)),25)

# Build and train  Network
nn.fit<- dnn(Sepal.Length~., data = datasets::iris[-validation_set,], epochs = 32)

# continue training for another 32 epochs
nn.fit<- continue_training(nn.fit,epochs = 32)

# Use model on validation set
predictions <- predict(nn.fit, iris[validation_set,])
}


cito documentation built on Nov. 23, 2026, 5:07 p.m.