OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::NeuralNetwork Class Reference

Stack of Layers forming a trainable model. More...

#include <neural_network.h>

Inheritance diagram for opennn::NeuralNetwork:
[legend]

Public Member Functions

 NeuralNetwork ()
 Default-constructs an empty network.
 
virtual ~NeuralNetwork ()=default
 Defaulted virtual destructor for safe polymorphic deletion.
 
 NeuralNetwork (const filesystem::path &file_name)
 Constructs a network by loading a serialized model from disk.
 
void add_layer (unique_ptr< Layer > new_layer, const vector< Index > &input_indices=vector< Index >())
 Appends a layer to the stack.
 
const Configuration::Resolvedget_config () const
 Returns the resolved device/precision configuration.
 
bool is_gpu () const
 Reports whether the network is configured to run on CUDA.
 
bool is_cpu () const
 Reports whether the network is configured to run on CPU.
 
Type get_training_type () const
 Returns the precision used for training.
 
Type get_inference_type () const
 Returns the precision used for inference.
 
vector< vector< Shape > > get_parameter_shapes () const
 Returns the parameter shapes of every layer.
 
vector< vector< Shape > > get_state_shapes () const
 Returns the persistent state shapes of every layer.
 
vector< vector< Shape > > get_forward_shapes (Index batch_size) const
 Returns the forward-propagation buffer shapes for a given batch size.
 
vector< vector< Shape > > get_backward_shapes (Index batch_size) const
 Returns the backward-propagation buffer shapes for a given batch size.
 
Index get_states_size () const
 Returns the total size in floats of all persistent state buffers.
 
Index get_forward_size (Index batch_size) const
 Returns the total size in floats of the forward-propagation workspace.
 
Index get_backward_size (Index batch_size) const
 Returns the total size in floats of the backward-propagation workspace.
 
void compile ()
 Allocates parameters and resolves layer-input indices.
 
bool has (const string &layer_name) const
 Reports whether the network contains a layer of the given name.
 
bool has (LayerType type) const
 Reports whether the network contains a layer of the given type.
 
bool is_empty () const
 Reports whether the network has zero layers.
 
float * get_parameters_data ()
 Returns the parameter buffer as a raw float pointer.
 
const float * get_parameters_data () const
 Returns the parameter buffer as a raw float pointer (const overload).
 
Index get_parameters_size () const
 Returns the parameter count in floats.
 
const vector< Variable > & get_input_variables () const
 Returns the input variables describing each input feature.
 
const vector< string > get_input_feature_names () const
 Returns the names of the input features.
 
const vector< Variable > & get_output_variables () const
 Returns the output variables describing each output target.
 
const vector< string > get_output_feature_names () const
 Returns the names of the output features.
 
const vector< unique_ptr< Layer > > & get_layers () const
 Returns the layer stack.
 
const unique_ptr< Layer > & get_layer (const Index i) const
 Returns the layer at a given index.
 
const unique_ptr< Layer > & get_layer (const string &layer_name) const
 Returns the layer with a given name.
 
Index get_layer_index (const string &layer_name) const
 Returns the index of the layer with a given name.
 
const vector< vector< Index > > & get_layer_input_indices () const
 Returns the per-layer input-layer indices.
 
vector< vector< Index > > get_layer_output_indices () const
 Returns the per-layer output-layer indices.
 
Layerget_first (const string &layer_name)
 Returns the first layer of a given type by name.
 
Layerget_first (LayerType type)
 Returns the first layer of a given type.
 
const Layerget_first (const string &layer_name) const
 Returns the first layer of a given type by name (const overload).
 
const Layerget_first (LayerType type) const
 Returns the first layer of a given type (const overload).
 
void set_layers_number (const Index new_layers_number)
 Resizes the layer stack.
 
void set_layer_input_indices (const vector< vector< Index > > &new_layer_input_indices)
 Replaces the entire layer-input wiring.
 
void set_layer_input_indices (const Index layer_index, const vector< Index > &new_input_indices)
 Replaces the input wiring of a single layer by index.
 
