Skip to contents

Uses reticulate to call Python's torch.save on a model object returned from run_cissvae (or any Python model in the R session).

Usage

save_cissvae_model(model, file)

Arguments

model

Python model object (e.g., res$model from run_cissvae)

file

Path where the model will be saved (e.g., "trained_vae.pt")

Value

NULL. Called for side effects.

Examples

# \donttest{
## Requires a working Python environment via reticulate
## Examples are wrapped in try() to avoid failures on CRAN check
try({
  reticulate::use_virtualenv("cissvae_environment", required = TRUE)
  data(df_missing)
  data(clusters)

  ## Run CISS-VAE training
  dat <- try(
    run_cissvae(
      data = df_missing,
      index_col = "index",
      val_proportion = 0.1,
      cols_ignore = c(
        "Age", "Salary", "ZipCode10001", "ZipCode20002", "ZipCode30003"
      ),
      clusters = clusters$clusters,
      epochs = 5,
      return_silhouettes = FALSE,
      return_history = TRUE,
      verbose = FALSE,
      return_model = TRUE,
      device = "cpu",
      layer_order_enc = c("unshared", "shared", "unshared"),
      layer_order_dec = c("shared", "unshared", "shared")
    ),
    silent = TRUE
  )

  ## Save the trained model to a temporary file (CRAN-safe)
  tmpfile <- tempfile(fileext = ".pt")
  try(save_cissvae_model(dat$model, tmpfile), silent = TRUE)
})# }