Module: random

Random-number generation nodes.

This package includes nodes for drawing samples from random distributions (usually outputting arrays), and for managing random seeds and chainable keys.

CreateRandomSeed

Create a (splittable) random seed for deterministic random number generation.

Random operations, such as RandomNormal will by default use a global random state, which makes them non-deterministic in practice. Sometimes this is fine, but for many applications it is necessary to have deterministic random numbers, and to do so even in parallel computing contexts. Therefore all random operations optionally accept a "seed", which ensures that the operation will produce the same results every time it is run. For sequences of random operations one therefore has to generate new seeds for each successive operation from an initial seed to prevent them from all producing the same results. One might naively just use RandomIntegers (randint) to generate multiple fresh integer seeds for this purpose, but this is a flawed approach (the computations can yield shifted but identical random numbers). Instead, NeuroPype provides the "Split Random Seed" node for this purpose, which uses a key splitting algorithm. Additionally there are a number of convenience facilities to avoid having to manually deal with key splitting, including 1) the ability to draw seeds "out of thin air" as needed using the "Draw Random Seed" (DrawRandomSeed) node. This requires that there is a "With Random Seed" (WithRandomSeed) node somewhere downstream in the pipeline, which takes a global randseed and supplies a derived sequence of seeds to nodes that run under its managed context). As a result of using key splitting, NeuroPype's seeds are arrays (which have sufficient entropy) rather than integers, and arrays of keys (generated by some nodes) come as 2d arrays. Lastly, there is also the ability to mix an existing seed and additional data, such as a worker or task ID, to generate a derived seed that will be unique yet deterministic for each parallel task, using the "Derive Random Seed" (DeriveRandomSeed) node. Another handy node is RandomSeedIterator, which can be used just like e.g., ListIterator or PathIterator to iterate over a series of successive seeds without the need for WithRandomSeed. Different compute backends tend to have their own implementation of splittable seeds, and for this reason it is a good practice to use the same backend for both the seed management and the random operations, but this is only relevant if you are overriding compute backends (this is very easy using the With Backend node, which runs all operations under it on a specified backend).

Version 0.5.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • key
    Splittable random seed.

    • verbose name: Key
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • seed
    Initial random seed.

    • verbose name: Seed
    • default value: 1234
    • port type: IntPort
    • value type: int (can be None)
  • algorithm
    Random number generation algorithm for which to generate a seed. The default depends on the chosen backend, and not all backends support all algorithms. For this reason it is recommended to use the default.

    • verbose name: Algorithm
    • default value: default
    • port type: EnumPort
    • value type: str (can be None)
  • backend
    Optional compute backend for which to generate the seed. Keep is the current default, which is typically numpy, but which can be overridden in contexts that require it. Some backends (notably jax and tensorflow) require that the seed be generated using the same backend as the downstream random operation. For this reason, it is a good idea to use the same backend for both the seed management and the random operation to future-proof one's pipeline.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

DeriveRandomSeed

Derive a new random seed from an initial seed and some data.

This can be used to "specialize" a seed for a particular use to ensure unique but determinitic random numbers. An example is a deterministic parallel computation with N workers, where each worker needs a unique seed that is however derived from a common initial seed. The initial seed must have been generated using the Create Random Seed node.

Version 0.5.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • key
    Splittable random seed.

    • verbose name: Key
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: INOUT
  • data
    Data to fold into the seed.

    • verbose name: Data
    • default value: 0
    • port type: IntPort
    • value type: int (can be None)
  • algorithm
    Random number generation algorithm for which to generate a seed. The default depends on the chosen backend, and not all backends support all algorithms. For this reason it is recommended to use the default.

    • verbose name: Algorithm
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • backend
    Optional compute backend for which to generate the seed. Keep is the current default, which is typically numpy, but which can be overridden in contexts that require it. Some backends (notably jax and tensorflow) require that the seed be generated using the same backend as the downstream random operation. For this reason, it is a good idea to use the same backend for both the seed management and the random operation to future-proof one's pipeline.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

DrawRandomSeed

Draw a random seed from the currently sequence of deterministic random seeds, if one is set.

This seed can be passed into a random operation to ensure that the operation will yield deterministic results (i.e., the same results for every run of the program). This node can only be used in a context where such a sequence has been set, which can be done by putting a WithRandomSeed node at the end of the computation/graph, which acts as a context manager.

