‹ Back to Tutorials

The software model of OpenNN

This tutorial describes the current high-level C++ software model of OpenNN. The library is divided into dependency-ordered modules for core utilities, neural networks, datasets, training, model selection, testing analysis, response optimization and ready-made models.

The diagrams use the Unified Modeling Language (UML) to show the most important public classes and their relationships. Internal helper types are omitted so that the model remains readable.

Contents:

  1. Core classes
  2. Associations
  3. Compositions
  4. Configured and specialized classes
  5. Members and methods

1. Core classes

The main classes cover the complete model lifecycle, from loading data to evaluating and optimizing a trained model.

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    class Dataset
    class NeuralNetwork
    class TrainingStrategy
    class ModelSelection
    class TestingAnalysis
    class ResponseOptimization
  • Dataset: abstract data interface for samples, variables, roles, shapes and batches.
  • NeuralNetwork: owns and executes a directed graph of layers on CPU or CUDA.
  • TrainingStrategy: combines a loss and an optimizer to train a network with a dataset.
  • ModelSelection: searches for useful inputs and an appropriate hidden-layer size.
  • TestingAnalysis: evaluates a trained model on testing samples.
  • ResponseOptimization: searches for model inputs that satisfy constraints and optimize one or more outputs.

2. Associations

These classes collaborate through non-owning references. Ownership of datasets and networks remains with the application.

Training and selection

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction LR
    TrainingStrategy --> NeuralNetwork
    TrainingStrategy --> Dataset
    ModelSelection --> TrainingStrategy

Evaluation and response optimization

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction LR
    TestingAnalysis --> NeuralNetwork
    TestingAnalysis --> Dataset
    ResponseOptimization --> NeuralNetwork
  • TrainingStrategy points to the NeuralNetwork and Dataset used during training.
  • ModelSelection repeatedly invokes its TrainingStrategy to compare candidates.
  • TestingAnalysis combines network outputs with the corresponding testing targets.
  • ResponseOptimization evaluates the network while exploring feasible input values.

3. Compositions

Dataset

Dataset defines the common batching and metadata interface. Concrete datasets implement storage and preprocessing for each data modality.

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction TB
    class Dataset
    class TabularDataset
    class ImageDataset
    class LanguageDataset
    class TextGenerationDataset
    class TimeSeriesDataset
    class BertDataset
    class YoloDataset
    Dataset <|-- TabularDataset
    Dataset <|-- ImageDataset
    Dataset <|-- LanguageDataset
    Dataset <|-- TextGenerationDataset
    TabularDataset <|-- TimeSeriesDataset
    TabularDataset <|-- BertDataset
    ImageDataset <|-- YoloDataset
  • TabularDataset: delimited tabular files, variables, missing values, correlations and scaling.
  • TimeSeriesDataset: tabular sequences with lagged inputs and forecast targets.
  • ImageDataset: image folders and image preprocessing.
  • YoloDataset: object-detection images, boxes and class labels.
  • LanguageDataset: paired input and target text sequences.
  • TextGenerationDataset: token blocks created from a continuous text corpus.
  • BertDataset: BERT token, segment and attention-mask features.

NeuralNetwork

A NeuralNetwork owns Layer objects and records the source layer indices for every connection. This supports sequential models, residual paths and multi-input graphs.

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction TB
    class Layer
    class Scaling
    class Unscaling
    class Clamping
    class Dense
    class Activation
    class Recurrent
    class LongShortTermMemory
    Layer <|-- Scaling
    Scaling <|-- Unscaling
    Layer <|-- Clamping
    Layer <|-- Dense
    Layer <|-- Activation
    Layer <|-- Recurrent
    Layer <|-- LongShortTermMemory
%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction TB
    class Layer
    class Convolutional
    class Pooling
    class Pooling3d
    class Flatten
    class Normalization3d
    class Upsampling
    class Concatenation
    class Addition
    class C2PSA
    class Detection
    class DetectionV8
    class NonMaxSuppression
    Layer <|-- Convolutional
    Layer <|-- Pooling
    Layer <|-- Pooling3d
    Layer <|-- Flatten
    Layer <|-- Normalization3d
    Layer <|-- Upsampling
    Layer <|-- Concatenation
    Layer <|-- Addition
    Layer <|-- C2PSA
    Layer <|-- Detection
    Layer <|-- DetectionV8
    Layer <|-- NonMaxSuppression
%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction TB
    class Layer
    class Tokenizer
    class Embedding
    class MultiHeadAttention
    class GroupedQueryAttention
    Layer <|-- Tokenizer
    Layer <|-- Embedding
    Layer <|-- MultiHeadAttention
    Layer <|-- GroupedQueryAttention

The current catalogue no longer contains DenseRelu, ConvolutionalRelu or Bounding classes. Activations are configured in their corresponding layers, and output limits are implemented by Clamping. The name Bounding is accepted only as a legacy loading alias.

Ready-made models

The classes in opennn/models build common architectures on top of NeuralNetwork.

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction TB
    class NeuralNetwork
    class ApproximationNetwork
    class ClassificationNetwork
    class ForecastingNetwork
    class ForecastingLstmNetwork
    class AutoAssociationNetwork
    class ImageClassificationNetwork
    class ResNet
    class YoloNetwork
    NeuralNetwork <|-- ApproximationNetwork
    NeuralNetwork <|-- ClassificationNetwork
    NeuralNetwork <|-- ForecastingNetwork
    NeuralNetwork <|-- ForecastingLstmNetwork
    NeuralNetwork <|-- AutoAssociationNetwork
    NeuralNetwork <|-- ImageClassificationNetwork
    NeuralNetwork <|-- ResNet
    NeuralNetwork <|-- YoloNetwork
