opm-common
Loading...
Searching...
No Matches
Opm::ML::NNLayerDense< Evaluation > Class Template Reference
Inheritance diagram for Opm::ML::NNLayerDense< Evaluation >:
Opm::ML::NNLayer< Evaluation >

Public Member Functions

 NNLayerDense (Tensor< float > weights={}, Tensor< float > biases={}, ActivationType activation_type=ActivationType::kLinear)
bool loadLayer (std::ifstream &file) override
bool apply (const Tensor< Evaluation > &in, Tensor< Evaluation > &out) override
 Applies the forward pass of a dense (fully connected) neural-network layer.

Member Function Documentation

◆ apply()

template<class Evaluation>
bool Opm::ML::NNLayerDense< Evaluation >::apply ( const Tensor< Evaluation > & in,
Tensor< Evaluation > & out )
overridevirtual

Applies the forward pass of a dense (fully connected) neural-network layer.

This method performs a matrix–vector multiplication between the layer's weight matrix and the input tensor, adds the bias vector, and then applies the configured activation function.

Shape conventions

  • in is treated as a 1D row vector of length weights_.dims_[0].
  • weights_ has shape (input_dim, output_dim):
    • rows = input features
    • columns = output neurons
  • biases_ is a vector of length output_dim.
  • out is a 1D vector of length output_dim.

This implements:

\‍[    \text{tmp}_j = \sum_i \text{in}_i \cdot W_{i,j} + b_j,
    \qquad \text{out} = \text{activation}(\text{tmp})
\‍]

Note on row-major vs column-major

The current implementation assumes row-major access to W and is efficient when using larger batch sizes. For inference with very small batches (especially (1 × input_dim)), a column-major layout or transposed multiply could improve cache locality because each output neuron would read contiguous memory. Whether to switch depends on expected inference batch sizes and the storage layout of Tensor<Evaluation>. This will depend on future applications of ML. Current applications and best related convention:

  • Hybrid Newton:
    • input (1, N_cells x N_in_feat) --> output(1, N_cells x N_out_feat)
    • Best convention: column-major

Implements Opm::ML::NNLayer< Evaluation >.

◆ loadLayer()

template<class Evaluation>
bool Opm::ML::NNLayerDense< Evaluation >::loadLayer ( std::ifstream & file)
overridevirtual

The documentation for this class was generated from the following file: