|
OpenNN
Open-source neural networks library
|
Per-feature output-clamping layer. More...
#include <bounding_layer.h>
Public Types | |
| using | BoundingMethod = Bound::Method |
| Alias for the underlying Bound::Method enumeration. | |
Public Member Functions | |
| Bounding (const Shape &output_shape={0}, const string &label="bounding_layer") | |
| Constructs a Bounding layer. | |
| Shape | get_input_shape () const override |
| Returns the per-sample input shape (same as output). | |
| Shape | get_output_shape () const override |
| Returns the per-sample output shape. | |
| const BoundingMethod & | get_bounding_method () const |
| Returns the configured bounding method. | |
| VectorR | get_lower_bounds () const |
| Returns the per-feature lower bounds. | |
| VectorR | get_upper_bounds () const |
| Returns the per-feature upper bounds. | |
| vector< Operator * > | get_operators () override |
| Returns the single Bound operator that implements this layer. | |
| void | set (const Shape &output_shape={0}, const string &label="bounding_layer") |
| Re-initializes the layer. | |
| void | set_input_shape (const Shape &) override |
| Updates the input shape (kept equal to the output shape). | |
| void | set_output_shape (const Shape &) override |
| Updates the output shape and resizes the bound vectors. | |
| void | set_bounding_method (const BoundingMethod &) |
| Sets the bounding method directly. | |
| void | set_bounding_method (const string &) |
| Sets the bounding method by name. | |
| void | set_lower_bounds (const VectorR &) |
| Sets every per-feature lower bound at once. | |
| void | set_lower_bound (Index feature_index, float value) |
| Sets the lower bound of a single feature. | |
| void | set_upper_bounds (const VectorR &) |
| Sets every per-feature upper bound at once. | |
| void | set_upper_bound (Index feature_index, float value) |
| Sets the upper bound of a single feature. | |
| void | read_JSON_body (const Json *) override |
| Reads the layer-specific JSON body (method, lower and upper bounds). | |
| void | write_JSON_body (JsonWriter &) const override |
| Writes the layer-specific JSON body (method, lower and upper bounds). | |
Public Member Functions inherited from opennn::Layer | |
| virtual | ~Layer ()=default |
| Virtual destructor; subclasses are owned via unique_ptr<Layer>. | |
| const string & | get_label () const |
| Returns the user-assigned label of this layer. | |
| const string & | get_name () const |
| Returns the canonical type name of this layer. | |
| LayerType | get_type () const |
| Returns the LayerType enumerator for this layer. | |
| void | set_label (string new_label) |
| Sets the human-readable label of this layer. | |
| Index | get_parameters_number () const |
| Total number of trainable parameters in this layer. | |
| virtual vector< pair< Shape, Type > > | get_parameter_specs () const |
| Specifications of the trainable parameter tensors owned by this layer. | |
| virtual vector< pair< Shape, Type > > | get_state_specs () const |
| Specifications of the persistent state tensors of this layer. | |
| virtual vector< pair< Shape, Type > > | get_forward_specs (Index batch_size) const |
| Specifications of the forward intermediate buffers for one batch. | |
| virtual vector< pair< Shape, Type > > | get_backward_specs (Index batch_size) const |
| Specifications of the backward intermediate buffers for one batch. | |
| vector< Shape > | get_parameter_shapes () const |
| Shape-only view of get_parameter_specs(). | |
| vector< Shape > | get_state_shapes () const |
| Shape-only view of get_state_specs(). | |
| vector< Shape > | get_forward_shapes (Index b) const |
Shape-only view of get_forward_specs() for batch size b. | |
| vector< Shape > | get_backward_shapes (Index b) const |
Shape-only view of get_backward_specs() for batch size b. | |
| vector< Type > | get_parameter_dtypes () const |
| Dtype-only view of get_parameter_specs(). | |
| vector< Type > | get_forward_dtypes (Index b) const |
Dtype-only view of get_forward_specs() for batch size b. | |
| vector< Type > | get_backward_dtypes (Index b) const |
Dtype-only view of get_backward_specs() for batch size b. | |
| virtual Activation::Function | get_output_activation () const |
| Activation function fused at the end of this layer, if any. | |
| Index | get_inputs_number () const |
| Total number of scalar inputs per sample (product of input dims). | |
| Index | get_outputs_number () const |
| Total number of scalar outputs per sample (product of output dims). | |
| virtual void | forward_propagate (ForwardPropagation &fp, size_t layer, bool is_training) noexcept |
Forward pass: reads inputs from fp and writes outputs into fp. | |
| virtual void | back_propagate (ForwardPropagation &, BackPropagation &, size_t) const noexcept |
| Backward pass: propagates gradients through this layer. | |
| virtual void | from_JSON (const JsonDocument &document) |
| Loads the layer configuration (hyperparameters) from JSON. | |
| virtual void | load_state_from_JSON (const JsonDocument &document) |
| Loads parameter and state tensors from a JSON document. | |
| virtual void | to_JSON (JsonWriter &writer) const |
| Writes the layer configuration to JSON. | |
| virtual void | print () const |
| Prints a human-readable summary of the layer to stdout. | |
| bool | get_is_trainable () const |
| Whether this layer has trainable parameters. | |
| Type | get_compute_dtype () const |
| Numerical type used for forward/backward computation. | |
| void | set_compute_dtype (Type new_compute_dtype) |
| Sets the compute dtype and triggers on_compute_dtype_changed(). | |
| virtual void | on_compute_dtype_changed () |
| Hook invoked after set_compute_dtype() mutates the dtype. | |
| virtual float * | link_parameters (float *pointer) |
| Wires this layer's parameter TensorViews onto an external buffer. | |
| virtual float * | link_states (float *pointer) |
| Wires this layer's state TensorViews onto an external buffer. | |
| vector< TensorView > & | get_parameter_views () |
| Mutable access to this layer's parameter TensorViews. | |
| const vector< TensorView > & | get_parameter_views () const |
| Read-only access to this layer's parameter TensorViews. | |
| vector< TensorView > & | get_state_views () |
| Mutable access to this layer's state TensorViews. | |
| const vector< TensorView > & | get_state_views () const |
| Read-only access to this layer's state TensorViews. | |
| void | redistribute_parameters_to_operators () |
| Forwards the current parameter views down to each composing Operator. | |
| void | redistribute_parameter_gradients_to_operators (vector< TensorView > &gradient_views) |
| Forwards externally provided gradient views down to each Operator. | |
| void | redistribute_states_to_operators () |
| Forwards the current state views down to each composing Operator. | |
Additional Inherited Members | |
Protected Member Functions inherited from opennn::Layer | |
| Layer ()=default | |
| Default constructor; only invoked by subclasses. | |
| float * | link_views (float *pointer, const vector< Shape > &shapes, vector< TensorView > &views, const char *tag) const |
Builds views over a contiguous float buffer using shapes. | |
| void | distribute_to_operators (vector< TensorView > &views, void(Operator::*link)(const vector< TensorView > &), vector< pair< Shape, Type > >(Operator::*specs)() const) |
| Generic helper used by the redistribute_*_to_operators() routines. | |
Protected Attributes inherited from opennn::Layer | |
| string | label = "my_layer" |
| User-visible label for this layer instance (default "my_layer"). | |
| string | name = "layer" |
| Canonical type name set by the subclass (e.g. "dense"). | |
| LayerType | layer_type = LayerType::Dense |
| Layer type tag set by the subclass. | |
| bool | is_trainable = true |
| True if the layer has parameters that participate in training. | |
| bool | is_first_layer = false |
| True if this layer is the network's input layer. | |
| Type | compute_dtype = Type::FP32 |
| Numerical type used for forward and backward computation. | |
| vector< TensorView > | parameters |
| Parameter TensorViews bound to the network's parameter arena. | |
| vector< TensorView > | states |
| State TensorViews bound to the network's state arena. | |
| vector< unique_ptr< Layer > > | layers |
| Sub-layers, when this layer is itself a composite. | |
Per-feature output-clamping layer.
Holds a lower bound and an upper bound for every feature and clamps the incoming values to that interval. Used as the last layer of regression networks when outputs are known to lie inside a physical range.
The layer has no trainable parameters.
Alias for the underlying Bound::Method enumeration.
| opennn::Bounding::Bounding | ( | const Shape & | output_shape = {0}, |
| const string & | label = "bounding_layer" ) |
Constructs a Bounding layer.
| output_shape | Per-sample output (and input) shape. |
| label | Human-readable label assigned to this layer. |
|
inline |
Returns the configured bounding method.
|
inlineoverridevirtual |
Returns the per-sample input shape (same as output).
Implements opennn::Layer.
| VectorR opennn::Bounding::get_lower_bounds | ( | ) | const |
Returns the per-feature lower bounds.
|
inlineoverridevirtual |
Returns the single Bound operator that implements this layer.
Reimplemented from opennn::Layer.
|
overridevirtual |
Returns the per-sample output shape.
Implements opennn::Layer.
| VectorR opennn::Bounding::get_upper_bounds | ( | ) | const |
Returns the per-feature upper bounds.
|
overridevirtual |
Reads the layer-specific JSON body (method, lower and upper bounds).
Reimplemented from opennn::Layer.
| void opennn::Bounding::set | ( | const Shape & | output_shape = {0}, |
| const string & | label = "bounding_layer" ) |
Re-initializes the layer.
| output_shape | Per-sample output shape. |
| label | Human-readable label. |
| void opennn::Bounding::set_bounding_method | ( | const BoundingMethod & | ) |
Sets the bounding method directly.
Receives a Bound::Method value (e.g. NoBounding, Clamp).
| void opennn::Bounding::set_bounding_method | ( | const string & | ) |
Sets the bounding method by name.
Receives the canonical method name; throws if it is unrecognized.
|
overridevirtual |
Updates the input shape (kept equal to the output shape).
Reimplemented from opennn::Layer.
| void opennn::Bounding::set_lower_bound | ( | Index | feature_index, |
| float | value ) |
Sets the lower bound of a single feature.
| feature_index | Index of the feature whose lower bound is updated. |
| value | New lower bound for that feature. |
| void opennn::Bounding::set_lower_bounds | ( | const VectorR & | ) |
Sets every per-feature lower bound at once.
Receives a vector with as many entries as the layer has features.
|
overridevirtual |
Updates the output shape and resizes the bound vectors.
Reimplemented from opennn::Layer.
| void opennn::Bounding::set_upper_bound | ( | Index | feature_index, |
| float | value ) |
Sets the upper bound of a single feature.
| feature_index | Index of the feature whose upper bound is updated. |
| value | New upper bound for that feature. |
| void opennn::Bounding::set_upper_bounds | ( | const VectorR & | ) |
Sets every per-feature upper bound at once.
Receives a vector with as many entries as the layer has features.
|
overridevirtual |
Writes the layer-specific JSON body (method, lower and upper bounds).
Reimplemented from opennn::Layer.