warmstart.k_ontram: Set initial weights

View source: R/k-ontram_methods.R

warmstart.k_ontramR Documentation

Set initial weights

Description

Set initial weights

Usage

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

Arguments

object

an object of class k_ontram.

thetas

intercepts of a Polr model as a vector (used to initialize the weights of the baseline model).

betas

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

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)
mbl <- k_mod_baseline(ncol(y))
msh <- mod_shift(ncol(x))
mim <- keras_model_sequential() %>%
  layer_dense(units = 8, input_shape = 1L, activation = "relu") %>%
  layer_dense(units = 16, activation = "relu") %>%
  layer_dense(units = 1, use_bias = FALSE)
mo <- k_ontram(mbl, list(msh, mim))
mo <- warmstart(mo, thetas = coef(mod_polr, with_baseline = T)[1:4L],
                which = "baseline only")
coef(mod_polr, with_baseline = TRUE)
ontram:::.to_theta(get_weights(mo$mod_baseline)[[1]])

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