liveBook · Manning

Global state

As explained in Deep Learning with R, Third Edition

Global state is mutable information maintained outside a function and implicitly shared across calls.

Global state is mutable information maintained outside a function and implicitly shared across calls. In R, random-number functions consult hidden global state, including .Random.seed, so repeated calls can produce different values. section 3.5.3

Randomness through hidden state

Calling runif(3) twice produces different results because the first call changes the random-number state used by the second. set.seed() can set that state, while keras3::set_random_seed() coordinates seeds across R, NumPy, Python, TensorFlow, and Torch. section 3.5.3

JAX avoids hidden global state. Its random operations receive explicit PRNG key objects, making identical calls with identical keys reproducible; jax$random$split() creates a new key for new values. section 3.5.3

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines hidden random state, demonstrates seed control, and contrasts it with JAX keys without detailing all purity mechanics.
Examples
Uses repeated runif() calls, an R noise function, and JAX PRNG keys to demonstrate reproducibility and state control.
What you can do after
Understand how to recognize hidden random state and make randomness reproducible with explicit seeds or JAX PRNG keys.
How it connects
Connects global state to pseudo-random number generation, random seeds, stateless programming, and pure functions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.