%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction TB
    class NeuralNetwork
    class TextClassificationNetwork
    class Transformer
    class TextGenerationNetwork
    class Qwen3
    class Bert
    class BertForSequenceClassification
    NeuralNetwork <|-- TextClassificationNetwork
    NeuralNetwork <|-- Transformer
    NeuralNetwork <|-- TextGenerationNetwork
    NeuralNetwork <|-- Qwen3
    NeuralNetwork <|-- Bert
    NeuralNetwork <|-- BertForSequenceClassification

TrainingStrategy

TrainingStrategy owns one Loss and one Optimizer. Both point to the same network and dataset used by the training loop.

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction LR
    class TrainingStrategy {
        -unique_ptr~Loss~ loss
        -unique_ptr~Optimizer~ optimizer
        -NeuralNetwork* neural_network
        -Dataset* dataset
        +train() TrainingResult
    }
    class Loss
    class Optimizer
    class NeuralNetwork
    class Dataset
    TrainingStrategy *-- Loss : owns
    TrainingStrategy *-- Optimizer : owns
    TrainingStrategy --> NeuralNetwork : uses
    TrainingStrategy --> Dataset : uses

ModelSelection

ModelSelection owns a GrowingNeurons object and an optional input-selection strategy. All selection algorithms share the common SelectionAlgorithm configuration.

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction TB
    class ModelSelection
    class SelectionAlgorithm
    class InputsSelection
    class GrowingInputs
    class GeneticAlgorithm
    class GrowingNeurons
    SelectionAlgorithm <|-- InputsSelection
    SelectionAlgorithm <|-- GrowingNeurons
    InputsSelection <|-- GrowingInputs
    InputsSelection <|-- GeneticAlgorithm
    ModelSelection *-- InputsSelection : owns selected strategy
    ModelSelection *-- GrowingNeurons : owns

The former separate NeuronSelection hierarchy no longer exists. NeuronSelection is retained only as a compatibility alias for GrowingNeurons.

4. Configured and specialized classes

Loss

Loss is a single class configured with an Error enum. It also supports L1, L2 or no regularization.

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    class Loss {
        +MeanSquaredError
        +MeanAbsoluteError
        +NormalizedSquaredError
        +WeightedSquaredError
        +CrossEntropy
        +CrossEntropy3d
        +MinkowskiError
        +Yolo
        +set_error(Error)
        +set_regularization(Regularization)
    }

Optimizer

The optimizer registry exposes four named implementations. The base Optimizer also contains the shared training loop, stopping criteria, batching and callbacks.

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    direction TB
    class Optimizer
    class AdaptiveMomentEstimation
    class QuasiNewtonMethod
    class StochasticGradientDescent
    class LevenbergMarquardtAlgorithm
    Optimizer <|-- AdaptiveMomentEstimation
    Optimizer <|-- QuasiNewtonMethod
    Optimizer <|-- StochasticGradientDescent
    Optimizer <|-- LevenbergMarquardtAlgorithm

InputsSelection

InputsSelection is the abstract feature-selection interface. Its current implementations are GrowingInputs and GeneticAlgorithm. Neuron selection is performed directly by GrowingNeurons.

5. Members and methods

The following diagrams summarize representative public methods. They are intentionally shorter than the complete headers.

Dataset and TabularDataset

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    class Dataset {
        +split_samples(training, validation, testing)
        +get_features_number(role) Index
        +get_feature_names(role) vector~string~
        +get_input_shape() Shape
        +get_target_shape() Shape
        +fill_batch(Batch, indices, features)
    }
    class TabularDataset {
        +set(path, separator, has_header, has_ids)
        +scale_features(role) vector~Descriptives~
        +unscale_features(role, descriptives)
        +read_csv()
    }
    Dataset <|-- TabularDataset

NeuralNetwork

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    class NeuralNetwork {
        +add_layer(unique_ptr~Layer~, source_indices) Index
        +compile(Device)
        +get_layer(index_or_name) Layer
        +get_source_layers() vector
        +calculate_outputs(Tensor) MatrixR
        +save(path)
        +load(path)
    }

TrainingStrategy

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    class TrainingStrategy {
        +TrainingStrategy(NeuralNetwork*, Dataset*)
        +set_loss(name)
        +set_optimization_algorithm(name)
        +get_loss() Loss*
        +get_optimization_algorithm() Optimizer*
        +train() TrainingResult
        +save(path)
        +load(path)
    }

ModelSelection

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    class ModelSelection {
        +ModelSelection(TrainingStrategy*)
        +perform_input_selection() InputsSelectionResult
        +perform_neurons_selection() NeuronsSelectionResult
        +get_inputs_selection_name() string
        +save(path)
        +load(path)
    }

TestingAnalysis

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    class TestingAnalysis {
        +TestingAnalysis(NeuralNetwork*, Dataset*)
        +calculate_error_data() Tensor3
        +perform_goodness_of_fit_analysis() results
        +calculate_confusion(threshold) MatrixI
        +perform_roc_analysis() RocAnalysis
        +calculate_reconstruction_errors(role) VectorR
    }

ResponseOptimization

%%{init: {"look":"classic","theme":"base","themeVariables":{"background":"#ffffff","primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#ffffff","tertiaryColor":"#ffffff","edgeLabelBackground":"#ffffff","fontFamily":"Outfit, Arial, sans-serif"},"class":{"hideEmptyMembersBox":true}}}%%
classDiagram
    class ResponseOptimization {
        +ResponseOptimization(NeuralNetwork*)
        +set_constraint(name, comparison, low, up)
        +set_objective(name, sense, value)
        +perform_response_optimization() MatrixR
        +perform_multiobjective_optimization() MatrixR
    }

References