void set_layer_input_indices (const string &layer_name, const vector< string > &input_layer_names)
 Replaces the input wiring of a single layer by name.
 
void set_layer_input_indices (const string &layer_name, initializer_list< string > input_layer_names)
 Replaces the input wiring of a single layer by name (initializer-list overload).
 
void set_layer_input_indices (const string &layer_name, const string &input_layer_name)
 Sets a single source layer as input to a destination layer.
 
void set_input_variables (const vector< Variable > &new_input_variables)
 Replaces the input variables.
 
void set_output_variables (const vector< Variable > &new_output_variables)
 Replaces the output variables.
 
void set_input_names (const vector< string > &new_input_names)
 Sets the names of the input features.
 
void set_output_names (const vector< string > &new_output_names)
 Sets the names of the output features.
 
void set_input_shape (const Shape &new_input_shape)
 Sets the input shape of the network.
 
void set_default ()
 Resets non-architectural state to defaults.
 
Index get_layers_number () const
 Returns the number of layers.
 
Index get_layers_number (const string &layer_name) const
 Returns the number of layers of a given type by name.
 
Index get_layers_number (LayerType type) const
 Returns the number of layers of a given type.
 
Index get_first_trainable_layer_index () const
 Returns the index of the first trainable layer.
 
Index get_last_trainable_layer_index () const
 Returns the index of the last trainable layer.
 
Index get_inputs_number () const
 Returns the total number of input features.
 
Index get_outputs_number () const
 Returns the total number of output features.
 
Shape get_input_shape () const
 Returns the network's input shape.
 
Shape get_output_shape () const
 Returns the network's output shape.
 
Activation::Function get_output_activation () const
 Returns the activation function of the last layer.
 
Index get_parameters_number () const
 Returns the total number of trainable parameters.
 
vector< Index > get_layer_parameter_numbers () const
 Returns the parameter count of every layer.
 
void set_parameters (const VectorR &new_parameters)
 Replaces all trainable parameters.
 
void set_parameters_random ()
 Initializes parameters with uniform random values.
 
void set_parameters_glorot ()
 Initializes parameters with Glorot (Xavier) uniform values.
 
MatrixR calculate_outputs (const vector< TensorView > &inputs)
 Computes outputs from a list of input tensor views.
 
MatrixR calculate_outputs (const MatrixR &inputs)
 Computes outputs for tabular inputs.
 
MatrixR calculate_outputs (const Tensor3 &inputs)
 Computes outputs for rank-3 inputs (e.g. sequence data).
 
MatrixR calculate_outputs (const Tensor4 &inputs)
 Computes outputs for rank-4 inputs (e.g. images).
 
MatrixR calculate_directional_inputs (const Index direction, const VectorR &point, float minimum, float maximum, Index points_number=101) const
 Computes outputs along a directional sweep of one input.
 
Tensor3 calculate_outputs (const Tensor3 &inputs, const Tensor3 &context)
 Computes outputs from two rank-3 inputs (encoder/decoder pair).
 
Index calculate_image_output (const filesystem::path &image_path)
 Runs the network on a single image and returns the predicted class.
 
MatrixR calculate_text_outputs (const Tensor< string, 1 > &texts)
 Runs the network on a batch of strings and returns class outputs.
 
void from_JSON (const JsonDocument &document)
 Restores the network from a JSON document.
 
void to_JSON (JsonWriter &writer) const
 Serializes the network to JSON.
 
void save (const filesystem::path &file_name) const
 Saves the full network (architecture + parameters) to a JSON file.
 
void save_parameters (const filesystem::path &file_name) const
 Saves only the parameters in binary form.
 
void load (const filesystem::path &file_name)
 Loads the full network (architecture + parameters) from a JSON file.
 
void load_parameters_binary (const filesystem::path &file_name)
 Loads parameters from a binary file produced by save_parameters().
 
vector< string > get_names_string () const
 Returns the names of every input and output feature.
 