Version 0.5.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • key
    Splittable random seed.

    • verbose name: Key
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • num
    Number of seeds to draw. If more than one is drawn, keys will be a correspondingly larger array.

    • verbose name: Number Of Seeds
    • default value: 1
    • port type: IntPort
    • value type: int (can be None)
  • from_context
    Ambient context from which to draw the random seed. The auto mode will attempt to use first the deep learning context, then the Bayesian context, and finally the WithRandomSeed context. If set to WithRandomSeed, the next random seed provided by the nearest enclosing WithRandomSeed node is used. If set to deep learning, the seed provided by the nearest enclosing deep-learning context (usually DeepModel, but can also be NetTransform) is used. If set to bayes, the seed provided by the nearest enclosing Bayesian inference context is used (usually one of the Inference nodes).

    • verbose name: From Context
    • default value: auto
    • port type: EnumPort
    • value type: str (can be None)
  • backend
    Optional compute backend for which to generate the seed. Keep is the current default, which is typically numpy, but which can be overridden in contexts that require it. Some backends (notably jax and tensorflow) require that the seed be generated using the same backend as the downstream random operation. For this reason, it is a good idea to use the same backend for both the seed management and the random operation to future-proof one's pipeline.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • from_haiku_context
    Legacy option, use from_context instead.

    • verbose name: From Haiku Context
    • default value: None
    • port type: AliasPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomChoice

Draw a random subset from the set of integers from 0 to a given total minus 1, without replacement.

This can then be used as an index set to select from some data. This is similar to first generating a permutation of the integers and then taking the first n elements of that permutation. For drawing with replacement, see the Random Integers node. If deterministic results are sought, pass in a seed; see also CreateRandomSeed for documentation on how seeds are best managed. The node supports alternative compute backends, which can be used to speed up processing.

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • array
    Output array.

    • verbose name: Array
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • like
    Optional template array.

    • verbose name: Like
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • seed
    Random seed for deterministic results.

    • verbose name: Seed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • shape
    Shape of the array. Can be omitted if a template array is provided.

    • verbose name: Shape
    • default value: []
    • port type: ListPort
    • value type: list (can be None)
  • total
    Total number of elements from which the subset is taken.

    • verbose name: Total
    • default value: 100
    • port type: IntPort
    • value type: int (can be None)
  • backend
    Optional compute backend to use. Keep is the current default, which resolves to that of the template array if one is provided and otherwise numpy unless overridden. Numpy is the standard CPU backend that underpins most of NeuroPype's operations. The others require one or more GPUs to be present on the system, except for torch-cpu. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • precision
    Numeric precision to use. Keep resolves to the precision of the template array if one is provided, and otherwise to the current default (usually 64-bit). Can be reduced to save memory (e.g. if running on GPU).

    • verbose name: Precision
    • default value: int32
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomGamma

Draw an array of random numbers from a gamma distribution with a given mean and standard deviation, optionally matching a template array in shape and optionally data type.

If deterministic results are sought, pass in a seed; see also CreateRandomSeed for documentation on how seeds are best managed. The node supports alternative compute backends, which can be used to speed up processing.

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • array
    Output array.

    • verbose name: Array
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • like
    Optional template array.

    • verbose name: Like
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • seed
    Random seed for deterministic results.

    • verbose name: Seed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • shape
    Shape of the array. Can be omitted if a template array is provided.

    • verbose name: Shape
    • default value: []
    • port type: ListPort
    • value type: list (can be None)
  • k
    Shape parameter of the distribution.

    • verbose name: K
    • default value: 1
    • port type: FloatPort
    • value type: float (can be None)
  • scale
    Scale parameter of the distribution (theta).

    • verbose name: Scale
    • default value: 1
    • port type: FloatPort
    • value type: float (can be None)
  • backend
    Optional compute backend to use. Keep is the current default, which resolves to that of the template array if one is provided and otherwise numpy unless overridden. Numpy is the standard CPU backend that underpins most of NeuroPype's operations. The others require one or more GPUs to be present on the system, except for torch-cpu. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • precision
    Numeric precision to use. Keep resolves to the precision of the template array if one is provided, and otherwise to the current default (usually 64-bit). Can be reduced to save memory (e.g. if running on GPU).

    • verbose name: Precision
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomIntegers

