OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::Recurrent Class Referencefinal

Basic recurrent (RNN) layer that unrolls over time steps with a shared activation. More...

#include <recurrent_layer.h>

Inheritance diagram for opennn::Recurrent:
[legend]

Public Member Functions

 Recurrent (const Shape &={0, 0}, const Shape &={0})
 Constructs a recurrent layer with input and output shapes.
 
Shape get_input_shape () const override
 Returns the input tensor shape (time_steps, input_features).
 
Shape get_output_shape () const override
 Returns the output tensor shape (hidden units).
 
const TensorViewget_biases () const
 
const TensorViewget_input_weights () const
 
const TensorViewget_recurrent_weights () const
 
const string & get_activation_function () const
 
vector< TensorSpecget_parameter_specs () const override
 Returns the tensor specifications for the trainable parameters.
 
vector< TensorSpecget_forward_specs (Index batch_size) const override
 Returns the tensor specifications used during forward propagation.
 
vector< TensorSpecget_backward_specs (Index batch_size) const override
 Returns the tensor specifications used during back propagation.
 
void set (const Shape &={}, const Shape &={})
 Reconfigures the layer with new input and output shapes.
 
void set_input_shape (const Shape &) override
 Updates the layer for a new input shape.
 
void set_output_shape (const Shape &) override
 Updates the layer for a new output shape.
 
void set_activation_function (const string &)
 Sets the activation function by name (e.g. "Tanh", "ReLU").
 
void forward_propagate (ForwardPropagation &, size_t, bool) noexcept override
 Runs the forward pass, unrolling the recurrence across time steps.
 
void back_propagate (ForwardPropagation &, BackPropagation &, size_t) const noexcept override
 Runs the backward pass (backpropagation through time).
 
void read_JSON_body (const Json *) override
 Reads the layer configuration from a JSON node.
 
void write_JSON_body (JsonWriter &) const override
 Writes the layer configuration to a JSON writer.
 
string write_expression (const vector< string > &input_names, const vector< string > &output_names) const override
 Returns a symbolic expression of the layer for export.
 
- Public Member Functions inherited from opennn::Layer
virtual ~Layer ()=default
 
const string & get_label () const
 
const string & get_name () const
 
LayerType get_type () const
 
void set_label (string new_label)
 
Index get_parameters_number () const
 Returns the total number of trainable parameters owned by this layer.
 
const vector< Operator * > & get_operators () const
 
virtual vector< TensorSpecget_state_specs () const
 Returns the tensor specs of persistent state (e.g. running mean/variance).
 
virtual ActivationOp::Function get_output_activation () const
 Returns the layer's output activation (Identity for most layers; overridden by Dense/Bounding).
 
Index get_inputs_number () const
 
Index get_outputs_number () const
 
virtual void from_JSON (const JsonDocument &document)
 Restores layer configuration and parameters from a JSON document.
 
virtual void load_state_from_JSON (const JsonDocument &document)
 Restores persistent state (e.g. running statistics) from a JSON document.
 
virtual void to_JSON (JsonWriter &writer) const
 Serializes layer configuration and parameters to a JSON writer.
 
virtual void print () const
 Prints a human-readable summary of the layer to standard output.
 
bool get_is_trainable () const
 
Type get_compute_dtype () const
 
void set_compute_dtype (Type new_compute_dtype)
 Sets the compute dtype and notifies subclasses via on_compute_dtype_changed().
 
virtual void on_compute_dtype_changed ()
 Subclass hook invoked when the compute dtype changes; default is no-op.
 
virtual float * link_states (float *pointer)
 Binds the persistent-state region of the shared buffer to operator views.
 
float * link_gradients (float *pointer, vector< TensorView > &gradient_views)
 Binds the gradient slice of the shared buffer to operator gradient views.
 
vector< TensorView > & get_parameter_views ()
 
const vector< TensorView > & get_parameter_views () const
 
void redistribute_parameters_to_operators ()
 Re-binds operator parameter views after the parameter buffer has been resized or moved.
 

Additional Inherited Members

- Protected Types inherited from opennn::Layer
enum  Forward { Input , Output }
 
enum  Backward { OutputDelta , InputDelta }
 
- Protected Member Functions inherited from opennn::Layer
 Layer ()=default
 
 Layer (LayerType t, bool trainable=true)
 
