Neural Network Baseclass

This is the parent class to all neural networks. The NeuralNetwork is an abstract baseclass and a subclass of torch.nn.Module.

The documentation in the NeuralNetwork class may be inherited from PyTorch docstrings.

Methods

class NeuralNetwork(**kwargs)[source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

abstract forward(**kwargs)[source]

Define the computation at every model call. Inherited from torch.nn.Module. See Pytorch documentation for details.

summary(**kwargs)[source]

Call torchinfo.summary() on self. See torchinfo documentation for details.

Parameters:

kwargs – Keyword arguments passed to torchinfo.summary.

Returns:

Model statistics

count_parameters()[source]

Get the total number of parameters that require a gradient computation in the model

sample(mode=True)[source]

Set sampling mode.

Note

This method and self.sampling only affects UQpy’s Bayesian layers

Parameters:

mode (bool) – If True sample from distributions, otherwise use distribution means.

Returns:

self

drop(mode=True)[source]

Set dropping mode.

Note

This method and self.dropping only affects UQpy’s dropout layers

Parameters:

mode (bool) – If True perform dropout, otherwise act as the identity function.

is_deterministic()[source]

Check if neural network is behaving deterministically or probabilistically.

Note

This flag may be incorrect if the model has sources of randomness that do not depend on the attributes training, dropping, or sampling.

Return type:

bool

Returns:

True if sampling, dropping, and training are all False. Otherwise, returns False.

set_deterministic(mode=True)[source]

Set training, dropping, and sampling to the opposite of mode.

This is equivalent to

>>> model.train(not mode)
>>> model.drop(not mode)
>>> model.sample(not mode)

If the model has sources of randomness that do not depend on the training, dropping, or sampling attributes, they will not be affected.

Attributes

NeuralNetwork.dropping: bool

Boolean represents whether this module is in dropping mode or not.

NeuralNetwork.sampling: bool

Boolean represents whether this module is in sampling mode or not.