scimba_torch.approximation_space.spectral_space¶
Defines the spectral approximation space and its components.
Classes
|
A nonlinear approximation space using a neural network model. |
|
A nonlinear approximation space using a neural network model. |
- class SpectralxSpace(nb_unknowns, basis_type, nb_mods_by_direction, bounds, integrator, **kwargs)[source]¶
Bases:
AbstractApproxSpace,ScimbaModuleA nonlinear approximation space using a neural network model.
This class represents a parametric approximation space, where the solution is modeled by a neural network. It integrates functionality for evaluating the network, setting/retrieving degrees of freedom, and computing the Jacobian.
- Parameters:
nb_unknowns (
int) – Number of unknowns in the approximation problem.basis_type (
str) – Type of basis functions used in the approximation (e.g., “sine”, “cosine”).nb_mods_by_direction (
int) – Number of modes in each spatial direction.bounds (
list) – list of tuples specifying the bounds for each spatial dimension.integrator (
DomainSampler) – Integrator for the spatial and parameter domains.**kwargs – Additional arguments passed to the neural network model.
- integrator: DomainSampler¶
The integrator combining the spatial and parameter domains.
- forward(features, with_last_layer=True)[source]¶
Evaluate the parametric model for given input features.
- Parameters:
features (
Tensor) – Input tensor with concatenated spatial and parameter data.with_last_layer (
bool) – whether to include the last layer in the evaluation (Default value = True)
- Return type:
Tensor- Returns:
Output tensor from the neural network.
- evaluate(x, mu, with_last_layer=True)[source]¶
Evaluate the parametric model for given inputs and parameters.
- Parameters:
x (
LabelTensor) – Input tensor from the spatial domain.mu (
LabelTensor) – Input tensor from the parameter domain.with_last_layer (
bool) – whether to include the last layer in the evaluation (Default value = True)
- Return type:
- Returns:
Output tensor from the neural network, wrapped with multi-label metadata.
- set_dof(theta, flag_scope='all')[source]¶
Sets the degrees of freedom (DoF) for the neural network.
- Parameters:
theta (
Tensor) – A vector containing the network parameters.flag_scope (
str) – scope of the DoF (Default value = “all”)
- Return type:
None
- get_dof(flag_scope='all', flag_format='list')[source]¶
Retrieves the degrees of freedom (DoF) of the neural network.
- Parameters:
flag_scope (
str) – scope of the DoF (Default value = “all”)flag_format (
str) – format of the DoF (Default value = “list”)
- Return type:
list[Parameter] |Tensor- Returns:
Tensor containing the DoF of the network.
- jacobian(x, mu)[source]¶
Compute the Jacobian of the network with respect to its parameters.
- Parameters:
x (
LabelTensor) – Input tensor from the spatial domain.mu (
LabelTensor) – Input tensor from the parameter domain.
- Return type:
Tensor- Returns:
Jacobian matrix of shape (num_samples, out_size, num_params).
- class SeparatedSpectralxSpace(nb_unknowns, basis_type, nb_mods_by_direction, bounds, integrator, rank, **kwargs)[source]¶
Bases:
AbstractApproxSpace,ModuleA nonlinear approximation space using a neural network model.
This class represents a parametric approximation space, where the solution is modeled by a neural network. It integrates functionality for evaluating the network, setting/retrieving degrees of freedom, and computing the Jacobian.
- Parameters:
nb_unknowns (
int) – Number of unknowns in the approximation problem.basis_type (
str) – Type of basis functions used in the approximation (e.g., “sine”, “cosine”).nb_mods_by_direction (
int) – Number of modes in each spatial direction.bounds (
list) – list of tuples specifying the bounds for each spatial dimension.integrator (
TensorizedSampler) – Integrator for the spatial and parameter domains.rank (
int) – Rank of the tensor structure.**kwargs – Additional arguments passed to the neural network model.
- forward(features)[source]¶
Evaluate the parametric model for given input features.
- Parameters:
features (
Tensor) – Input tensor with concatenated spatial and parameter data.- Return type:
Tensor- Returns:
Output tensor from the neural network.
- evaluate(x, mu, with_last_layer=True)[source]¶
Evaluate the parametric model for given inputs and parameters.
- Parameters:
x (
LabelTensor) – Input tensor from the spatial domain.mu (
LabelTensor) – Input tensor from the parameter domain.with_last_layer (
bool) – whether to include the last layer in the evaluation (Default value = True)
- Return type:
- Returns:
Output tensor from the neural network, wrapped with multi-label metadata.
- Raises:
ValueError – If with_last_layer is False.
- set_dof(theta, flag_scope='all')[source]¶
Sets the degrees of freedom (DoF) for the neural network.
- Parameters:
theta (
Tensor) – A vector containing the network parameters.flag_scope (
str) – (Default value = “all”)
- Raises:
ValueError – If the flag_scope is not “all”.
- Return type:
None
- get_dof(flag_scope='all', flag_format='list')[source]¶
Retrieves the degrees of freedom (DoF) of the neural network.
- Parameters:
flag_scope (
str) – (Default value = “all”)flag_format (
str) – (Default value = “list”)
- Return type:
Tensor|list[Parameter]- Returns:
The network parameters in the specified format.
- Raises:
ValueError – If the flag_scope is not “all” or if the flag_format is not “list” or “tensor”.
- jacobian(x, mu)[source]¶
Compute the Jacobian of the network with respect to its parameters.
- Parameters:
x (
LabelTensor) – Input tensor from the spatial domain.mu (
LabelTensor) – Input tensor from the parameter domain.
- Return type:
Tensor- Returns:
Jacobian matrix of shape (num_samples, out_size, num_params).