OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
scaling_layer.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// 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 "statistics.h"
12#include "layer.h"
13#include "operators.h"
14#include "variable.h"
15
16namespace opennn
17{
18
20class Scaling final : public Layer
21{
22public:
23
25 Scaling(const Shape& = {});
26
27 Shape get_output_shape() const override { return input_shape; }
28
29 const vector<Descriptives>& get_descriptives() const { return descriptives; }
30 const vector<ScalerMethod>& get_scalers() const { return scalers; }
31
40
41 float get_min_range() const { return min_range; }
42 float get_max_range() const { return max_range; }
43
45 void set(const Shape& = {});
47 void set_input_shape(const Shape&) override;
48
50 void set_descriptives(const vector<Descriptives>&);
52 void set_min_max_range(float min, float max);
54 void set_scalers(const vector<string>&);
56 void set_scalers(const string&);
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 vector<Descriptives> descriptives;
73 vector<ScalerMethod> scalers;
74 float min_range = -1.0f;
75 float max_range = 1.0f;
76
77 Buffer op_storage;
78 bool op_storage_dirty = true;
79
80 ScaleOp scale_op;
81
82 void refresh_op_storage(Device device);
83};
84
85}
86
87// OpenNN: Open Neural Networks Library.
88// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
89// Licensed under the GNU Lesser General Public License v2.1 or later.
Definition json.h:85
Definition json.h:23
Layer()=default
Shape input_shape
Definition layer.h:256
VectorR get_maximums() const
Returns the per-variable maximum values from the stored descriptive statistics.
void set_min_max_range(float min, float max)
Sets the target output range used by min-max scaling methods.
void set_input_shape(const Shape &) override
Sets the input shape; subclasses override to derive dependent dimensions.
float get_min_range() const
Definition scaling_layer.h:41
void set(const Shape &={})
Reconfigures the layer with a new input shape, resetting descriptives and scalers.
const vector< ScalerMethod > & get_scalers() const
Definition scaling_layer.h:30
Scaling(const Shape &={})
Constructs a scaling layer for the given input shape.
VectorR get_means() const
Returns the per-variable means from the stored descriptive statistics.
void set_scalers(const vector< string > &)
Sets the scaling method for each input variable from a vector of method names.
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_scalers(const string &)
Sets the same scaling method for all input variables from its name.
float * link_states(float *) override
Binds the persistent-state region of the shared buffer to operator views.
void set_descriptives(const vector< Descriptives > &)
Sets the descriptive statistics (min, max, mean, stddev) used for scaling each variable.
Shape get_output_shape() const override
Returns the output shape; subclasses must implement this to expose their geometry.
Definition scaling_layer.h:27
VectorR get_standard_deviations() const
Returns the per-variable standard deviations from the stored descriptive statistics.
VectorR get_minimums() const
Returns the per-variable minimum values from the stored descriptive statistics.
void write_JSON_body(JsonWriter &) const override
Subclass hook writing the body section of the layer's JSON node.
float get_max_range() const
Definition scaling_layer.h:42
void read_JSON_body(const Json *) override
Subclass hook reading the body section of the layer's JSON node.
const vector< Descriptives > & get_descriptives() const
Definition scaling_layer.h:29
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
Scales inputs to a target range using per-feature minimum/maximum or mean/std statistics.
Definition operators.h:1019
Fixed-capacity small-vector describing tensor dimensions (rank up to MaxRank).
Definition tensor_utilities.h:42