OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
bounding_layer.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// B O U N D I N G L A Y E R C L A S S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#pragma once
10
11#include "layer.h"
12#include "operators.h"
13
14namespace opennn
15{
16
18class Bounding final : public Layer
19{
20public:
21
23
25 Bounding(const Shape& = {0}, const string& = "bounding_layer");
26
27 Shape get_input_shape() const override { return output_shape; }
28 Shape get_output_shape() const override { return output_shape; }
29
30 const BoundingMethod& get_bounding_method() const { return bound.method; }
31
36
38 void set(const Shape& = {0}, const string& = "bounding_layer");
39
41 void set_input_shape(const Shape&) override;
42
46 void set_bounding_method(const string&);
47
51 void set_lower_bound(Index, float);
52
56 void set_upper_bound(Index, float);
57
59 float* link_states(float*) override;
60
62 void read_JSON_body(const Json*) override;
64 void write_JSON_body(JsonWriter&) const override;
65
67 string write_expression(const vector<string>& input_names,
68 const vector<string>& output_names) const override;
69
70private:
71
72 Shape output_shape;
73
74 vector<float> lower_bounds;
75 vector<float> upper_bounds;
76
77 Buffer op_storage;
78 bool op_storage_dirty = true;
79
80 BoundOp bound;
81
82 void refresh_op_storage(Device device);
83
84 static const EnumMap<BoundingMethod>& bounding_method_map();
85};
86
87}
88
89// OpenNN: Open Neural Networks Library.
90// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
91// Licensed under the GNU Lesser General Public License v2.1 or later.
void set_upper_bounds(const VectorR &)
Sets the full vector of upper bounds, one entry per output variable.
Shape get_output_shape() const override
Returns the output shape; subclasses must implement this to expose their geometry.
Definition bounding_layer.h:28
float * link_states(float *) override
Binds the persistent-state region of the shared buffer to operator views.
void write_JSON_body(JsonWriter &) const override
Subclass hook writing the body section of the layer's JSON node.
void set_lower_bound(Index, float)
Sets the lower bound of a single output variable by index.
BoundOp::Method BoundingMethod
Definition bounding_layer.h:22
Shape get_input_shape() const override
Returns the input shape stored by the layer.
Definition bounding_layer.h:27
void set_lower_bounds(const VectorR &)
Sets the full vector of lower bounds, one entry per output variable.
VectorR get_lower_bounds() const
Returns the configured lower bound for each output variable.
void set_bounding_method(const string &)
Sets the bounding method from its string name.
const BoundingMethod & get_bounding_method() const
Definition bounding_layer.h:30
void read_JSON_body(const Json *) override
Subclass hook reading the body section of the layer's JSON node.
VectorR get_upper_bounds() const
Returns the configured upper bound for each output variable.
void set_bounding_method(const BoundingMethod &)
Sets the bounding method enum used to clip outputs.
void set(const Shape &={0}, const string &="bounding_layer")
Reconfigures the layer with a new output shape and label.
string write_expression(const vector< string > &input_names, const vector< string > &output_names) const override
Returns a human-readable mathematical expression for this layer (empty by default).
void set_input_shape(const Shape &) override
Sets the input shape; subclasses override to derive dependent dimensions.
Bounding(const Shape &={0}, const string &="bounding_layer")
Constructs a bounding layer for the given output shape and label.
void set_upper_bound(Index, float)
Sets the upper bound of a single output variable by index.
Definition json.h:85
Definition json.h:23
Layer()=default
Definition adaptive_moment_estimation.h:14
Device
Execution device selection for OpenNN runtime (auto-detected, CPU or CUDA GPU).
Definition configuration.h:17
Matrix< float, Dynamic, 1 > VectorR
Definition pch.h:181
Clamps each output channel to a configurable lower/upper interval.
Definition operators.h:1004
Method
Disables bounding or enables per-channel clamping.
Definition operators.h:1006
Owning raw byte buffer that lives on CPU or CUDA memory, with aligned (re)allocation.
Definition tensor_utilities.h:166
Definition enum_map.h:18
Fixed-capacity small-vector describing tensor dimensions (rank up to MaxRank).
Definition tensor_utilities.h:42