OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
unscaling_layer.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// U N S C A L 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#include "scaling.h"
14#include "statistics.h"
15#include "variable.h"
16
17namespace opennn
18{
19
21class Unscaling final : public Layer
22{
23public:
24
26 Unscaling(const Shape& = {0}, const string& = "unscaling_layer");
27
28 Shape get_input_shape() const override { return { Index(scalers.size()) }; }
29 Shape get_output_shape() const override { return { Index(scalers.size()) }; }
30
31 const vector<Descriptives>& get_descriptives() const { return descriptives; }
32 const vector<ScalerMethod>& get_scalers() const { return scalers; }
33
42
43 float get_min_range() const { return min_range; }
44 float get_max_range() const { return max_range; }
45
47 void set(Index = 0, const string& = "unscaling_layer");
48
50 void set_input_shape(const Shape&) override;
52 void set_output_shape(const Shape&) override;
53
55 void set_descriptives(const vector<Descriptives>&);
57 void set_min_max_range(float min, float max);
59 void set_scalers(const vector<string>&);
61 void set_scalers(const string&);
62
64 float* link_states(float*) override;
65
67 void read_JSON_body(const Json*) override;
69 void write_JSON_body(JsonWriter&) const override;
70
72 string write_expression(const vector<string>& input_names,
73 const vector<string>& output_names) const override;
74
75private:
76
77 vector<Descriptives> descriptives;
78 vector<ScalerMethod> scalers;
79 float min_range = -1.0f;
80 float max_range = 1.0f;
81
82 Buffer op_storage;
83 bool op_storage_dirty = true;
84
85 UnscaleOp unscale_op;
86
87 void refresh_op_storage(Device device);
88};
89
90}
91
92// OpenNN: Open Neural Networks Library.
93// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
94// Licensed under the GNU Lesser General Public License v2.1 or later.
Definition json.h:85
Definition json.h:23
Layer()=default
const vector< ScalerMethod > & get_scalers() const
Definition unscaling_layer.h:32
void read_JSON_body(const Json *) override
Subclass hook reading the body section of the layer's JSON node.
void set_input_shape(const Shape &) override
Sets the input shape; subclasses override to derive dependent dimensions.
void write_JSON_body(JsonWriter &) const override
Subclass hook writing the body section of the layer's JSON node.
void set_descriptives(const vector< Descriptives > &)
Sets the descriptive statistics (min, max, mean, stddev) used for unscaling each variable.
float get_min_range() const
Definition unscaling_layer.h:43
void set_scalers(const string &)
Sets the same unscaling method for all output variables from its name.
Shape get_output_shape() const override
Returns the output shape; subclasses must implement this to expose their geometry.
Definition unscaling_layer.h:29
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_output_shape(const Shape &) override
Sets the output shape; subclasses override when the output is user-configurable.
VectorR get_minimums() const
Returns the per-variable minimum values from the stored descriptive statistics.
VectorR get_standard_deviations() const
Returns the per-variable standard deviations from the stored descriptive statistics.
Unscaling(const Shape &={0}, const string &="unscaling_layer")
Constructs an unscaling layer for the given number of outputs and label.
VectorR get_means() const
Returns the per-variable means from the stored descriptive statistics.
void set_min_max_range(float min, float max)
Sets the source range expected by min-max unscaling methods.
void set_scalers(const vector< string > &)
Sets the unscaling method for each output variable from a vector of method names.
float * link_states(float *) override
Binds the persistent-state region of the shared buffer to operator views.
const vector< Descriptives > & get_descriptives() const
Definition unscaling_layer.h:31
float get_max_range() const
Definition unscaling_layer.h:44
VectorR get_maximums() const
Returns the per-variable maximum values from the stored descriptive statistics.
void set(Index=0, const string &="unscaling_layer")
Reconfigures the layer with a new number of outputs and label.
Shape get_input_shape() const override
Returns the input shape stored by the layer.
Definition unscaling_layer.h:28
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
Owning raw byte buffer that lives on CPU or CUDA memory, with aligned (re)allocation.
Definition tensor_utilities.h:166
Fixed-capacity small-vector describing tensor dimensions (rank up to MaxRank).
Definition tensor_utilities.h:42
Inverse of ScaleOp: maps normalized outputs back to the original feature range.
Definition operators.h:1035