void save_outputs (MatrixR &outputs, const filesystem::path &file_name)
 Saves a tabular outputs tensor to a CSV file.
 
void save_outputs (Tensor3 &outputs, const filesystem::path &file_name)
 Saves a rank-3 outputs tensor to a CSV file.
 
void forward_propagate (const vector< TensorView > &inputs, ForwardPropagation &forward, bool is_training=false) const
 Runs the forward pass and writes intermediate activations into forward.
 
void forward_propagate (const vector< TensorView > &inputs, const VectorR &parameters, ForwardPropagation &forward)
 Runs the forward pass with explicitly supplied parameters.
 
vector< string > get_layer_labels () const
 Returns a label for every layer (name + key hyperparameters).
 

Protected Attributes

string name = "neural_network"
 Network identifier; used as a JSON tag.
 
vector< Variableinput_variables
 Description of every input feature (role, scaler, type).
 
vector< Variableoutput_variables
 Description of every output feature (role, scaler, type).
 
vector< unique_ptr< Layer > > layers
 Owned layers in execution order.
 
vector< vector< Index > > layer_input_indices
 Per-destination-layer list of source-layer indices.
 
Buffer parameters
 Flat parameter buffer shared by all layers.
 
Buffer parameters_bf16 {Device::CUDA}
 BF16 mirror of parameters for mixed-precision CUDA training.
 
vector< vector< vector< TensorView > > > parameter_views
 Per-layer per-parameter-group views into parameters.
 
Buffer states
 Flat persistent-state buffer shared by stateful layers (e.g. Recurrent).
 
Configuration::Resolved config
 Resolved device/precision configuration applied at compile time.
 

Detailed Description

Stack of Layers forming a trainable model.

The class is designed to be subclassed; the standard architectures (ApproximationNetwork, ClassificationNetwork, ForecastingNetwork, ImageClassificationNetwork, etc.) preconfigure the layer stack for common tasks. Direct users can also call add_layer() and compile() to build custom topologies.

Holds a single parameter Buffer that all layers index into, plus a parallel states Buffer for layers that maintain hidden state. CUDA mirrors are available when compiled with OPENNN_HAS_CUDA.

Constructor & Destructor Documentation

◆ NeuralNetwork() [1/2]

opennn::NeuralNetwork::NeuralNetwork ( )

Default-constructs an empty network.

No layers, no input/output variables, default device/precision config.

◆ ~NeuralNetwork()

virtual opennn::NeuralNetwork::~NeuralNetwork ( )
virtualdefault

Defaulted virtual destructor for safe polymorphic deletion.

◆ NeuralNetwork() [2/2]

opennn::NeuralNetwork::NeuralNetwork ( const filesystem::path & file_name)

Constructs a network by loading a serialized model from disk.

Parameters
file_namePath to a JSON file produced by save().

Member Function Documentation

◆ add_layer()

void opennn::NeuralNetwork::add_layer ( unique_ptr< Layer > new_layer,
const vector< Index > & input_indices = vector< Index >() )

Appends a layer to the stack.

Parameters
new_layerOwning pointer to the layer; ownership is transferred.
input_indicesIndices of the layers whose outputs feed this layer. Empty means "the previous layer".

◆ calculate_directional_inputs()

MatrixR opennn::NeuralNetwork::calculate_directional_inputs ( const Index direction,
const VectorR & point,
float minimum,
float maximum,
Index points_number = 101 ) const

Computes outputs along a directional sweep of one input.

Holds the other inputs at point and varies input direction across points_number values in [minimum, maximum].

Parameters
directionIndex of the input to sweep.
pointReference point for all other inputs.
minimumMinimum value for the swept input.
maximumMaximum value for the swept input.
points_numberNumber of evaluation points along the sweep.
Returns
Matrix [points_number x outputs] with the network response.

◆ calculate_image_output()

Index opennn::NeuralNetwork::calculate_image_output ( const filesystem::path & image_path)

Runs the network on a single image and returns the predicted class.