float * link_views_to_operators (vector< TensorView > &views, float *pointer, vector< TensorSpec >(Operator::*specs_fn)() const, void(Operator::*link_fn)(span< const TensorView >))
 
- Protected Attributes inherited from opennn::Layer
string label = "my_layer"
 
LayerType layer_type = LayerType::Dense
 
bool is_trainable = true
 
Shape input_shape
 
Type compute_dtype = Type::FP32
 
vector< TensorViewparameters
 
vector< TensorViewstates
 
vector< Operator * > operators
 

Detailed Description

Basic recurrent (RNN) layer that unrolls over time steps with a shared activation.

Constructor & Destructor Documentation

◆ Recurrent()

opennn::Recurrent::Recurrent ( const Shape & = {0, 0},
const Shape & = {0} )

Constructs a recurrent layer with input and output shapes.

Parameters
input_shapeInput shape as (time_steps, input_features).
output_shapeOutput shape (number of hidden units).

Member Function Documentation

◆ back_propagate()

void opennn::Recurrent::back_propagate ( ForwardPropagation & ,
BackPropagation & ,
size_t  ) const
overridevirtualnoexcept

Runs the backward pass (backpropagation through time).

Reimplemented from opennn::Layer.

◆ forward_propagate()

void opennn::Recurrent::forward_propagate ( ForwardPropagation & ,
size_t ,
bool  )
overridevirtualnoexcept

Runs the forward pass, unrolling the recurrence across time steps.

Reimplemented from opennn::Layer.

◆ get_activation_function()

const string & opennn::Recurrent::get_activation_function ( ) const
inline

◆ get_backward_specs()

vector< TensorSpec > opennn::Recurrent::get_backward_specs ( Index batch_size) const
overridevirtual

Returns the tensor specifications used during back propagation.

Reimplemented from opennn::Layer.

◆ get_biases()

const TensorView & opennn::Recurrent::get_biases ( ) const
inline

◆ get_forward_specs()

vector< TensorSpec > opennn::Recurrent::get_forward_specs ( Index batch_size) const
overridevirtual

Returns the tensor specifications used during forward propagation.

Reimplemented from opennn::Layer.

◆ get_input_shape()

Shape opennn::Recurrent::get_input_shape ( ) const
inlineoverridevirtual

Returns the input tensor shape (time_steps, input_features).

Reimplemented from opennn::Layer.

◆ get_input_weights()

const TensorView & opennn::Recurrent::get_input_weights ( ) const
inline

◆ get_output_shape()

Shape opennn::Recurrent::get_output_shape ( ) const
overridevirtual

Returns the output tensor shape (hidden units).

Implements opennn::Layer.

◆ get_parameter_specs()

vector< TensorSpec > opennn::Recurrent::get_parameter_specs ( ) const
overridevirtual

Returns the tensor specifications for the trainable parameters.

Reimplemented from opennn::Layer.

◆ get_recurrent_weights()

const TensorView & opennn::Recurrent::get_recurrent_weights ( ) const
inline

◆ read_JSON_body()

void opennn::Recurrent::read_JSON_body ( const Json * )
overridevirtual

Reads the layer configuration from a JSON node.

Reimplemented from opennn::Layer.

◆ set()

void opennn::Recurrent::set ( const Shape & = {},
const Shape & = {} )

Reconfigures the layer with new input and output shapes.

◆ set_activation_function()

void opennn::Recurrent::set_activation_function ( const string & )

Sets the activation function by name (e.g. "Tanh", "ReLU").

◆ set_input_shape()

void opennn::Recurrent::set_input_shape ( const Shape & )
overridevirtual

Updates the layer for a new input shape.

Reimplemented from opennn::Layer.

◆ set_output_shape()

void opennn::Recurrent::set_output_shape ( const Shape & )
overridevirtual

Updates the layer for a new output shape.

Reimplemented from opennn::Layer.

◆ write_expression()

string opennn::Recurrent::write_expression ( const vector< string > & input_names,
const vector< string > & output_names ) const
overridevirtual

Returns a symbolic expression of the layer for export.

Reimplemented from opennn::Layer.

◆ write_JSON_body()

void opennn::Recurrent::write_JSON_body ( JsonWriter & ) const
overridevirtual

Writes the layer configuration to a JSON writer.

Reimplemented from opennn::Layer.