scimba_torch.approximation_space.radial_space

Defines the radial approximation space and its components.

Classes

NNxSpace(nb_unknowns, nb_parameters, ...)

A nonlinear approximation space using a neural network model.

NNxSpaceSplit(nb_unknowns, nb_parameters, ...)

A nonlinear approximation space using a network split into separate components.

SeparatedNNxSpace(nb_unknowns, ...)

A nonlinear approximation space using a neural network model.

class NNxSpace(nb_unknowns, nb_parameters, net_type, spatial_domain, integrator, **kwargs)[source]

Bases: AbstractApproxSpace, Module

A 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.

  • nb_parameters (int) – Number of parameters in the input.

  • net_type (Module) – The neural network class used to approximate the solution.

  • spatial_domain (VolumetricDomain) – The spatial domain of the problem.

  • integrator (DomainSampler) – Sampler used for integration over the spatial and parameter domains.

  • **kwargs – Additional arguments passed to the neural network model.

in_size: int

Size of the input to the neural network (spatial dimension + parameters).

out_size: int

Size of the output of the neural network (number of unknowns).

spatial_domain: VolumetricDomain

The spatial domain of the problem.

integrator: DomainSampler

Integrator combining the spatial and parameter domains.

network: nn.Module

Neural network used for the approximation.

ndof: int

Total number of degrees of freedom in the network.

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 (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.

Return the result as a multi-label tensor.

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 computation.

Return type:

MultiLabelTensor

Returns:

MultiLabelTensor with the evaluation results.

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 parameters to set (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 parameters to retrieve.

  • flag_format (str) – Format of the returned parameters.

Return type:

Tensor

Returns:

The network parameters as specified by the format.

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:

The Jacobian matrix after post-processing.

class NNxSpaceSplit(nb_unknowns, nb_parameters, net_type, spatial_domain, integrator, **kwargs)[source]

Bases: AbstractApproxSpace, Module

A nonlinear approximation space using a network split into separate components.

Separate into spatial and parameter domains.

This class is designed to handle problems where the input space can be split into spatial and parameter components, allowing for more efficient processing via separate neural networks for each component.

Parameters:
  • nb_unknowns (int) – The number of unknowns in the approximation problem.

  • nb_parameters (int) – The number of parameters in the problem.

  • net_type (Module) – The neural network model used to approximate the solution.

  • spatial_domain (VolumetricDomain) – The domain representing the spatial component of the problem.

  • integrator (TensorizedSampler) – The sampler used for integration over the spatial domain.

  • **kwargs – Additional keyword arguments for configuring the neural network model.

in_size: int

The size of the inputs to the neural network.

out_size: int

The size of the outputs from the neural network.

spatial_domain: VolumetricDomain

The spatial domain of the problem.

integrator: TensorizedSampler

The integrator for the spatial and parameter domains.

pre_processing_x: Callable

Pre-processing function for spatial inputs.

pre_processing_mu: Callable

Pre-processing function for parameter inputs.

post_processing: Callable

Post-processing function for neural network outputs.

split_latent_space: int

The dimensionality of the latent space for split networks.

network_x: torch.nn.Module

Neural network for processing spatial inputs.

network_mu: torch.nn.Module

Neural network for processing parameter inputs.

network_cat: torch.nn.Module

Neural network for combining latent spaces from spatial and parameter inputs.

ndof: int

Number of degrees of freedom (DoF) for the entire network.

forward(x, mu, with_last_layer=True)[source]

Evaluate the parametric model for given inputs and parameters.

Parameters:
  • x (Tensor) – Input tensor from the spatial domain.

  • mu (Tensor) – Input tensor from the parameter domain.

  • with_last_layer (bool) – Whether to include the last layer in computation (default: True).

Returns:

Output tensor from the neural network.

evaluate(x, mu, with_last_layer=True)[source]

Evaluate the parametric model for given inputs and parameters.

Return the result as a multi-label tensor.

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 computation (default: True).

Return type:

MultiLabelTensor

Returns:

The result of the neural network evaluation.

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 parameters to set (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) – (Default value = “all”)

  • flag_format (str) – (Default value = “list”)

Return type:

Tensor

Returns:

The network parameters in the specified format.

jacobian(x, mu)[source]

Compute the Jacobian matrix of the model with respect to its inputs.

Parameters:
  • x (LabelTensor) – The input tensor for the spatial domain.

  • mu (LabelTensor) – The input tensor for the parameter domain.

Returns:

The Jacobian matrix of the model.

class SeparatedNNxSpace(nb_unknowns, nb_parameters, rank, net_type, spatial_domain, integrator, **kwargs)[source]

Bases: AbstractApproxSpace, Module

A 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.

  • nb_parameters (int) – Number of parameters in the input.

  • rank (int) – The rank for the separated representation.

  • net_type (Module) – The neural network class used to approximate the solution.

  • spatial_domain (VolumetricDomain) – The spatial domain of the problem.

  • integrator (DomainSampler) – Sampler used for integration over the spatial and parameter domains.

  • **kwargs – Additional arguments passed to the neural network model.

in_size: int

Size of the input to the neural network (spatial dimension + parameters).

out_size: int

Size of the output of the neural network (number of unknowns).

spatial_domain: VolumetricDomain

The spatial domain of the problem.

integrator: DomainSampler

The integrator combining the spatial and parameter domains.

network: nn.ModuleList

The neural network used for the approximation.

ndof: int

The total number of degrees of freedom in the network.

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) – (Default value = True)

Return type:

MultiLabelTensor

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 unknown 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).