Parameters
image_pathPath to the image file.
Returns
Predicted class index.

◆ calculate_outputs() [1/5]

MatrixR opennn::NeuralNetwork::calculate_outputs ( const MatrixR & inputs)

Computes outputs for tabular inputs.

Parameters
inputsInput matrix [samples x features].
Returns
Network outputs as a matrix [samples x outputs].

◆ calculate_outputs() [2/5]

MatrixR opennn::NeuralNetwork::calculate_outputs ( const Tensor3 & inputs)

Computes outputs for rank-3 inputs (e.g. sequence data).

Parameters
inputsRank-3 input tensor.
Returns
Network outputs as a matrix [samples x outputs].

◆ calculate_outputs() [3/5]

Tensor3 opennn::NeuralNetwork::calculate_outputs ( const Tensor3 & inputs,
const Tensor3 & context )

Computes outputs from two rank-3 inputs (encoder/decoder pair).

Parameters
inputsRank-3 input tensor.
contextRank-3 context tensor.
Returns
Rank-3 output tensor.

◆ calculate_outputs() [4/5]

MatrixR opennn::NeuralNetwork::calculate_outputs ( const Tensor4 & inputs)

Computes outputs for rank-4 inputs (e.g. images).

Parameters
inputsRank-4 input tensor.
Returns
Network outputs as a matrix [samples x outputs].

◆ calculate_outputs() [5/5]

MatrixR opennn::NeuralNetwork::calculate_outputs ( const vector< TensorView > & inputs)

Computes outputs from a list of input tensor views.

Parameters
inputsInput tensor views indexed by input slot.
Returns
Network outputs as a matrix [samples x outputs].

◆ calculate_text_outputs()

MatrixR opennn::NeuralNetwork::calculate_text_outputs ( const Tensor< string, 1 > & texts)

Runs the network on a batch of strings and returns class outputs.

Parameters
textsOne string per sample.
Returns
Output matrix [samples x outputs].

◆ compile()

void opennn::NeuralNetwork::compile ( )

Allocates parameters and resolves layer-input indices.

Should be called after the layer stack is fully assembled. Validates input/output shape consistency and sets up the shared parameter buffer.

◆ forward_propagate() [1/2]

void opennn::NeuralNetwork::forward_propagate ( const vector< TensorView > & inputs,
const VectorR & parameters,
ForwardPropagation & forward )

Runs the forward pass with explicitly supplied parameters.

Used by line-search style optimizers that probe along a direction.

Parameters
inputsInput tensor views.
parametersParameter vector used for this evaluation.
forwardForward-propagation workspace; populated in place.

◆ forward_propagate() [2/2]

void opennn::NeuralNetwork::forward_propagate ( const vector< TensorView > & inputs,
ForwardPropagation & forward,
bool is_training = false ) const

Runs the forward pass and writes intermediate activations into forward.

Parameters
inputsInput tensor views.
forwardForward-propagation workspace; populated in place.
is_trainingWhether to enable training-time behavior (e.g. dropout).

◆ from_JSON()

void opennn::NeuralNetwork::from_JSON ( const JsonDocument & document)

Restores the network from a JSON document.

Parameters
documentParsed JSON produced by to_JSON().

◆ get_backward_shapes()

vector< vector< Shape > > opennn::NeuralNetwork::get_backward_shapes ( Index batch_size) const
inline

Returns the backward-propagation buffer shapes for a given batch size.

Parameters
batch_sizeNumber of samples per backward pass.
Returns
Outer vector indexed by layer, inner by buffer group.

◆ get_backward_size()

Index opennn::NeuralNetwork::get_backward_size ( Index batch_size) const
inline

Returns the total size in floats of the backward-propagation workspace.

Parameters
batch_sizeNumber of samples per backward pass.
Returns
Element count summed across layers, accounting for alignment.

◆ get_config()

const Configuration::Resolved & opennn::NeuralNetwork::get_config ( ) const
inline

Returns the resolved device/precision configuration.

Returns
Const reference to the configuration.

