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()onself. 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.samplingonly affects UQpy’s Bayesian layers- Parameters:
mode (
bool) – IfTruesample from distributions, otherwise use distribution means.- Returns:
self
- drop(mode=True)[source]
Set dropping mode.
Note
This method and
self.droppingonly affects UQpy’s dropout layers- Parameters:
mode (
bool) – IfTrueperform 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, orsampling.- Return type:
- Returns:
Trueifsampling,dropping, andtrainingare allFalse. Otherwise, returnsFalse.
- 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, orsamplingattributes, 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.