mindscience.models.neural_operator.FFNOBlocks

class mindscience.models.neural_operator.FFNOBlocks(in_channels, out_channels, n_modes, resolutions, factor=1, n_ff_layers=2, ff_weight_norm=False, layer_norm=True, dropout=0.0, r_padding=0, use_fork=False, forecast_ff=None, backcast_ff=None, fourier_weight=None, dft_compute_dtype=mstype.float32, ffno_compute_dtype=mstype.float32)[source]

The FFNOBlock, which usually accompanied by a Lifting Layer ahead and a Projection Layer behind, is a part of Factorized Fourier Neural Operator. It contains a Factorized Fourier Layer. The details can be found in A. Tran, A. Mathews, et. al: FACTORIZED FOURIER NEURAL OPERATORS.

Parameters
  • in_channels (int) – The number of channels in the input space.

  • out_channels (int) – The number of channels in the output space.

  • n_modes (Union[int, list(int)]) – The number of modes reserved after linear transformation in Fourier Layer.

  • resolutions (Union[int, list(int)]) – The resolutions of the input tensor.

  • factor (int, optional) – The number of neurons in the hidden layer of a feedforward network. Default: 1.

  • n_ff_layers (int, optional) – The number of layers (hidden layers) in the feedforward neural network. Default: 2.

  • ff_weight_norm (bool, optional) – Whether to do weight normalization in feedforward or not. Used as a reserved function interface, the weight normalization is not supported in feedforward. Default: False.

  • layer_norm (bool, optional) – Whether to do layer normalization in feedforward or not. Default: True.

  • dropout (float, optional) – The value of percent be dropped when applying dropout regularization. Default: 0.0.

  • r_padding (int, optional) – The number used to pad a tensor on the right in a certain dimension. Pad the domain if input is non-periodic. Default: 0.

  • use_fork (bool, optional) – Whether to perform forecasting or not. Default: False.

  • forecast_ff (Feedforward, optional) – The feedforward network of generating "backcast" output. Default: None.

  • backcast_ff (Feedforward, optional) – The feedforward network of generating "forecast" output. Default: None.

  • fourier_weight (ParameterTuple[Parmemter], optional) –

    The fourier weight for transforming data in the frequency domain, with a ParameterTuple of Parmemter with a length of 2N.

    • Even indices (0, 2, 4, …) represent the real parts of the complex parmemter.

    • Odd indices (1, 3, 5, …) represent the imaginary parts of the complex parmemter.

    Default: None, meaning no data is provided.

  • dft_compute_dtype (dtype.Number, optional) – The computation type of DFT in SpectralConv. Default: mstype.float32.

  • ffno_compute_dtype (dtype.Number, optional) – The computation type of MLP in ffno skip. Should be mstype.float32 or mstype.float16. mstype.float32 is recommended for the GPU backend, mstype.float16 is recommended for the Ascend backend. Default: mstype.float32.

Inputs:
  • x (Tensor) - Tensor of shape \((batch\_size, in\_channels, resolution)\).

Outputs:
  • output (Tensor) -Tensor of shape \((batch\_size, out\_channels, resolution)\).

Raises

ValueError – If ff_weight_norm is not False.

Examples

>>> import numpy as np
>>> from mindspore import Tensor
>>> import mindspore.common.dtype as mstype
>>> from mindscience.models.neural_operator.ffno import FFNOBlocks
>>> data = Tensor(np.ones([2, 128, 128, 2]), mstype.float32)
>>> net = FFNOBlocks(in_channels=2, out_channels=2, n_modes=[20, 20], resolutions=[128, 128])
>>> out0, out1 = net(data)
>>> print(data.shape, out0.shape, out1.shape)
(2, 128, 128, 2) (2, 128, 128, 2) (2, 128, 128, 2)