◆ get_first() [1/4]

Layer * opennn::NeuralNetwork::get_first ( const string & layer_name)

Returns the first layer of a given type by name.

Parameters
layer_nameLayer type name (e.g. "Scaling", "Dense").
Returns
Pointer to the layer, or nullptr if none exists.

◆ get_first() [2/4]

const Layer * opennn::NeuralNetwork::get_first ( const string & layer_name) const

Returns the first layer of a given type by name (const overload).

Parameters
layer_nameLayer type name.
Returns
Const pointer to the layer, or nullptr.

◆ get_first() [3/4]

Layer * opennn::NeuralNetwork::get_first ( LayerType type)

Returns the first layer of a given type.

Parameters
typeLayer type enum.
Returns
Pointer to the layer, or nullptr if none exists.

◆ get_first() [4/4]

const Layer * opennn::NeuralNetwork::get_first ( LayerType type) const

Returns the first layer of a given type (const overload).

Parameters
typeLayer type enum.
Returns
Const pointer to the layer, or nullptr.

◆ get_first_trainable_layer_index()

Index opennn::NeuralNetwork::get_first_trainable_layer_index ( ) const

Returns the index of the first trainable layer.

Returns
Layer index, or -1 if no trainable layer exists.

◆ get_forward_shapes()

vector< vector< Shape > > opennn::NeuralNetwork::get_forward_shapes ( Index batch_size) const
inline

Returns the forward-propagation buffer shapes for a given batch size.

Parameters
batch_sizeNumber of samples per forward pass.
Returns
Outer vector indexed by layer, inner by buffer group.

◆ get_forward_size()

Index opennn::NeuralNetwork::get_forward_size ( Index batch_size) const
inline

Returns the total size in floats of the forward-propagation workspace.

Parameters
batch_sizeNumber of samples per forward pass.
Returns
Element count summed across layers, accounting for alignment.

◆ get_inference_type()

Type opennn::NeuralNetwork::get_inference_type ( ) const
inline

Returns the precision used for inference.

Returns
Configured inference Type (e.g. FP32, BF16, FP16).

◆ get_input_feature_names()

const vector< string > opennn::NeuralNetwork::get_input_feature_names ( ) const

Returns the names of the input features.

Returns
Vector of input feature names, one per input variable.

◆ get_input_shape()

Shape opennn::NeuralNetwork::get_input_shape ( ) const

Returns the network's input shape.

Returns
Shape of the input tensor expected by the first layer.

◆ get_input_variables()

const vector< Variable > & opennn::NeuralNetwork::get_input_variables ( ) const
inline

Returns the input variables describing each input feature.

Returns
Const reference to the input variables vector.

◆ get_inputs_number()

Index opennn::NeuralNetwork::get_inputs_number ( ) const

Returns the total number of input features.

Returns
Inputs count.

◆ get_last_trainable_layer_index()

Index opennn::NeuralNetwork::get_last_trainable_layer_index ( ) const

Returns the index of the last trainable layer.

Returns
Layer index, or -1 if no trainable layer exists.

◆ get_layer() [1/2]

const unique_ptr< Layer > & opennn::NeuralNetwork::get_layer ( const Index i) const
inline

Returns the layer at a given index.

Parameters
iZero-based index into the layer stack.
Returns
Const reference to the owned Layer pointer.

◆ get_layer() [2/2]

const unique_ptr< Layer > & opennn::NeuralNetwork::get_layer ( const string & layer_name) const

Returns the layer with a given name.

Parameters
layer_nameLayer name.
Returns
Const reference to the owned Layer pointer.

◆ get_layer_index()

Index opennn::NeuralNetwork::get_layer_index ( const string & layer_name) const

Returns the index of the layer with a given name.

Parameters
layer_nameLayer name.
Returns
Zero-based index into the layer stack.

◆ get_layer_input_indices()

const vector< vector< Index > > & opennn::NeuralNetwork::get_layer_input_indices ( ) const
inline

