save_shrinkGPR: Save a fitted shrinkGPR model object to disk

View source: R/save_load.R

save_shrinkGPRR Documentation

Save a fitted shrinkGPR model object to disk

Description

save_shrinkGPR saves a fitted model object to a single .zip file, preserving the trained model, optimizer state, and all metadata needed for prediction and continued training via cont_model.

Usage

save_shrinkGPR(obj, file)

Arguments

obj

an object of class shrinkGPR, shrinkTPR, shrinkMVGPR, or shrinkMVTPR, as returned by the corresponding fitting function.

file

a character string specifying the file path to save to.

Details

Internally, the model components are saved as separate files via torch_save and bundled into a single .zip archive. This is necessary because torch nn_module objects contain external pointers that cannot be serialized within a nested list. The plain R components (loss history, model internals) are saved via saveRDS.

Value

Invisibly returns the file path.

Author(s)

Peter Knaus peter.knaus@wu.ac.at

See Also

load_shrinkGPR

Examples


if (torch::torch_is_installed()) {
  # Fit a model and save it
  sim <- simGPR()
  mod <- shrinkGPR(y ~ ., data = sim$data)
  tmp <- tempfile(fileext = ".zip")
  save_shrinkGPR(mod, tmp)

  # Load it back
  mod_loaded <- load_shrinkGPR(tmp)

  # Continue training
  mod2 <- shrinkGPR(y ~ ., data = sim$data, cont_model = mod_loaded)
  }


shrinkGPR documentation built on March 30, 2026, 5:06 p.m.