OpenNN  2.2
Open Neural Networks Library
model_selection.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.opennn.net */
5 /* */
6 /* M O D E L S E L E C T I O N C L A S S H E A D E R */
7 /* */
8 /* Fernando Gomez */
9 /* Artelnics - Making intelligent use of data */
10 /* fernandogomez@artelnics.com */
11 /* */
12 /****************************************************************************************************************/
13 
14 #ifndef __MODELSELECTION_H__
15 #define __MODELSELECTION_H__
16 
17 // System includes
18 
19 #include <iostream>
20 #include <fstream>
21 #include <string>
22 #include <sstream>
23 #include <cmath>
24 #include <ctime>
25 
26 // OpenNN includes
27 
28 #include "training_strategy.h"
29 
30 #include "incremental_order.h"
31 #include "golden_section_order.h"
32 #include "simulated_annealing_order.h"
33 
34 #include "growing_inputs.h"
35 #include "pruning_inputs.h"
36 #include "genetic_algorithm.h"
37 
38 #include "f1_score_optimization_threshold.h"
39 #include "matthew_correlation_optimization_threshold.h"
40 #include "youden_index_optimization_threshold.h"
41 #include "kappa_coefficient_optimization_threshold.h"
42 #include "roc_curve_optimization_threshold.h"
43 
44 // TinyXml includes
45 
46 #include "../tinyxml2/tinyxml2.h"
47 
48 namespace OpenNN
49 {
50 
53 
55 {
56 
57 public:
58 
59  // DEFAULT CONSTRUCTOR
60 
61  explicit ModelSelection(void);
62 
63  // TRAINING STRATEGY CONSTRUCTOR
64 
66 
67  // FILE CONSTRUCTOR
68 
69  explicit ModelSelection(const std::string&);
70 
71  // XML CONSTRUCTOR
72 
73  explicit ModelSelection(const tinyxml2::XMLDocument&);
74 
75 
76  // DESTRUCTOR
77 
78  virtual ~ModelSelection(void);
79 
81 
83  {
84  NO_INPUTS_SELECTION,
85  GROWING_INPUTS,
86  PRUNING_INPUTS,
87  GENETIC_ALGORITHM
88  };
89 
91 
93  {
94  NO_ORDER_SELECTION,
95  INCREMENTAL_ORDER,
96  GOLDEN_SECTION,
97  SIMULATED_ANNEALING
98  };
99 
101 
103  {
104  NO_THRESHOLD_SELECTION,
105  F1_SCORE_OPTIMIZATION,
106  MATTHEW_CORRELATION,
107  YOUDEN_INDEX,
108  KAPPA_COEFFICIENT,
109  ROC_CURVE_DISTANCE
110  };
111 
112 
113  // STRUCTURES
114 
118 
120  {
121 
122  void save(const std::string&) const;
123 
124  // Order selection results
125 
127 
129 
131 
133 
135 
137 
139 
141 
143 
145 
147 
149 
151 
153 
155 
157 
159 
161 
163 
165 
167 
169 
170  };
171 
172  // METHODS
173 
174  // Get methods
175 
177  bool has_training_strategy(void) const;
178 
179  const OrderSelectionType& get_order_selection_type(void) const;
182 
186 
190 
196 
197  // Set methods
198 
199  void set_default(void);
200 
201  void set_display(const bool&);
202 
204 
205 #ifdef __OPENNN_MPI__
206  void set_MPI(TrainingStrategy*, const ModelSelection*);
207 
208  void set_inputs_selection_MPI(const ModelSelection*);
209  void set_order_selection_MPI(const ModelSelection*);
210  void set_threshold_selection_MPI(const ModelSelection*);
211 #endif
212 
214  void set_order_selection_type(const std::string&);
215 
217  void set_inputs_selection_type(const std::string&);
218 
220  void set_threshold_selection_type(const std::string&);
221 
222  void set_approximation(const bool&);
223 
224  // Pointer methods
225 
226  void destruct_order_selection(void);
227 
228  void destruct_inputs_selection(void);
229 
230  void destruct_threshold_selection(void);
231 
232  // Model selection methods
233 
234  void check(void) const;
235 
237 
239 
241 
243 
245 
246  // Serialization methods
247 
248  tinyxml2::XMLDocument* to_XML(void) const;
249  void from_XML(const tinyxml2::XMLDocument&);
250 
251  void write_XML(tinyxml2::XMLPrinter&) const;
252  // void read_XML( );
253 
254  void print(void) const;
255  void save(const std::string&) const;
256  void load(const std::string&);
257 
258 private:
259 
260  // MEMBERS
261 
263 
265 
267 
269 
271 
273 
275 
277 
279 
281 
283 
285 
287 
289 
291 
293 
295 
297 
299 
301 
303 
305 
307 
309 
311 
313 
315 
317 
319 
321 
323 
324  bool display;
325 };
326 
327 }
328 
329 #endif
const ThresholdSelectionType & get_threshold_selection_type(void) const
Returns the type of algorithm for the threshold selection.
void from_XML(const tinyxml2::XMLDocument &)
const InputsSelectionType & get_inputs_selection_type(void) const
Returns the type of algorithm for the inputs selection.
InputsSelectionType
Enumeration of all the available types of inputs selection algorithms.
IncrementalOrder * get_incremental_order_pointer(void) const
Returns a pointer to the incremental order selection algorithm.
ModelSelectionResults perform_inputs_selection(void) const
Vector< double > calculate_inputs_importance(void) const
Calculate the importance of the inputs, returns a vector with the selection loss of the neural networ...
GoldenSectionOrder::GoldenSectionOrderResults * golden_section_order_results_pointer
Pointer to a structure with the results from the golden section order selection algorithm.
bool has_training_strategy(void) const
KappaCoefficientOptimizationThreshold * kappa_coefficient_optimization_threshold_pointer
Pointer to a kappa coefficient optimization object to be used in the threshold selection.
ModelSelectionResults perform_threshold_selection(void) const
IncrementalOrder * incremental_order_pointer
Pointer to a incremental order object to be used in the order selection.
PruningInputs * pruning_inputs_pointer
Pointer to a pruning inputs object to be used in the inputs selection.
ThresholdSelectionType
Enumeration of all the available types of threshold selection algorithms.
GrowingInputs::GrowingInputsResults * growing_inputs_results_pointer
Pointer to a structure with the results from the growing inputs selection algorithm.
ThresholdSelectionType threshold_selection_type
Type of threshold selection algorithm.
MatthewCorrelationOptimizationThreshold::MatthewCorrelationOptimizationThresholdResults * matthew_correlation_optimization_results_pointer
Pointer to a structure with the results from the matthew correlation optimization threshold selection...
GeneticAlgorithm::GeneticAlgorithmResults * genetic_algorithm_results_pointer
Pointer to a structure with the results from the genetic inputs selection algorithm.
InputsSelectionType inputs_selection_type
Type of inputs selection algorithm.
OrderSelectionType order_selection_type
Type of order selection algorithm.
GeneticAlgorithm * genetic_algorithm_pointer
Pointer to a genetic algorithm object to be used in the inputs selection.
GoldenSectionOrder * golden_section_order_pointer
Pointer to a golden section order object to be used in the order selection.
bool display
Display messages to screen.
F1ScoreOptimizationThreshold * get_f1_score_optimization_threshold_pointer(void) const
Returns a pointer to the f1 score optimiztion threshold selection algorithm.
void set_default(void)
Sets the members of the model selection object to their default values.
void load(const std::string &)
ROCCurveOptimizationThreshold * roc_curve_optimization_threshold_pointer
Pointer to a roc curve distance optimization object to be used in the threshold selection.
MatthewCorrelationOptimizationThreshold * matthew_correlation_optimization_threshold_pointer
Pointer to a matthew correlation optimization object to be used in the threshold selection.
PruningInputs::PruningInputsResults * pruning_inputs_results_pointer
Pointer to a structure with the results from the pruning inputs selection algorithm.
void set_inputs_selection_type(const InputsSelectionType &)
MatthewCorrelationOptimizationThreshold * get_matthew_correlation_optimization_threshold(void) const
Returns a pointer to the matthew correlation optimiztion threshold selection algorithm.
SimulatedAnnealingOrder::SimulatedAnnealingOrderResults * simulated_annealing_order_results_pointer
Pointer to a structure with the results from the simulated annealing order selection algorithm...
void destruct_order_selection(void)
This method deletes the order selection algorithm object which composes this model selection object...
OrderSelectionType
Enumeration of all the available types of order selection algorithms.
void check(void) const
Checks that the different pointers needed for performing the model selection are not NULL...
GoldenSectionOrder * get_golden_section_order_pointer(void) const
Returns a pointer to the golden section order selection algorithm.
TrainingStrategy * get_training_strategy_pointer(void) const
Returns a pointer to the training strategy object.
F1ScoreOptimizationThreshold * f1_score_optimization_threshold_pointer
Pointer to a f1 score optimization object to be used in the inputs selection.
YoudenIndexOptimizationThreshold * youden_index_optimization_threshold_pointer
Pointer to a youden index optimization object to be used in the threshold selection.
void print(void) const
Prints to the screen the XML representation of this model selection object.
GrowingInputs * get_growing_inputs_pointer(void) const
Returns a pointer to the growing inputs selection algorithm.
void set_training_strategy_pointer(TrainingStrategy *)
const OrderSelectionType & get_order_selection_type(void) const
Returns the type of algorithm for the order selection.
ModelSelectionResults perform_order_selection(void) const
ModelSelectionResults perform_model_selection(void) const
ModelSelection(void)
Default constructor.
void destruct_inputs_selection(void)
This method deletes the inputs selection algorithm object which composes this model selection object...
TrainingStrategy * training_strategy_pointer
Pointer to a training strategy object.
virtual ~ModelSelection(void)
Destructor.
PruningInputs * get_pruning_inputs_pointer(void) const
Returns a pointer to the pruning inputs selection algorithm.
SimulatedAnnealingOrder * simulated_annelaing_order_pointer
Pointer to a simulated annealing order object to be used in the order selection.
KappaCoefficientOptimizationThreshold::KappaCoefficientOptimizationThresholdResults * kappa_coefficient_optimization_results_pointer
Pointer to a structure with the results from the kappa coefficient optimization threshold selection a...
SimulatedAnnealingOrder * get_simulated_annealing_order_pointer(void) const
Returns a pointer to the simulated annealing order selection algorithm.
KappaCoefficientOptimizationThreshold * get_kappa_coefficient_optimization_threshold(void) const
Returns a pointer to the kappa coefficient optimiztion threshold selection algorithm.
YoudenIndexOptimizationThreshold * get_youden_index_optimization_threshold(void) const
Returns a pointer to the youden index optimiztion threshold selection algorithm.
void destruct_threshold_selection(void)
This method deletes the threshold selection algorithm object which composes this model selection obje...
ROCCurveOptimizationThreshold * get_roc_curve_optimization_threshold(void) const
Returns a pointer to the roc curve optimiztion threshold selection algorithm.
GrowingInputs * growing_inputs_pointer
Pointer to a growing inputs object to be used in the inputs selection.
F1ScoreOptimizationThreshold::F1ScoreOptimizationThresholdResults * f1_score_opimization_results_pointer
Pointer to a structure with the results from the f1 score optimization threshold selection algorithm...
void write_XML(tinyxml2::XMLPrinter &) const
IncrementalOrder::IncrementalOrderResults * incremental_order_results_pointer
Pointer to a structure with the results from the incremental order selection algorithm.
void set_threshold_selection_type(const ThresholdSelectionType &)
void set_order_selection_type(const OrderSelectionType &)
GeneticAlgorithm * get_genetic_algorithm_pointer(void) const
Returns a pointer to the genetic inputs selection algorithm.
ROCCurveOptimizationThreshold::ROCCurveOptimizationThresholdResults * roc_curve_optimization_results_pointer
Pointer to a structure with the results from the roc curve optimization threshold selection algorithm...
void set_display(const bool &)
YoudenIndexOptimizationThreshold::YoudenIndexOptimizationThresholdResults * youden_index_optimization_results_pointer
Pointer to a structure with the results from the youden index optimization threshold selection algori...
tinyxml2::XMLDocument * to_XML(void) const
void set_approximation(const bool &)