scimba_torch.neural_nets.coordinates_based_nets.features¶
Neural networks with feature transformations such as Fourier features.
Classes
|
A network that generates learnable features such as Fourier features. |
|
Combine flipping feature transformations with a Multi-Layer Perceptron (MLP). |
|
Combines Fourier feature transformations with a Multi-Layer Perceptron (MLP). |
|
Combines Fourier feature transformations with a ResNet architecture. |
|
A template for a general network with enhanced features. |
|
Combines Fourier feature transformations with a specified neural network. |
|
Combines Fourier feature transformations with a specified neural network. |
|
A neural network that appends a periodic embedding before the first layer. |
|
A linear combination of Fourier feature transformations with MLP. |
|
Combine Fourier feature transformations with Residual Networks (ResNet). |
|
A neural network that combines periodic feature transformations with an MLP. |
|
Combine a periodic feature transformations with a ResNet architecture. |
- class EnhancedFeatureNet(in_size, **kwargs)[source]¶
Bases:
ModuleA network that generates learnable features such as Fourier features.
The weights are initialized using a normal distribution.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).**kwargs (
Any) –Additional keyword arguments:
nb_features (
int, default=1): The number of features generated by the network.type_feature (
str, default=”fourier”): The type of feature transformation to apply.mean (
float, default=0.0): The mean used for initializing the weights.std (
float, default=1.0): The standard deviation used for initializing the weights.
- class GenericFeatureNet(in_size, out_size, **kwargs)[source]¶
Bases:
ScimbaModuleA template for a general network with enhanced features.
A feature can be a periodic embedding, Fourier features, etc.
- parameters(flag_scope='all', flag_format='list')[source]¶
Get parameters of the neural net.
- Parameters:
flag_scope (
str) – Specifies which parameters to return. Options: ‘all’, ‘last_layer’, ‘except_last_layer’.flag_format (
str) – Specifies the format Options: ‘list’, ‘tensor’.
- Return type:
list[Parameter] |Tensor- Returns:
A list of parameters or a single tensor containing all parameters.
- Raises:
ValueError – If an unknown flag_scope or flag_format is provided.
- class GenericFourierNet(in_size, out_size, **kwargs)[source]¶
Bases:
GenericFeatureNetCombines Fourier feature transformations with a specified neural network.
The network first generates enhanced features (such as Fourier features), concatenates them with the original input, and then passes the result through a user-specified network architecture.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).out_size (
int) – The output dimension (number of features in the output tensor).**kwargs –
Additional keyword arguments:
nb_features (
int, default=1): Number of features generated by EnhancedFeatureNet.type_feature (
str, default=”fourier”): Type of feature transformationOther keyword arguments are passed to the EnhancedFeatureNet and to whichever network class is specified by the user.
Learnable Parameters:
features (
EnhancedFeatureNet): A network that generates enhanced features such as Fourier features.net: (
ScimbaModule): A neural network that processes the input and features.
- forward(x, with_last_layer=True)[source]¶
Compute the forward pass.
Apply the feature transformation, concatenate the features with the original input, and pass the result through the neural network to produce the output.
- Parameters:
x (
Tensor) – Input tensor.with_last_layer (
bool) – Whether to include the last layer in the forward pass. (default: True)
- Return type:
Tensor- Returns:
Output tensor after passing through the neural network.
- class FourierMLP(in_size, out_size, **kwargs)[source]¶
Bases:
GenericFourierNetCombines Fourier feature transformations with a Multi-Layer Perceptron (MLP).
The network first generates enhanced features (such as Fourier features), concatenates them with the original input, and then passes the result through a fully connected MLP.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).out_size (
int) – The output dimension (number of features in the output tensor).**kwargs –
Additional keyword arguments:
nb_features (
int, default=1): Number of features generated by EnhancedFeatureNet.type_feature (
str, default=”fourier”): Type of feature transformation applied.Other keyword arguments are passed to EnhancedFeatureNet and GenericMLP classes.
- class FourierResNet(in_size, out_size, **kwargs)[source]¶
Bases:
GenericFourierNetCombines Fourier feature transformations with a ResNet architecture.
The network first generates enhanced features (such as Fourier features), concatenates them with the original input, and then passes the result through a series of residual blocks. It is a specialization of GenericFourierNet.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).out_size (
int) – The output dimension (number of features in the output tensor).**kwargs – Additional keyword arguments.
- class GenericPeriodicNet(in_size, out_size, **kwargs)[source]¶
Bases:
GenericFeatureNetA neural network that appends a periodic embedding before the first layer.
- The network first generates periodic features, passes the input through it, and then
passes the result through the chosen architecture.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).out_size (
int) – The output dimension (number of features in the output tensor).**kwargs –
Additional keyword arguments:
domain_bounds (
required): The bounds of the domain for the periodic features.nb_features (
optional): The number of features generated by the EnhancedFeatureNet.type_feature (
optional): The type of feature transformation applied (e.g., “periodic”).Other arguments passed to the EnhancedFeatureNet class and whichever network class is specified by the user.
- Raises:
KeyError – If domain_bounds is not provided in kwargs.
ValueError – If domain_bounds is not a torch.Tensor or has incorrect shape.
Learnable Parameters:
features (
EnhancedFeatureNet): A network that generates enhanced features such as Fourier features.net: (
ScimbaModule): A neural network that processes the input and features.
- compute_periods(domain_bounds)[source]¶
Compute the periods for the periodic embedding from the domain bounds.
- Parameters:
domain_bounds (
Tensor) – The bounds of the domain for periodic features.- Returns:
The computed periods.
- Return type:
torch.Tensor
- forward(x, with_last_layer=True)[source]¶
Compute the forward pass.
Apply the periodic transformation and pass the result through the MLP to produce the output.
- Parameters:
x (
Tensor) – Input tensor.with_last_layer (
bool) – Whether to include the last layer in the forward pass. (default: True)
- Return type:
Tensor- Returns:
Output tensor after passing through the neural network.
- class PeriodicMLP(in_size, out_size, **kwargs)[source]¶
Bases:
GenericPeriodicNetA neural network that combines periodic feature transformations with an MLP.
The network first generates periodic features, passes the input through it, and then passes the result through a fully connected MLP.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).out_size (
int) – The output dimension (number of features in the output tensor).**kwargs –
Other keyword arguments including:
domain_bounds (
required): The bounds of the domain for the periodic features.nb_features (
optional): Number of features generated by EnhancedFeatureNet.type_feature (
optional): Type of feature transformation applied (e.g., “periodic”).Other arguments passed to EnhancedFeatureNet and GenericMLP classes.
- class PeriodicResNet(in_size, out_size, **kwargs)[source]¶
Bases:
GenericPeriodicNetCombine a periodic feature transformations with a ResNet architecture.
The network first generates periodic features, passes the input through it, and then passes the result through a ResNet.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).out_size (
int) – The output dimension (number of features in the output tensor).**kwargs –
Other keyword arguments including:
domain_bounds (
required): The bounds of the domain for the periodic features.nb_features (
optional): The number of features generated by the EnhancedFeatureNet.type_feature (
optional): The type of feature transformation applied (e.g., “periodic”).Other arguments passed to the EnhancedFeatureNet and GenericResNet classes
- class FlippedMLP(in_size, out_size, **kwargs)[source]¶
Bases:
GenericFeatureNetCombine flipping feature transformations with a Multi-Layer Perceptron (MLP).
The network first generates flipped features, passes the input through it, and then passes the result through a fully connected MLP.
This class is only available for 2D inputs on the unit square.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).out_size (
int) – The output dimension (number of features in the output tensor).**kwargs –
Other keyword arguments including:
nb_features (
optional): Number of features generated by EnhancedFeatureNet.type_feature (
optional): Type of feature transformation applied (e.g., “flipped”).Other arguments passed to EnhancedFeatureNet and GenericMLP classes.
- forward(x, with_last_layer=True)[source]¶
Compute the forward pass.
Apply the periodic transformation and pass the result through the MLP to produce the output.
- Parameters:
x (
Tensor) – Input tensor.with_last_layer (
bool) – Whether to include the last layer in the forward pass (default: True)
- Return type:
Tensor- Returns:
Output tensor after passing through the MLP.
- class GenericMultiScaleFourierNet(in_size, out_size, **kwargs)[source]¶
Bases:
ScimbaModuleCombines Fourier feature transformations with a specified neural network.
The network first generates enhanced features (such as Fourier features), concatenates them with the original input, and then passes the result through a user-specified network architecture. The result is obtained as a linear combination of the Fourier networks.
- Parameters:
in_size (
int) – intout_size (
int) – int**kwargs –
Additional keyword arguments:
means (
list[float], default=[0.0]): Initialize the weights of the EnhancedFeatureNet layersstds (
list[float], default=[1.0]): Initialize the weights of the EnhancedFeatureNet layersnb_features (
int, default=1): The number of features generated by the EnhancedFeatureNettype_feature (
str, default=”fourier”): The type of feature transformation appliedOther keyword arguments are passed to the EnhancedFeatureNet and to whichever network class is specified by the user.
Learnable Parameters:
features (
EnhancedFeatureNet): A network that generates enhanced features such as Fourier features.net: (
ScimbaModule): A neural network that processes the input and features.
- re_init_features(means, stds)[source]¶
Reinitialize the weights of the EnhancedFeatureNet layer.
Use a normal distribution with the specified mean and standard deviation.
- Parameters:
means (
list[float]) – List of mean values for the normal distribution.stds (
list[float]) – List of standard deviations for the normal distribution.
- forward(x, with_last_layer=True)[source]¶
Compute the forward pass.
Apply the feature transformation, concatenate the features with the original input and pass the result through the neural network to produce the output.
- Parameters:
x (
Tensor) – Input tensor.with_last_layer (
bool) – Whether to include the last layer in the forward pass. (default: True)
- Return type:
Tensor- Returns:
Output tensor after passing through the neural network.
- class MultiScaleFourierMLP(in_size, out_size, **kwargs)[source]¶
Bases:
GenericMultiScaleFourierNetA linear combination of Fourier feature transformations with MLP.
The networks first generate enhanced features (such as Fourier features), concatenate them with the original input, and then passes the result through a fully connected MLP.
The result is obtained as a linear combination of the Fourier networks.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).out_size (
int) – The output dimension (number of features in the output tensor).**kwargs –
Additional keyword arguments:
means (
list[float], default=[0.0]): Initialize the weights of the EnhancedFeatureNet layersstds (
list[float], default=[1.0]): Initialize the weights of the EnhancedFeatureNet layersnb_features (
int, default=1): The number of features generated by the EnhancedFeatureNettype_feature (
str, default=”fourier”): The type of feature transformation applied
- class MultiScaleFourierResNet(in_size, out_size, **kwargs)[source]¶
Bases:
GenericMultiScaleFourierNetCombine Fourier feature transformations with Residual Networks (ResNet).
The networks first generate enhanced features (such as Fourier features), concatenate them with the original input, and then passes the result through a fully connected ResNet. The result is obtained as a linear combination of the Fourier networks. It is a specialization of the generic class GenericMultiScaleFourierNet.
- Parameters:
in_size (
int) – The input dimension (number of features in the input tensor).out_size (
int) – The output dimension (number of features in the output tensor).**kwargs – Additional keyword arguments.