Skip to contents

Sets random seeds for R and Keras to support reproducible neural network training. This is a convenience wrapper around set.seed and set_random_seed.

Usage

set_random_seed(seed)

Arguments

seed

Integer seed value.

Value

Invisibly returns NULL. Called for side effects.

Details

Neural network training involves randomness from R (data shuffling and CV fold creation) and Keras/TensorFlow (weight initialization and dropout).

Seed both to reproduce a training run as closely as possible. Call this function immediately before each training call because landscape generation and other R operations advance R's random-number stream. Minor variations may still occur across different hardware and software configurations.

See also

Examples

if (FALSE) { # requireNamespace("reticulate", quietly = TRUE) && reticulate::virtualenv_exists("r-keras")
# Generate reproducible training data
set.seed(42)
landscapes <- create_landscapes(n = 6, patterns = c("sharp", "random"))

# Reset both random-number generators immediately before training
set_random_seed(42)
model <- train_pixel_model(landscapes, cv_method = "none", epochs = 5)
}