Skip to content

Commit

Permalink
demo for warmstarting weights
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasKook committed Nov 1, 2024
1 parent 2c2734b commit 729fdad
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions inst/demos/warmstart.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Demo continuous response
# Lucas Kook
# Feb 2022

set.seed(1234)

# Deps --------------------------------------------------------------------

library(tram)
devtools::load_all(".")

# Data --------------------------------------------------------------------

data("BostonHousing2", package = "mlbench")

# Model -------------------------------------------------------------------

tm <- Colr(cmedv ~ nox + age, data = BostonHousing2, order = 6,
support = range(BostonHousing2$cmedv))
cfb <- coef(tm, with_baseline = TRUE)[1:7]

m <- deeptrafo(cmedv ~ 0 + nox + age, data = BostonHousing2, order = 6)

tmp <- get_weights(m$model)
tmp[[2]][] <- coef(tm)[1]
tmp[[3]][] <- coef(tm)[2]
tmp[[1]][] <- c(cfb[1], log(exp(diff(cfb)) - 1 + 1e-6))
set_weights(m$model, tmp)

# Compare shift coefs
coef(m)
coef(m, "shifting")

# Compare baseline coefs
coef(tm, with_baseline = TRUE)
unlist(coef(m, which = "interacting"))

# Compare logLik
logLik(tm)
logLik(m)

0 comments on commit 729fdad

Please sign in to comment.