pymor.models.neural_network

Module Contents

class pymor.models.neural_network.BaseNeuralNetworkModel(dim_input=0, products=None, error_estimator=None, visualizer=None, name=None)[source]

Bases: pymor.models.interface.Model

Base class for models that use artificial neural networks.

This class implements the scaling methods for inputs and outputs/targets of neural networks.

class pymor.models.neural_network.FullyConnectedNN(layer_sizes, activation_function=torch.tanh)[source]

Bases: torch.nn.Module, pymor.core.base.BasicObject

Class for neural networks with fully connected layers.

This class implements neural networks consisting of linear and fully connected layers. Furthermore, the same activation function is used between each layer, except for the last one where no activation function is applied.

Parameters

layer_sizes

List of sizes (i.e. number of neurons) for the layers of the neural network.

activation_function

Function to use as activation function between the single layers.

Methods

forward

Performs the forward pass through the neural network.

forward(x)[source]

Performs the forward pass through the neural network.

Applies the weights in the linear layers and passes the outcomes to the activation function.

Parameters

x

Input for the neural network.

Returns

The output of the neural network for the input x.

class pymor.models.neural_network.NeuralNetworkInstationaryModel(T, nt, neural_network, parameters={}, scaling_parameters={}, output_functional=None, products=None, error_estimator=None, visualizer=None, name=None)[source]

Bases: BaseNeuralNetworkModel

Class for models of instationary problems that use artificial neural networks.

This class implements a Model that uses a neural network for solving.

Parameters

T

The final time T.

nt

The number of time steps.

neural_network

The neural network that approximates the mapping from parameter space to solution space. Should be an instance of FullyConnectedNN with input size that matches the (total) number of parameters and output size equal to the dimension of the reduced space.

parameters

Parameters of the reduced order model (the same as used in the full-order model).

scaling_parameters

Dict of tensors that determine how to scale inputs before passing them through the neural network and outputs after obtaining them from the neural network. If not provided or each entry is None, no scaling is applied. Required keys are 'min_inputs', 'max_inputs', 'min_targets', and 'max_targets'.

output_functional

Operator mapping a given solution to the model output. In many applications, this will be a Functional, i.e. an Operator mapping to scalars. This is not required, however.

products

A dict of inner product Operators defined on the discrete space the problem is posed on. For each product with key 'x' a corresponding attribute x_product, as well as a norm method x_norm is added to the model.

error_estimator

An error estimator for the problem. This can be any object with an estimate_error(U, mu, m) method. If error_estimator is not None, an estimate_error(U, mu) method is added to the model which will call error_estimator.estimate_error(U, mu, self).

visualizer

A visualizer for the problem. This can be any object with a visualize(U, m, ...) method. If visualizer is not None, a visualize(U, *args, **kwargs) method is added to the model which forwards its arguments to the visualizer’s visualize method.

name

Name of the model.

class pymor.models.neural_network.NeuralNetworkInstationaryStatefreeOutputModel(T, nt, neural_network, parameters={}, scaling_parameters={}, error_estimator=None, name=None)[source]

Bases: BaseNeuralNetworkModel

Class for models of the output of instationary problems that use ANNs.

This class implements a Model that uses a neural network for solving for the output quantity in the instationary case.

Parameters

T

The final time T.

nt

The number of time steps.

neural_network

The neural network that approximates the mapping from parameter space to output space. Should be an instance of FullyConnectedNN with input size that matches the (total) number of parameters and output size equal to the dimension of the output space.

parameters

Parameters of the reduced order model (the same as used in the full-order model).

scaling_parameters

Dict of tensors that determine how to scale inputs before passing them through the neural network and outputs after obtaining them from the neural network. If not provided or each entry is None, no scaling is applied. Required keys are 'min_inputs', 'max_inputs', 'min_targets', and 'max_targets'.

error_estimator

An error estimator for the problem. This can be any object with an estimate_error(U, mu, m) method. If error_estimator is not None, an estimate_error(U, mu) method is added to the model which will call error_estimator.estimate_error(U, mu, self).

name

Name of the model.

class pymor.models.neural_network.NeuralNetworkModel(neural_network, parameters={}, scaling_parameters={}, output_functional=None, products=None, error_estimator=None, visualizer=None, name=None)[source]

Bases: BaseNeuralNetworkModel

Class for models of stationary problems that use artificial neural networks.

This class implements a Model that uses a neural network for solving.

Parameters

neural_network

The neural network that approximates the mapping from parameter space to solution space. Should be an instance of FullyConnectedNN with input size that matches the (total) number of parameters and output size equal to the dimension of the reduced space.

parameters

Parameters of the reduced order model (the same as used in the full-order model).

scaling_parameters

Dict of tensors that determine how to scale inputs before passing them through the neural network and outputs after obtaining them from the neural network. If not provided or each entry is None, no scaling is applied. Required keys are 'min_inputs', 'max_inputs', 'min_targets', and 'max_targets'.

output_functional

Operator mapping a given solution to the model output. In many applications, this will be a Functional, i.e. an Operator mapping to scalars. This is not required, however.

products

A dict of inner product Operators defined on the discrete space the problem is posed on. For each product with key 'x' a corresponding attribute x_product, as well as a norm method x_norm is added to the model.

error_estimator

An error estimator for the problem. This can be any object with an estimate_error(U, mu, m) method. If error_estimator is not None, an estimate_error(U, mu) method is added to the model which will call error_estimator.estimate_error(U, mu, self).

visualizer

A visualizer for the problem. This can be any object with a visualize(U, m, ...) method. If visualizer is not None, a visualize(U, *args, **kwargs) method is added to the model which forwards its arguments to the visualizer’s visualize method.

name

Name of the model.

class pymor.models.neural_network.NeuralNetworkStatefreeOutputModel(neural_network, parameters={}, scaling_parameters={}, error_estimator=None, name=None)[source]

Bases: BaseNeuralNetworkModel

Class for models of the output of stationary problems that use ANNs.

This class implements a Model that uses a neural network for solving for the output quantity.

Parameters

neural_network

The neural network that approximates the mapping from parameter space to output space. Should be an instance of FullyConnectedNN with input size that matches the (total) number of parameters and output size equal to the dimension of the output space.

parameters

Parameters of the reduced order model (the same as used in the full-order model).

scaling_parameters

Dict of tensors that determine how to scale inputs before passing them through the neural network and outputs after obtaining them from the neural network. If not provided or each entry is None, no scaling is applied. Required keys are 'min_inputs', 'max_inputs', 'min_targets', and 'max_targets'.

error_estimator

An error estimator for the problem. This can be any object with an estimate_error(U, mu, m) method. If error_estimator is not None, an estimate_error(U, mu) method is added to the model which will call error_estimator.estimate_error(U, mu, self).

name

Name of the model.