if (interactive() && keras::is_keras_available()) {
dist <- dist_exponential()
params <- list(rate = 1.0)
N <- 100L
rand_input <- runif(N)
x <- dist$sample(N, with_params = params)
tf_in <- keras::layer_input(1L)
mod <- tf_compile_model(
inputs = list(tf_in),
intermediate_output = tf_in,
dist = dist,
optimizer = keras::optimizer_adam(),
censoring = FALSE,
truncation = FALSE
)
tf_fit <- fit(
object = mod,
x = k_matrix(rand_input),
y = x,
epochs = 10L,
callbacks = list(
callback_debug_dist_gradients(mod, k_matrix(rand_input), x)
)
)
tf_preds <- predict(mod, data = k_matrix(rand_input))
}
Run the code above in your browser using DataLab