Returns the per-layer input-layer indices.

Returns
Outer vector indexed by destination layer, inner by source layer.

◆ get_layer_labels()

vector< string > opennn::NeuralNetwork::get_layer_labels ( ) const

Returns a label for every layer (name + key hyperparameters).

Returns
Layer labels suitable for printing.

◆ get_layer_output_indices()

vector< vector< Index > > opennn::NeuralNetwork::get_layer_output_indices ( ) const

Returns the per-layer output-layer indices.

Returns
Outer vector indexed by source layer, inner by destination layer.

◆ get_layer_parameter_numbers()

vector< Index > opennn::NeuralNetwork::get_layer_parameter_numbers ( ) const

Returns the parameter count of every layer.

Returns
Vector of parameter counts, one per layer.

◆ get_layers()

const vector< unique_ptr< Layer > > & opennn::NeuralNetwork::get_layers ( ) const
inline

Returns the layer stack.

Returns
Const reference to the vector of owned Layer pointers.

◆ get_layers_number() [1/3]

Index opennn::NeuralNetwork::get_layers_number ( ) const
inline

Returns the number of layers.

Returns
Layer count.

◆ get_layers_number() [2/3]

Index opennn::NeuralNetwork::get_layers_number ( const string & layer_name) const

Returns the number of layers of a given type by name.

Parameters
layer_nameLayer type name.
Returns
Number of matching layers.

◆ get_layers_number() [3/3]

Index opennn::NeuralNetwork::get_layers_number ( LayerType type) const

Returns the number of layers of a given type.

Parameters
typeLayer type enum.
Returns
Number of matching layers.

◆ get_names_string()

vector< string > opennn::NeuralNetwork::get_names_string ( ) const

Returns the names of every input and output feature.

Returns
Concatenated vector of input feature names followed by output feature names.

◆ get_output_activation()

Activation::Function opennn::NeuralNetwork::get_output_activation ( ) const

Returns the activation function of the last layer.

Returns
Activation::Function enum value.

◆ get_output_feature_names()

const vector< string > opennn::NeuralNetwork::get_output_feature_names ( ) const

Returns the names of the output features.

Returns
Vector of output feature names, one per output variable.

◆ get_output_shape()

Shape opennn::NeuralNetwork::get_output_shape ( ) const

Returns the network's output shape.

Returns
Shape of the output tensor produced by the last layer.

◆ get_output_variables()

const vector< Variable > & opennn::NeuralNetwork::get_output_variables ( ) const
inline

Returns the output variables describing each output target.

Returns
Const reference to the output variables vector.

◆ get_outputs_number()

Index opennn::NeuralNetwork::get_outputs_number ( ) const

Returns the total number of output features.

Returns
Outputs count.

◆ get_parameter_shapes()

vector< vector< Shape > > opennn::NeuralNetwork::get_parameter_shapes ( ) const
inline

Returns the parameter shapes of every layer.

Returns
Outer vector indexed by layer, inner by parameter group.

◆ get_parameters_data() [1/2]

float * opennn::NeuralNetwork::get_parameters_data ( )
inline

Returns the parameter buffer as a raw float pointer.

Returns
Pointer to the underlying float storage.

◆ get_parameters_data() [2/2]

const float * opennn::NeuralNetwork::get_parameters_data ( ) const
inline

Returns the parameter buffer as a raw float pointer (const overload).

Returns
Const pointer to the underlying float storage.

◆ get_parameters_number()

Index opennn::NeuralNetwork::get_parameters_number ( ) const

Returns the total number of trainable parameters.

Returns
Parameter count summed across layers.

◆ get_parameters_size()

Index opennn::NeuralNetwork::get_parameters_size ( ) const
inline

Returns the parameter count in floats.

Returns
Number of float entries in the parameter buffer.

◆ get_state_shapes()

vector< vector< Shape > > opennn::NeuralNetwork::get_state_shapes ( ) const
inline

Returns the persistent state shapes of every layer.

Returns
Outer vector indexed by layer, inner by state group.

