liveBook · Manning

Determinism

As explained in Deep Learning with R, Third Edition

Determinism is the property that identical inputs and explicit state produce identical computational results.

Determinism means getting the same result when a computation receives the same inputs and explicit random state. JAX makes random state explicit: calls using the same PRNG key return the same values. section 3.5.3

To manage random values in JAX:

  • Create a PRNG key from an integer seed and pass it to random operations. section 3.5.3
  • Split a key to create a different key when you need new random values. section 3.5.3
  • In programs that combine R, Python, NumPy, and Keras, use keras3::set_random_seed() to set seeds across those systems; set.seed() affects only R. section 3.5.3
seed_key <- jax$random$key(123L)
jax$random$normal(seed_key, shape = shape(3))
jax$random$normal(seed_key, shape = shape(3))

Array([1.6359469 , 0.8408094 , 0.02212393], dtype = float32)

Array([1.6359469 , 0.8408094 , 0.02212393], dtype = float32)

The same JAX key passed to two normal-random calls produces identical arrays. section 3.5.3

seed_key <- jax$random$key(123L)
jax$random$normal(seed_key, shape = shape(3))

Array([1.6359469 , 0.8408094 , 0.02212393], dtype = float32)

new_seed_key <- jax$random$split(seed_key, num = 1L)@py[0]  #1
jax$random$normal(new_seed_key, shape = shape(3))

Array([-0.49093357, -0.9478693 , -1.775197  ], dtype = float32)

Splitting a key provides a different key and produces different random values. section 3.5.3

How Deep Learning with R, Third Edition covers it

How deep it goes
Demonstrates repeatable random calls and key splitting, without detailing PRNG internals.
Examples
Shows JAX normal samples generated with the same key and with a split key.
What it assumes
Contrasts hidden global random state with explicit seeds and keys.
What you can do after
Apply JAX PRNG keys to reproduce random values or generate new ones by splitting keys.
How it connects
Connects determinism to pseudorandom number generation, random seeds, and stateless programming.

Also explained in

Compare how 10 books explain determinism →

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.