Draw an array of random integers from a uniform distribution with a given low and high value (the high value being exclusive), optionally matching a template array in shape and optionally data type.

If deterministic results are sought, pass in a seed; see also CreateRandomSeed for documentation on how seeds are best managed. The node supports alternative compute backends, which can be used to speed up processing.

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • array
    Output array.

    • verbose name: Array
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • like
    Optional template array.

    • verbose name: Like
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • seed
    Random seed for deterministic results.

    • verbose name: Seed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • shape
    Shape of the array. Can be omitted if a template array is provided.

    • verbose name: Shape
    • default value: []
    • port type: ListPort
    • value type: list (can be None)
  • low
    Lower bound (inclusive).

    • verbose name: Low
    • default value: 0
    • port type: FloatPort
    • value type: float (can be None)
  • high
    Upper bound (exclusive).

    • verbose name: High
    • default value: 10
    • port type: FloatPort
    • value type: float (can be None)
  • backend
    Optional compute backend to use. Keep is the current default, which resolves to that of the template array if one is provided and otherwise numpy unless overridden. Numpy is the standard CPU backend that underpins most of NeuroPype's operations. The others require one or more GPUs to be present on the system, except for torch-cpu. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • precision
    Numeric precision to use. Keep resolves to the precision of the template array if one is provided, and otherwise to the current default (usually 64-bit). Can be reduced to save memory (e.g. if running on GPU).

    • verbose name: Precision
    • default value: int32
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomNormal

Draw an array of random numbers from a normal distribution with a given mean and standard deviation, optionally matching a template array in shape and optionally data type.

If deterministic results are sought, pass in a seed; see also CreateRandomSeed for documentation on how seeds are best managed. The node supports alternative compute backends, which can be used to speed up processing.

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • array
    Output array.

    • verbose name: Array
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • like
    Optional template array.

    • verbose name: Like
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • seed
    Random seed for deterministic results.

    • verbose name: Seed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • shape
    Shape of the array. Can be omitted if a template array is provided.

    • verbose name: Shape
    • default value: []
    • port type: ListPort
    • value type: list (can be None)
  • mean
    Mean of the distribution.

    • verbose name: Mean
    • default value: 0
    • port type: FloatPort
    • value type: float (can be None)
  • std
    Standard deviation of the distribution.

    • verbose name: Std
    • default value: 1
    • port type: FloatPort
    • value type: float (can be None)
  • backend
    Optional compute backend to use. Keep is the current default, which resolves to that of the template array if one is provided and otherwise numpy unless overridden. Numpy is the standard CPU backend that underpins most of NeuroPype's operations. The others require one or more GPUs to be present on the system, except for torch-cpu. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • precision
    Numeric precision to use. Keep resolves to the precision of the template array if one is provided, and otherwise to the current default (usually 64-bit). Can be reduced to save memory (e.g. if running on GPU).

    • verbose name: Precision
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomNumbers

Draw an array of random numbers from a passed-in distribution, optionally matching a template array in shape and optionally data type.