◆ get_states_size()

Index opennn::NeuralNetwork::get_states_size ( ) const
inline

Returns the total size in floats of all persistent state buffers.

Returns
Element count summed across layers, accounting for alignment.

◆ get_training_type()

Type opennn::NeuralNetwork::get_training_type ( ) const
inline

Returns the precision used for training.

Returns
Configured training Type (e.g. FP32, BF16).

◆ has() [1/2]

bool opennn::NeuralNetwork::has ( const string & layer_name) const

Reports whether the network contains a layer of the given name.

Parameters
layer_nameLayer type name (e.g. "Dense", "Recurrent").
Returns
true if any layer matches the name.

◆ has() [2/2]

bool opennn::NeuralNetwork::has ( LayerType type) const

Reports whether the network contains a layer of the given type.

Parameters
typeLayer type enum.
Returns
true if any layer matches the type.

◆ is_cpu()

bool opennn::NeuralNetwork::is_cpu ( ) const
inline

Reports whether the network is configured to run on CPU.

Returns
true when the configured device is Device::CPU.

◆ is_empty()

bool opennn::NeuralNetwork::is_empty ( ) const
inline

Reports whether the network has zero layers.

Returns
true when the layer stack is empty.

◆ is_gpu()

bool opennn::NeuralNetwork::is_gpu ( ) const
inline

Reports whether the network is configured to run on CUDA.

Returns
true when the configured device is Device::CUDA.

◆ load()

void opennn::NeuralNetwork::load ( const filesystem::path & file_name)

Loads the full network (architecture + parameters) from a JSON file.

Parameters
file_nameSource path.

◆ load_parameters_binary()

void opennn::NeuralNetwork::load_parameters_binary ( const filesystem::path & file_name)

Loads parameters from a binary file produced by save_parameters().

The architecture must already match the saved network.

Parameters
file_nameSource path.

◆ save()

void opennn::NeuralNetwork::save ( const filesystem::path & file_name) const

Saves the full network (architecture + parameters) to a JSON file.

Parameters
file_nameDestination path.

◆ save_outputs() [1/2]

void opennn::NeuralNetwork::save_outputs ( MatrixR & outputs,
const filesystem::path & file_name )

Saves a tabular outputs tensor to a CSV file.

Parameters
outputsOutputs matrix [samples x outputs].
file_nameDestination path.

◆ save_outputs() [2/2]

void opennn::NeuralNetwork::save_outputs ( Tensor3 & outputs,
const filesystem::path & file_name )

Saves a rank-3 outputs tensor to a CSV file.

Parameters
outputsRank-3 outputs tensor.
file_nameDestination path.

◆ save_parameters()

void opennn::NeuralNetwork::save_parameters ( const filesystem::path & file_name) const

Saves only the parameters in binary form.

Parameters
file_nameDestination path.

◆ set_default()

void opennn::NeuralNetwork::set_default ( )

Resets non-architectural state to defaults.

◆ set_input_names()

void opennn::NeuralNetwork::set_input_names ( const vector< string > & new_input_names)

Sets the names of the input features.

Parameters
new_input_namesOne entry per input variable.

◆ set_input_shape()

void opennn::NeuralNetwork::set_input_shape ( const Shape & new_input_shape)

Sets the input shape of the network.

Reshapes the first layer accordingly. Useful when reusing an architecture for a dataset with different feature dimensions.

Parameters
new_input_shapeNew input shape.

◆ set_input_variables()

void opennn::NeuralNetwork::set_input_variables ( const vector< Variable > & new_input_variables)
inline

Replaces the input variables.

Parameters
new_input_variablesNew input variables vector.

◆ set_layer_input_indices() [1/5]

void opennn::NeuralNetwork::set_layer_input_indices ( const Index layer_index,
const vector< Index > & new_input_indices )
inline

Replaces the input wiring of a single layer by index.

Parameters
layer_indexIndex of the destination layer.
new_input_indicesIndices of source layers feeding it.

