warmstart.k_ontram_ci: Set initial weights

View source: R/k-ontram_methods.R

warmstart.k_ontram_ciR Documentation

Set initial weights

Description

Set initial weights

Usage

## S3 method for class 'k_ontram_ci'
warmstart(
  object,
  thetas = NULL,
  betas = NULL,
  which = c("all", "baseline only", "shift only")
)

Arguments

thetas

intercepts of a Polr model as a vector (are added to the last layer during training).

betas

shift terms of a Polr model as a vector (used to initialize the weights of the simple shift model).

IMPORTANT

  • The warmstarted model has to be assigned to a new variable.

Examples

library(tram)
set.seed(2021)
data(wine, package = "ordinal")
wine$noise <- rnorm(nrow(wine))
y <- model.matrix(~ 0 + rating, data = wine)
x <- ontram:::.rm_int(model.matrix(rating ~ temp + contact, data = wine))
im <- ontram:::.rm_int(model.matrix(rating ~ noise, data = wine))
loss <- k_ontram_loss(ncol(y))
mod_polr <- Polr(rating ~ temp + contact, data = wine)
msh <- mod_shift(ncol(x))
mbl <- keras_model_sequential() %>%
  layer_dense(units = 8, input_shape = 1L, activation = "relu") %>%
  layer_dense(units = 16, activation = "relu") %>%
  layer_dense(units = ncol(y) - 1, use_bias = FALSE) %>%
  layer_trafo_intercept()()
mo <- k_ontram(mbl, msh, complex_intercept = TRUE)
mo <- warmstart(mo, thetas = coef(mod_polr, with_baseline = TRUE)[1:4L],
                betas = coef(mod_polr), which = "all")

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