A random seed must be passed in, see also CreateRandomSeed for documentation on how seeds are best managed. The node supports alternative compute backends, which can be used to force the result onto a specific backend (while the actual sampling is provided by the distribution's backend, which may or may not be the same).

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • dist
    Distribution to use.

    • verbose name: Dist
    • default value: None
    • port type: DataPort
    • value type: Distribution (can be None)
    • data direction: IN
  • like
    Optional template array.

    • verbose name: Like
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • seed
    Random seed for deterministic results.

    • verbose name: Seed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • data
    Output data.

    • verbose name: Data
    • default value: None
    • port type: DataPort
    • value type: AnyNumeric (can be None)
    • data direction: OUT
  • shape
    Shape of the array. Can be set to None if a template array is provided via the like input.

    • verbose name: Shape
    • default value: []
    • port type: ListPort
    • value type: list (can be None)
  • backend
    Optional compute backend to use. Keep is the current default, which resolves to that of the template array if one is provided as the like= argument, otherwise the compute backend of the distribution. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • precision
    Numeric precision to use. Keep resolves to the precision of the template array if one is provided, and otherwise the precision that the distribution is configured with.

    • verbose name: Precision
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomPermute

Return an array that has the items in the given array permuted along the first axis.

If deterministic results are sought, pass in a seed; see also CreateRandomSeed for documentation on how seeds are best managed. The node supports alternative compute backends, which can be used to speed up processing.

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • array
    Array to permute.

    • verbose name: Array
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: INOUT
  • seed
    Random seed for deterministic results.

    • verbose name: Seed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • backend
    Optional compute backend to use. Keep is the current default, which resolves to that of the provided array and otherwise numpy unless overridden. Numpy is the standard CPU backend that underpins most of NeuroPype's operations. The others require one or more GPUs to be present on the system, except for torch-cpu. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomPoisson

Draw an array of random numbers from a Poisson distribution with a given mean and standard deviation, optionally matching a template array in shape and optionally data type.

If deterministic results are sought, pass in a seed; see also CreateRandomSeed for documentation on how seeds are best managed. The node supports alternative compute backends, which can be used to speed up processing.

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • array
    Output array.

    • verbose name: Array
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • like
    Optional template array.

    • verbose name: Like
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • seed
    Random seed for deterministic results.

    • verbose name: Seed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • shape
    Shape of the array. Can be omitted if a template array is provided.

    • verbose name: Shape
    • default value: []
    • port type: ListPort
    • value type: list (can be None)
  • lam
    Mean of the distribution.

    • verbose name: Lam
    • default value: 1
    • port type: FloatPort
    • value type: float (can be None)
  • backend
    Optional compute backend to use. Keep is the current default, which resolves to that of the template array if one is provided and otherwise numpy unless overridden. Numpy is the standard CPU backend that underpins most of NeuroPype's operations. The others require one or more GPUs to be present on the system, except for torch-cpu. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • precision
    Numeric precision to use. Keep resolves to the precision of the template array if one is provided, and otherwise to the current default (usually 64-bit). Can be reduced to save memory (e.g. if running on GPU).

    • verbose name: Precision
    • default value: int32
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomSeedIterator

Iterate over an infinite series of random seeds that are derived from an initial seed.

You can use this in combination with e.g., a ZipIterator to iterate over both some data (or a finite counter) along with a sequence of random seeds.

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • curseed
    Current seed.

    • verbose name: Curseed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • initial_seed
    Seed for generated random number sequence. This can be either a splittable seed as generated by Create Random Seed or a plain integer seed.

    • verbose name: Initial Seed
    • default value: None
    • port type: Port
    • value type: AnyNumeric (can be None)
  • backend
    Optional compute backend for which to generate the seed. Keep is the current default, which is typically numpy, but which can be overridden in contexts that require it. Some backends (notably jax and tensorflow) require that the seed be generated using the same backend as the downstream random operation. For this reason, it is a good idea to use the same backend for both the seed management and the random operation to future-proof one's pipeline.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomTruncatedNormal

Draw an array of random numbers from a truncated normal distribution with a given mean and standard deviation, optionally matching a template array in shape and optionally data type.

If deterministic results are sought, pass in a seed; see also CreateRandomSeed for documentation on how seeds are best managed. The node supports alternative compute backends, which can be used to speed up processing,

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • array
    Output array.

    • verbose name: Array
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • like
    Optional template array.

    • verbose name: Like
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • seed
    Random seed for deterministic results.

    • verbose name: Seed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • shape
    Shape of the array. Can be omitted if a template array is provided.

    • verbose name: Shape
    • default value: []
    • port type: ListPort
    • value type: list (can be None)
  • mean
    Mean of the distribution.

    • verbose name: Mean
    • default value: 0
    • port type: FloatPort
    • value type: float (can be None)
  • std
    Standard deviation of the distribution.

    • verbose name: Std
    • default value: 1
    • port type: FloatPort
    • value type: float (can be None)
  • lower
    Lower bound in standard deviations.

    • verbose name: Lower
    • default value: -2
    • port type: FloatPort
    • value type: float (can be None)
  • upper
    Upper bound in standard deviations.

    • verbose name: Upper
    • default value: 2
    • port type: FloatPort
    • value type: float (can be None)
  • backend
    Optional compute backend to use. Keep is the current default, which resolves to that of the template array if one is provided and otherwise numpy unless overridden. Numpy is the standard CPU backend that underpins most of NeuroPype's operations. The others require one or more GPUs to be present on the system, except for torch-cpu. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • precision
    Numeric precision to use. Keep resolves to the precision of the template array if one is provided, and otherwise to the current default (usually 64-bit). Can be reduced to save memory (e.g. if running on GPU).

    • verbose name: Precision
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

RandomUniform

Draw an array of random numbers from a uniform distribution with a given minimum and maximum value, optionally matching a template array in shape and optionally data type.

If deterministic results are sought, pass in a seed; see also CreateRandomSeed for documentation on how seeds are best managed. The node supports alternative compute backends, which can be used to speed up processing.

Version 0.8.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • array
    Output array.

    • verbose name: Array
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • like
    Optional template array.

    • verbose name: Like
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • seed
    Random seed for deterministic results.

    • verbose name: Seed
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: IN
  • shape
    Shape of the array. Can be omitted if a template array is provided.

    • verbose name: Shape
    • default value: []
    • port type: ListPort
    • value type: list (can be None)
  • min
    Minimum of the distribution.

    • verbose name: Min
    • default value: 0
    • port type: FloatPort
    • value type: float (can be None)
  • max
    Maximum of the distribution.

    • verbose name: Max
    • default value: 1
    • port type: FloatPort
    • value type: float (can be None)
  • backend
    Optional compute backend to use. Keep is the current default, which resolves to that of the template array if one is provided and otherwise numpy unless overridden. Numpy is the standard CPU backend that underpins most of NeuroPype's operations. The others require one or more GPUs to be present on the system, except for torch-cpu. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • precision
    Numeric precision to use. Keep resolves to the precision of the template array if one is provided, and otherwise to the current default (usually 64-bit). Can be reduced to save memory (e.g. if running on GPU).

    • verbose name: Precision
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

SplitRandomSeed

Manually split a random seed into an array of multiple derived seeds.

The resulting array is of size (num,N) where N is implementation specific and depends on the type of seed. One way this can be used is to split off a key for each successive random operation one wants to perform, where one generates two keys from the initial seed -- one as the next seed (for future splitting) and one as the key for the current operation. The other way is to pre-generate a number of keys for use in multiple operations. The schemes can also be mixed, where one splits as many keys as needed to pass into various functions, and each function further splits keys to drive its random operations. The initial seed must have been generated using the Create Random Seed node. This node outputs the split key as an array of size (num,N) under the output key. However, for convenience, it also provides outputs named main_key and subkey1, subkey2, etc. which correspond to the zero'th and first through num'th elements of the key array, each of which represents a single key. Note there is technically no distinction between a "main" key and "sub"keys, but the naming suggests the use of the main key for subsequent splitting within the same function, and the subkey(s) for passing down into some random operation(s).

Version 0.5.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • key
    Splittable random seed.

    • verbose name: Key
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: INOUT
  • main_key
    Updated main key.

    • verbose name: Main Key
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • subkey1
    Subkey 1.

    • verbose name: Subkey1
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • subkey2
    Subkey 2.

    • verbose name: Subkey2
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • subkey3
    Subkey 3.

    • verbose name: Subkey3
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • subkey4
    Subkey 4.

    • verbose name: Subkey4
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • subkey5
    Subkey 5.

    • verbose name: Subkey5
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • subkey6
    Subkey 6.

    • verbose name: Subkey6
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • subkey7
    Subkey 7.

    • verbose name: Subkey7
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • subkey8
    Subkey 8.

    • verbose name: Subkey8
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • subkey9
    Subkey 9.

    • verbose name: Subkey9
    • default value: None
    • port type: DataPort
    • value type: AnyArray (can be None)
    • data direction: OUT
  • num
    Number of random seeds to generate.

    • verbose name: Num
    • default value: 2
    • port type: IntPort
    • value type: int (can be None)
  • algorithm
    Random number generation algorithm for which to generate a seed. The default depends on the chosen backend, and not all backends support all algorithms. For this reason it is recommended to use the default.

    • verbose name: Algorithm
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • backend
    Optional compute backend for which to generate the seed. Keep is the current default, which is typically numpy, but which can be overridden in contexts that require it. Some backends (notably jax and tensorflow) require that the seed be generated using the same backend as the downstream random operation. For this reason, it is a good idea to use the same backend for both the seed management and the random operation to future-proof one's pipeline.

    • verbose name: Backend
    • default value: keep
    • port type: EnumPort
    • value type: str (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)

WithRandomSeed

Run the given computational graph with a random seed sequence initialized to the given seed.

The graph can draw one or more successive seed(s) from the sequence using the Draw Random Seed node. This node is nestable, and can provide, for example a different, independent sequence of seeds to a sub-computation (meaning a computation that is wired into that node's graph port), while the node itself is part of a larger computation that is also using a random seed sequence. Note: this node will also establish a context for use with hk.next_rng_key() if this node is being used inside a context NetTransform context.

Version 0.9.0

Ports/Properties

  • metadata
    User-definable meta-data associated with the node. Usually reserved for technical purposes.

    • verbose name: Metadata
    • default value: {}
    • port type: DictPort
    • value type: dict (can be None)
  • graph
    Computation to run.

    • verbose name: Graph
    • default value: None
    • port type: GraphPort
    • value type: Graph
  • graph__signature
    Optionally the slotname of a Placeholder node that shall mark the starting point of the graph that runs under the with context. As with all "With" context manager nodes in NeuroPype, the graph that runs under the context managed by this node is preceding the context manager node in the graph, rather than following it. This is accomplished by wiring the final node of the graph that shall execute under the governance of the context manager into the "graph" input port of the subsequent "With" node. In graphical UIs, this edge will be drawn in dotted style to indicate that this is not normal forward data flow where first the preceding node executes and then the subsequent node receives its output, but that instead the subsequent node (the context manager) receives a portion of the preceding graph, which it then runs in such a way that the context applies. You can use a "tilde" binding, spelled as (~), which affects the same nodes that a then or else branch in an IfElse node would control, which is normally what one would expect. However, note that this can have sometimes the unexpected consequence that simply wiring a value into your graph may "infect" an upstream portion of the graph with unintentionally running under the context, too. As an alternative, you can instead rely on a named Placeholder node to mark the beginning of the managed graph. The typical way to do this is to list a single placeholder name, e.g., (with), and then to create a Placeholder in your graph whose slotname is set to "with". Then, only the nodes that are downstream of (i.e., formally depending on) that placeholder will run under the context defined by the "With" node. In this case you need to make everything that shall be part of the context dependent on the placeholder, which can be accomplished by wiring the update output port of the Placeholder into the update input port of any nodes that shall run under the context (this dependency propagates down the graph, so you don't need to wire it to every node, just to the first node(s) that you want to be part of the context). The result is that any use of the Draw Random Seed node in the managed graph will draw a seed from the sequence initialized by this node. This node can also be nested (see documentation of the equivalent setting in WithCoreLimit for more details).

    • verbose name: Graph [Tag]
    • default value: (~)
    • port type: Port
    • value type: object (can be None)
  • result
    Result of the computation.

    • verbose name: Result
    • default value: None
    • port type: DataPort
    • value type: object (can be None)
    • data direction: OUT
  • initial_seed
    Seed for generated random number sequence. This can be either a splittable seed as generated by Create Random Seed or a plain integer seed.

    • verbose name: Initial Seed
    • default value: None
    • port type: Port
    • value type: AnyNumeric (can be None)
  • supply_haiku
    Supply the haiku library with its own sequence of random seeds derived from the given initial seed. This will only work if used within a NetTransform context, and is equivalent to a call to hk.with_rng(initial_seed).

    • verbose name: Also Generate Haiku Sequence
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)
  • supply_bayes
    Supply nodes in the Bayesian package node with automatic random seeds derived from the given initial seed. This is mainly useful if you aim to run stochastic models plain without using any of the inference nodes, which provide their own seed.

    • verbose name: Expose To Bayes Nodes
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)
  • is_global
    If True, the context implicitly applies to the entire graph (except for those parts that are configuring the context itself). In this case the node must not have anything wired into its graph input and must not have any successors.

    • verbose name: Is Global
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)
  • supply_randomsample

    • verbose name: Supply Randomsample
    • default value: None
    • port type: AliasPort
    • value type: bool (can be None)
  • set_breakpoint
    Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

    • verbose name: Set Breakpoint (Debug Only)
    • default value: False
    • port type: BoolPort
    • value type: bool (can be None)