◆ set_layer_input_indices() [2/5]

void opennn::NeuralNetwork::set_layer_input_indices ( const string & layer_name,
const string & input_layer_name )

Sets a single source layer as input to a destination layer.

Parameters
layer_nameName of the destination layer.
input_layer_nameName of the source layer.

◆ set_layer_input_indices() [3/5]

void opennn::NeuralNetwork::set_layer_input_indices ( const string & layer_name,
const vector< string > & input_layer_names )

Replaces the input wiring of a single layer by name.

Parameters
layer_nameName of the destination layer.
input_layer_namesNames of layers feeding it.

◆ set_layer_input_indices() [4/5]

void opennn::NeuralNetwork::set_layer_input_indices ( const string & layer_name,
initializer_list< string > input_layer_names )

Replaces the input wiring of a single layer by name (initializer-list overload).

Parameters
layer_nameName of the destination layer.
input_layer_namesNames of layers feeding it.

◆ set_layer_input_indices() [5/5]

void opennn::NeuralNetwork::set_layer_input_indices ( const vector< vector< Index > > & new_layer_input_indices)
inline

Replaces the entire layer-input wiring.

Parameters
new_layer_input_indicesOuter vector indexed by destination layer.

◆ set_layers_number()

void opennn::NeuralNetwork::set_layers_number ( const Index new_layers_number)
inline

Resizes the layer stack.

Parameters
new_layers_numberNew layer count; existing entries are preserved.

◆ set_output_names()

void opennn::NeuralNetwork::set_output_names ( const vector< string > & new_output_names)

Sets the names of the output features.

Parameters
new_output_namesOne entry per output variable.

◆ set_output_variables()

void opennn::NeuralNetwork::set_output_variables ( const vector< Variable > & new_output_variables)
inline

Replaces the output variables.

Parameters
new_output_variablesNew output variables vector.

◆ set_parameters()

void opennn::NeuralNetwork::set_parameters ( const VectorR & new_parameters)

Replaces all trainable parameters.

Parameters
new_parametersFlat vector with as many entries as get_parameters_number().

◆ set_parameters_glorot()

void opennn::NeuralNetwork::set_parameters_glorot ( )

Initializes parameters with Glorot (Xavier) uniform values.

◆ set_parameters_random()

void opennn::NeuralNetwork::set_parameters_random ( )

Initializes parameters with uniform random values.

◆ to_JSON()

void opennn::NeuralNetwork::to_JSON ( JsonWriter & writer) const

Serializes the network to JSON.

Parameters
writerJSON writer that receives the network tree.

Member Data Documentation

◆ config

Configuration::Resolved opennn::NeuralNetwork::config
protected

Resolved device/precision configuration applied at compile time.

◆ input_variables

vector<Variable> opennn::NeuralNetwork::input_variables
protected

Description of every input feature (role, scaler, type).

◆ layer_input_indices

vector<vector<Index> > opennn::NeuralNetwork::layer_input_indices
protected

Per-destination-layer list of source-layer indices.

◆ layers

vector<unique_ptr<Layer> > opennn::NeuralNetwork::layers
protected

Owned layers in execution order.

◆ name

string opennn::NeuralNetwork::name = "neural_network"
protected

Network identifier; used as a JSON tag.

◆ output_variables

vector<Variable> opennn::NeuralNetwork::output_variables
protected

Description of every output feature (role, scaler, type).

◆ parameter_views

vector<vector<vector<TensorView> > > opennn::NeuralNetwork::parameter_views
protected

Per-layer per-parameter-group views into parameters.

◆ parameters

Buffer opennn::NeuralNetwork::parameters
protected

Flat parameter buffer shared by all layers.

◆ parameters_bf16

Buffer opennn::NeuralNetwork::parameters_bf16 {Device::CUDA}
protected

BF16 mirror of parameters for mixed-precision CUDA training.

◆ states

Buffer opennn::NeuralNetwork::states
protected

Flat persistent-state buffer shared by stateful layers (e.g. Recurrent).