OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
response_optimization.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// R E S P O N S E O P T I M I Z A T I O N 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 "pch.h"
12#include "dataset.h"
13#include "statistics.h"
14#include "variable.h"
15
16namespace opennn
17{
18
19class NeuralNetwork;
20
23{
24public:
25
28
30 struct Condition
31 {
33 float low_bound;
34 float up_bound;
35
37 Condition(ConditionType new_type = ConditionType::None, float new_low_bound = 0.0, float new_up_bound = 0.0)
38 : condition(new_type), low_bound(new_low_bound), up_bound(new_up_bound) {}
39 };
40
42 struct Domain
43 {
44 Domain() = default;
45 virtual ~Domain() = default;
46
48 Domain(const vector<Index>& feature_dimensions, const vector<Descriptives>& descriptives)
49 {
50 set(feature_dimensions, descriptives);
51 }
52
54 void set(const vector<Index>& feature_dimensions, const vector<Descriptives>& descriptives);
55
57 void bound(const vector<Index>& feature_dimensions, const vector<Condition>& conditions);
58
60 void reshape(const float zoom_factor,
61 const VectorR& center,
62 const MatrixR& subset_optimal_points,
63 const vector<Index>& input_feature_dimensions,
64 const vector<VariableType>& input_variable_types);
65
68 };
69
72 {
74 Objectives(const ResponseOptimization& response_optimization);
75
77
79
81
83 MatrixR extract(const MatrixR& inputs, const MatrixR& output) const;
84
86 void normalize(MatrixR& objective_matrix) const;
87 };
88
91
94
96 void set(NeuralNetwork* = nullptr, Dataset* = nullptr);
97
100
106 void set_condition(const string& name, const ConditionType condition, float low_bound = 0.0, float up_bound = 0.0);
107
108 void set_iterations(const int iterations);
109 void set_zoom_factor(float new_zoom_factor);
110 void set_evaluations_number(const int new_evaluations_number);
111 void set_relative_tolerance(float new_relative_tolerance);
112
114 vector<float> get_utopian_point() const;
115
117 Domain get_original_domain(const string role) const;
118
120 Condition get_condition(const Index index) const;
121
123 MatrixR calculate_random_inputs(const Domain& input_domain) const;
124
126 pair<MatrixR, MatrixR> filter_feasible_points(const MatrixR& inputs,
127 const MatrixR& outputs,
128 const Domain& output_domain) const;
129
131 pair<MatrixR, MatrixR> calculate_optimal_points(const MatrixR& feasible_inputs,
132 const MatrixR& feasible_outputs,
133 const Objectives& objectives) const;
134
136 MatrixR assemble_results(const MatrixR& inputs, const MatrixR& outputs) const;
137
140
142 pair<MatrixR, MatrixR> calculate_pareto(const MatrixR& inputs, const MatrixR& outputs, const MatrixR& objective_matrix) const;
143
145 pair<float, float> calculate_quality_metrics(const MatrixR& inputs, const MatrixR& outputs,const Objectives& objectives) const;
146
149
152
153private:
154
155 NeuralNetwork* neural_network = nullptr;
156
157 Dataset* dataset = nullptr;
158
159 vector<Condition> conditions;
160
161 Index evaluations_number = 2000;
162
163 Index max_iterations = 10;
164
165 Index min_iterations = 4;
166
167 float zoom_factor = 0.45f;
168
169 float relative_tolerance = 0.001f;
170
171};
172
173}
174
175// OpenNN: Open Neural Networks Library.
176// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
177// Licensed under the GNU Lesser General Public License v2.1 or later.
Abstract base class for OpenNN datasets, owning samples, variables, and metadata.
Definition dataset.h:61
Container of layers forming a feed-forward neural network, with parameter storage and I/O.
Definition neural_network.h:20
Domain get_original_domain(const string role) const
Returns the original (untrimmed) domain for variables playing the given role.
pair< MatrixR, MatrixR > calculate_optimal_points(const MatrixR &feasible_inputs, const MatrixR &feasible_outputs, const Objectives &objectives) const
Selects the optimal points among feasible candidates according to the supplied objectives.
MatrixR perform_response_optimization() const
Runs the response optimization using the configured conditions and returns the optimal results.
MatrixR assemble_results(const MatrixR &inputs, const MatrixR &outputs) const
Assembles the final results matrix concatenating inputs and outputs.
MatrixR perform_multiobjective_optimization(const Objectives &objectives) const
Performs multiobjective optimization and returns the Pareto-optimal input/output samples.
void set_zoom_factor(float new_zoom_factor)
pair< MatrixR, MatrixR > filter_feasible_points(const MatrixR &inputs, const MatrixR &outputs, const Domain &output_domain) const
Filters the (inputs, outputs) pairs whose outputs fall inside the feasible output domain.
pair< MatrixR, MatrixR > calculate_pareto(const MatrixR &inputs, const MatrixR &outputs, const MatrixR &objective_matrix) const
Computes the Pareto front of the supplied input/output samples.
Objectives build_objectives() const
Builds the Objectives helper from the current conditions.
MatrixR perform_single_objective_optimization(const Objectives &objectives) const
Performs single-objective optimization and returns the best input/output pair.
ConditionType
Types of constraint or objective applied to an input or output variable.
Definition response_optimization.h:27
@ EqualTo
Definition response_optimization.h:27
@ Between
Definition response_optimization.h:27
@ None
Definition response_optimization.h:27
@ Maximize
Definition response_optimization.h:27
@ LessEqualTo
Definition response_optimization.h:27
@ GreaterEqualTo
Definition response_optimization.h:27
@ LessThan
Definition response_optimization.h:27
@ Minimize
Definition response_optimization.h:27
@ GreaterThan
Definition response_optimization.h:27
void set_iterations(const int iterations)
pair< float, float > calculate_quality_metrics(const MatrixR &inputs, const MatrixR &outputs, const Objectives &objectives) const
Computes quality metrics of the optimization (e.g. distance to utopian point).
void set_relative_tolerance(float new_relative_tolerance)
void clear_conditions()
Removes all conditions previously configured on input and output variables.
void set_evaluations_number(const int new_evaluations_number)
void set_condition(const string &name, const ConditionType condition, float low_bound=0.0, float up_bound=0.0)
Adds or replaces the condition applied to the variable with the given name.
ResponseOptimization(NeuralNetwork *=nullptr, Dataset *=nullptr)
Constructs the optimizer bound to an optional neural network and dataset.
vector< float > get_utopian_point() const
Returns the coordinates of the utopian point used as reference for multiobjective optimization.
MatrixR calculate_random_inputs(const Domain &input_domain) const
Draws a random sample of input points within the given input domain.
void set(NeuralNetwork *=nullptr, Dataset *=nullptr)
Binds the optimizer to a neural network and a dataset.
Condition get_condition(const Index index) const
Returns the configured condition at the given index.
Definition adaptive_moment_estimation.h:14
vector< Descriptives > descriptives(const MatrixR &)
Returns the per-column descriptives of a matrix.
Matrix< float, Dynamic, 1 > VectorR
Definition pch.h:181
Matrix< float, Dynamic, Dynamic, Layout > MatrixR
Definition pch.h:177
Constraint or objective imposed on a single variable, with optional bounds.
Definition response_optimization.h:31
Condition(ConditionType new_type=ConditionType::None, float new_low_bound=0.0, float new_up_bound=0.0)
Builds a condition of the given type with the given bounds.
Definition response_optimization.h:37
ConditionType condition
Definition response_optimization.h:32
float low_bound
Definition response_optimization.h:33
float up_bound
Definition response_optimization.h:34
Bounded domain in input or output space defined by inferior and superior frontiers.
Definition response_optimization.h:43
Domain(const vector< Index > &feature_dimensions, const vector< Descriptives > &descriptives)
Builds a domain from feature dimensions and per-feature descriptives.
Definition response_optimization.h:48
VectorR inferior_frontier
Definition response_optimization.h:66
void reshape(const float zoom_factor, const VectorR &center, const MatrixR &subset_optimal_points, const vector< Index > &input_feature_dimensions, const vector< VariableType > &input_variable_types)
Zooms and recenters the domain around the supplied optimal points for the next iteration.
void bound(const vector< Index > &feature_dimensions, const vector< Condition > &conditions)
Tightens the frontiers using the supplied per-variable conditions.
void set(const vector< Index > &feature_dimensions, const vector< Descriptives > &descriptives)
Initializes the frontiers from feature dimensions and per-feature descriptives.
VectorR superior_frontier
Definition response_optimization.h:67
Encodes the objectives extracted from the response optimization configuration.
Definition response_optimization.h:72
void normalize(MatrixR &objective_matrix) const
Normalizes the objective matrix in place using the precomputed normalizer.
MatrixR extract(const MatrixR &inputs, const MatrixR &output) const
Extracts the objective values for the given inputs and outputs.
MatrixR objective_normalizer
Definition response_optimization.h:80
MatrixR objective_sources
Definition response_optimization.h:76
MatrixR utopian_and_senses
Definition response_optimization.h:78
Objectives(const ResponseOptimization &response_optimization)
Builds the objective matrices from the parent response optimization.