response_optimization.h
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#ifndef RESPONSEOPTIMIZATION_H
10#define RESPONSEOPTIMIZATION_H
11
12// System includes
13
14#include <cmath>
15#include <cstdlib>
16#include <fstream>
17#include <iostream>
18#include <string>
19#include <sstream>
20
21// OpenNN includes
22
23#include "config.h"
24#include "neural_network.h"
25
26namespace OpenNN
27{
28
29struct ResponseOptimizationResults;
30
32
36
38{
39
40public:
41
42 // DEFAULT CONSTRUCTOR
43
44 explicit ResponseOptimization();
45
47
48 virtual ~ResponseOptimization();
49
51
52 enum class Condition{Between, EqualTo, LessEqualTo, GreaterEqualTo, Minimum, Maximum};
53
54 // Get methods
55
56 Tensor<Condition, 1> get_inputs_conditions();
57 Tensor<Condition, 1> get_outputs_conditions();
58
59 Tensor<type, 1> get_inputs_minimums();
60 Tensor<type, 1> get_inputs_maximums();
61 Tensor<type, 1> get_outputs_minimums();
62 Tensor<type, 1> get_outputs_maximums();
63
64 // Set methods
65
66 void set_evaluations_number(const Index&);
67
68 void set_input_condition(const string&, const Condition&, const Tensor<type, 1>& = Tensor<type, 1>());
69 void set_output_condition(const string&, const Condition&, const Tensor<type, 1>& = Tensor<type, 1>());
70
71 void set_input_condition(const Index&, const Condition&, const Tensor<type, 1>& = Tensor<type, 1>());
72 void set_output_condition(const Index&, const Condition&, const Tensor<type, 1>& = Tensor<type, 1>());
73
74 void set_inputs_outputs_conditions(const Tensor<string, 1>&, const Tensor<string, 1>&, const Tensor<type, 1>& = Tensor<type, 1>());
75
76 Tensor<Condition, 1> get_conditions(const Tensor<string, 1>&) const;
77 Tensor<Tensor<type, 1>, 1> get_values_conditions(const Tensor<Condition, 1>&, const Tensor<type, 1>&) const;
78
79 Tensor<type, 2> calculate_inputs() const;
80
81 Tensor<type, 2> calculate_envelope(const Tensor<type, 2>&, const Tensor<type, 2>&) const;
82
84
85private:
86
87 NeuralNetwork* neural_network_pointer = nullptr;
88
89 Tensor<Condition, 1> inputs_conditions;
90 Tensor<Condition, 1> outputs_conditions;
91
92 Tensor<type, 1> inputs_minimums;
93 Tensor<type, 1> inputs_maximums;
94
95 Tensor<type, 1> outputs_minimums;
96 Tensor<type, 1> outputs_maximums;
97
98 Index evaluations_number = 1000;
99
100 type calculate_random_uniform(const type&, const type&) const;
101
102};
103
104
108
110{
112
113 explicit ResponseOptimizationResults(NeuralNetwork* new_neural_network_pointer)
114 {
115 neural_network_pointer = new_neural_network_pointer;
116 }
117
119
120 NeuralNetwork* neural_network_pointer = nullptr;
121
122 Tensor<type, 1> optimal_variables;
123
124 type optimum_objective = type(0);
125
126 void print() const
127 {
128 const Index inputs_number = neural_network_pointer->get_inputs_number();
129 const Index outputs_number = neural_network_pointer->get_outputs_number();
130
131 const Tensor<string, 1> inputs_names = neural_network_pointer->get_inputs_names();
132 const Tensor<string, 1> outputs_names = neural_network_pointer->get_outputs_names();
133
134 for(Index i = 0; i < inputs_number; i++)
135 {
136 cout << inputs_names[i] << ": " << optimal_variables[i] << endl;
137 }
138
139 for(Index i = 0; i < outputs_number; i++)
140 {
141 cout << outputs_names[i] << " " << optimal_variables[inputs_number+i] << endl;
142 }
143
144 cout << "Objective: " << optimum_objective << endl;
145 }
146};
147
148
149}
150
151#endif
152
153
154// OpenNN: Open Neural Networks Library.
155// Copyright(C) 2005-2021 Artificial Intelligence Techniques, SL.
156//
157// This library is free software; you can redistribute it and/or
158// modify it under the terms of the GNU Lesser General Public
159// License as published by the Free Software Foundation; either
160// version 2.1 of the License, or any later version.
161//
162// This library is distributed in the hope that it will be useful,
163// but WITHOUT ANY WARRANTY; without even the implied warranty of
164// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
165// Lesser General Public License for more details.
166
167// You should have received a copy of the GNU Lesser General Public
168// License along with this library; if not, write to the Free Software
169
170// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
171
This class is used to optimize model response identify the combinations of variable settings jointly ...
ResponseOptimizationResults * perform_optimization() const
void set_inputs_outputs_conditions(const Tensor< string, 1 > &, const Tensor< string, 1 > &, const Tensor< type, 1 > &=Tensor< type, 1 >())
Condition
Enumeration of available conditions for response optimization.
virtual ~ResponseOptimization()
Destructor.
ResponseOptimizationResults(NeuralNetwork *new_neural_network_pointer)
Default constructor.