Skip to content

← bayesian package

BayesNet

Instantiate a deep network inside a statistical model.

This node allows one to specify a subgraph inside a statistical model that is made up of neural network layers wired into the net input of the node (see documentation for the port for more details). The weights of these layers can then be associated with priors, which then defines a fully Bayesian neural network. Note that another commonly used combination of deep networks and bayesian inference is to use the network as part of a variational approximation to some other (perhaps conventionally defined) model, in which case the weights are treated as variational parameters to optimize, but this mode is not currently exposed since custom approximations cannot yet be wired into the variational inference node. During network bring-up it can be useful to start with a Laplace approximation and a fairly loose prior (e.g., Normal(0,10)) for the weights; the BayesNet node is typically situated in a With Stacked Variables context with subsampling enabled and set to a typical batch size (e.g., 16 or 32), and the inputs wired into the BayesNet data input are subsampled accordingly using the At Subscripts node. Note also that there is direct equivalent to the number of epochs to run; instead, the number of iterations is set in the variational inference node, which multiplies with the batch size to determine the total number of samples to draw (which, when divided by the training set size, gives the equivalent number of epochs). There is also currently no direct support for early stopping, but a (computationally expensive) substitute can be to make the iterations a hyper-parameter optimized via the Parameter Optimization node and set to a p-holdout train/test split. Version 0.8.0

Ports/Properties

net

Neural network graph. This is a graph of nodes starting with at least an input placeholder whose slotname must be set to match the name here (e.g., inputs), and which is followed by some combination of neural net nodes (nodes in the deep learning package) and nodes for math operations and/or data restructuring (no stateful nodes). Random Draw or With Stacked Variables (Plate) nodes cannot be used inside the net graph (if you need these inside the net, you need to declare more than one net, e.g., before and one after the Random Draw draw). The output of the network may be a packet or a plain array.

verbose name
Net
default value
None
port type
GraphPort
value type
Graph

net__signature

If you need to accept additional arguments in the network (e.g ., is_training), you can list those in the signature.

verbose name
Net [Signature]
default value
(inputs)
port type
Port
value type
object (can be None)

seed

Optional random seed. Only used if the net is applied in-place. If no seed is provided, one will be obtained from the context of the inference engine.

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

apply

Neural network graph that can be called with arguments after instantiation.

verbose name
Apply
default value
None
port type
GraphPort
value type
Graph

result

Result of applying the network to the arguments. Only for in-place use of the network (i.e., at the site of declaration.

verbose name
Result
default value
None
port type
DataPort
value type
AnyNumeric (can be None)
data direction
OUT

netname

Name under which the parameters (and optionally state) of this network appear in the statistical model.

verbose name
Name
default value
mynet
port type
StringPort
value type
str (can be None)

priors

Optional dictionary of prior distributions associated with specific named weight arrays of the network. This can either be specified textually as in the example (using the same format and distributions as available in the Random Sample node), or wired in as a dictionary with distribution nodes as the values. The dictionary keys can be wildcard strings, e.g., 'mylayer_*.b' to match specific sets of weights (be sure to review their naming in the learned variables to ensure that the wildcard matches what you expect). The weights being matched are typicalled named as in mylayer_eeg.w or mylayer_eeg.b, where mylayer is the layername, eeg is the name of the stream that the weights apply to, and w is one of the weight names of the layer for this stream. if the weight has more dimensions than the specified prior distribution, the leading dimensions are considered batch dimensions and a batch of samples will be drawn to match the dimensionality of the weight array. You can also use matrix- or tensor-variate prior distributions to draw full weight matrices. Note that you can also wire a prior distribution into the respective w_prior and b_prior ports of individual network layers, which take precedence over the dictionary-supplied priors, and which can be more explicit or less error-prone. Also note also that the prior is different from the weight initialization -- the initialization of the network weights (which needs to be delicately scaled) is unaffected by the presence of the priors. If no priors are specified for a given layer, then the parameters of that layer will be optimized as variational parameters (via variational inference), and if one is specified, then a posterior over the weights of that layer will be inferred.

verbose name
Default Weight Priors
default value
{'*': 'Normal(0,1)'}
port type
DictPort
value type
dict (can be None)

help

Help text for the network. This can be used to annotate the purpose/meaning of the network in the context of a statistical model.

verbose name
Help
default value
port type
StringPort
value type
str (can be None)

verbose_name

Optional verbose name for the network. Can be used for augmented human-readable output.

verbose name
Verbose Name
default value
None
port type
StringPort
value type
str (can be None)

usage

Intended usage of the network. If the network is used as a model (the default), then each weight tensor in the network must have an associated prior distribution. If instead the network is used as part of a custom variational approximation, then this is not necessary, but still allowed, as long as those distributions are parameterized by variational parameters. For this reason, the priors dictionary, if used, should not use textually defined priors but wired-in distributions. Note that as of NeuroPype 2025, the variational mode is not fully supported.

verbose name
Used In
default value
model
port type
EnumPort
value type
str (can be None)

arg1

Positional Argument 1.

verbose name
Arg1
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

arg2

Positional Argument 2.

verbose name
Arg2
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

arg3

Positional Argument 3.

verbose name
Arg3
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

arg4

Positional Argument 4.

verbose name
Arg4
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

arg5

Positional Argument 5.

verbose name
Arg5
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

arg6

Positional Argument 6.

verbose name
Arg6
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

arg7

Positional Argument 7.

verbose name
Arg7
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

arg8

Positional Argument 8.

verbose name
Arg8
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

arg9

Positional Argument 9.

verbose name
Arg9
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

argN

Additional positional arguments.. .

verbose name
Argn
default value
None
port type
DataPort
value type
list (can be None)
data direction
IN

kw_args

Keyword arguments.

verbose name
Kw Args
default value
None
port type
DataPort
value type
dict (can be None)
data direction
IN

arg0

Positional Argument 0.

verbose name
Arg0
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

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)

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)