OpenNN  2.2
Open Neural Networks Library
model_selection.cpp
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 */
7 /* */
8 /* Fernando Gomez */
9 /* Artelnics - Making intelligent use of data */
10 /* fernandogomez@artelnics.com */
11 /* */
12 /****************************************************************************************************************/
13 
14 // OpenNN includes
15 
16 #include "model_selection.h"
17 
18 namespace OpenNN
19 {
20 
21 // DEFAULT CONSTRUCTOR
22 
24 
26  : training_strategy_pointer(NULL)
27  , incremental_order_pointer(NULL)
28  , golden_section_order_pointer(NULL)
29  , simulated_annelaing_order_pointer(NULL)
30  , growing_inputs_pointer(NULL)
31  , pruning_inputs_pointer(NULL)
32  , genetic_algorithm_pointer(NULL)
33  , f1_score_optimization_threshold_pointer(NULL)
34  , matthew_correlation_optimization_threshold_pointer(NULL)
35  , youden_index_optimization_threshold_pointer(NULL)
36  , kappa_coefficient_optimization_threshold_pointer(NULL)
37  , roc_curve_optimization_threshold_pointer(NULL)
38 {
39  set_default();
40 }
41 
42 
43 // TRAINING STRATEGY CONSTRUCTOR
44 
47 
48 ModelSelection::ModelSelection(TrainingStrategy* new_training_strategy_pointer)
49  : training_strategy_pointer(new_training_strategy_pointer)
61 {
62  set_default();
63 }
64 
65 
66 // FILE CONSTRUCTOR
67 
70 
71 ModelSelection::ModelSelection(const std::string& file_name)
84 {
85  load(file_name);
86 }
87 
88 
89 // XML CONSTRUCTOR
90 
93 
94 ModelSelection::ModelSelection(const tinyxml2::XMLDocument& model_selection_document)
100  , pruning_inputs_pointer(NULL)
107 {
108  from_XML(model_selection_document);
109 }
110 
111 
112 // DESTRUCTOR
113 
115 
117 {
118  // Delete inputs selection algorithms
119 
120  delete growing_inputs_pointer;
121  delete pruning_inputs_pointer;
123 
124  // Delete order selection algorithms
125 
129 
130  // Delete threshold selection algorithms
131 
137 }
138 
139 
140 // METHODS
141 
142 // TrainingStrategy* get_training_strategy_pointer(void) const method
143 
145 
147 {
148 #ifdef __OPENNN_DEBUG__
149 
151  {
152  std::ostringstream buffer;
153 
154  buffer << "OpenNN Exception: ModelSelection class.\n"
155  << "TrainingStrategy* get_training_strategy_pointer(void) const method.\n"
156  << "Training strategy pointer is NULL.\n";
157 
158  throw std::logic_error(buffer.str());
159  }
160 
161 #endif
162 
164 }
165 
166 // bool has_training_strategy(void) const method
167 
170 
172 {
174  {
175  return(true);
176  }
177  else
178  {
179  return(false);
180  }
181 }
182 
183 // const OrderSelectionType& get_order_selection_type(void) const method
184 
186 
188 {
189  return(order_selection_type);
190 }
191 
192 // const InputSelectionType& get_inputs_selection_type(void) const method
193 
195 
197 {
198  return(inputs_selection_type);
199 }
200 
201 // const ThresholdSelectionType& get_threshold_selection_type(void) const method
202 
204 
206 {
207  return(threshold_selection_type);
208 }
209 
210 // IncrementalOrder* get_incremental_order_pointer(void) const method
211 
213 
215 {
217 }
218 
219 // GoldenSectionOrder* get_golden_section_order_pointer(void) const method
220 
222 
224 {
226 }
227 
228 // SimulatedAnnealingOrder* get_simulated_annealing_order_pointer(void) const method
229 
231 
233 {
235 }
236 
237 // GrowingInputs* get_growing_inputs_pointer(void) const method
238 
240 
242 {
243  return(growing_inputs_pointer);
244 }
245 
246 // PruningInputs* get_pruning_inputs_pointer(void) const method
247 
249 
251 {
252  return(pruning_inputs_pointer);
253 }
254 
255 // GeneticAlgorithm* get_genetic_algorithm_pointer(void) const method
256 
258 
260 {
262 }
263 
264 // F1ScoreOptimizationThreshold* get_f1_score_optimization_threshold_pointer(void) const method
265 
267 
269 {
271 }
272 
273 // MatthewCorrelationOptimizationThreshold* get_matthew_correlation_optimization_threshold(void) const method
274 
276 
278 {
280 }
281 
282 // YoudenIndexOptimizationThreshold* get_youden_index_optimization_threshold(void) const method
283 
285 
287 {
289 }
290 
291 // KappaCoefficientOptimizationThreshold* get_kappa_coefficient_optimization_threshold(void) const method
292 
294 
296 {
298 }
299 
300 // ROCCurveOptimizationThreshold* get_roc_curve_optimization_threshold(void) const method
301 
303 
305 {
307 }
308 
309 // void set_default(void) method
310 
312 
314 {
315  set_order_selection_type(ModelSelection::INCREMENTAL_ORDER);
316  set_inputs_selection_type(ModelSelection::GROWING_INPUTS);
317  set_threshold_selection_type(ModelSelection::YOUDEN_INDEX);
318 
319  display = true;
320 }
321 
322 // void set_display(const bool&) method
323 
328 
329 void ModelSelection::set_display(const bool& new_display)
330 {
331  display = new_display;
332 
333  switch (inputs_selection_type)
334  {
335  case NO_INPUTS_SELECTION:
336  {
337  // do nothing
338 
339  break;
340  }
341  case GROWING_INPUTS:
342  {
343  growing_inputs_pointer->set_display(new_display);
344 
345  break;
346  }
347  case PRUNING_INPUTS:
348  {
349  pruning_inputs_pointer->set_display(new_display);
350 
351  break;
352  }
353  case GENETIC_ALGORITHM:
354  {
356 
357  break;
358  }
359  default:
360  {
361  break;
362  }
363  }
364 
365  switch (order_selection_type)
366  {
367  case NO_ORDER_SELECTION:
368  {
369  // do nothing
370 
371  break;
372  }
373  case INCREMENTAL_ORDER:
374  {
376 
377  break;
378  }
379  case GOLDEN_SECTION:
380  {
382 
383  break;
384  }
385  case SIMULATED_ANNEALING:
386  {
388 
389  break;
390  }
391  default:
392  {
393  break;
394  }
395  }
396 
397  switch (threshold_selection_type)
398  {
399  case NO_THRESHOLD_SELECTION:
400  {
401  // do nothing
402 
403  break;
404  }
405  case F1_SCORE_OPTIMIZATION:
406  {
408 
409  break;
410  }
411  case MATTHEW_CORRELATION:
412  {
414 
415  break;
416  }
417  case YOUDEN_INDEX:
418  {
420 
421  break;
422  }
423  case KAPPA_COEFFICIENT:
424  {
426 
427  break;
428  }
429  case ROC_CURVE_DISTANCE:
430  {
432 
433  break;
434  }
435  default:
436  {
437  break;
438  }
439  }
440 }
441 
442 // void set_order_selection_type(const OrderSelectionType&) method
443 
446 
448 {
450 
451  order_selection_type = new_order_selection_type;
452 
453  switch (new_order_selection_type)
454  {
455  case NO_ORDER_SELECTION:
456  {
457  // do nothing
458 
459  break;
460  }
461  case INCREMENTAL_ORDER:
462  {
464 
465  break;
466  }
467  case GOLDEN_SECTION:
468  {
470 
471  break;
472  }
473  case SIMULATED_ANNEALING:
474  {
476 
477  break;
478  }
479  default:
480  {
481  std::ostringstream buffer;
482 
483  buffer << "OpenNN Exception: ModelSelection class.\n"
484  << "void set_order_selection_method(const OrderSelectionType&) const method.\n"
485  << "Unknow order selection method.\n";
486 
487  throw std::logic_error(buffer.str());
488 
489  break;
490  }
491  }
492 
493 
494 }
495 
496 // void set_order_selection_type(const std::string&) method
497 
500 
501 void ModelSelection::set_order_selection_type(const std::string& new_order_selection_type)
502 {
503  if(new_order_selection_type == "NO_ORDER_SELECTION")
504  {
505  set_order_selection_type(NO_ORDER_SELECTION);
506  }
507  else if(new_order_selection_type == "INCREMENTAL_ORDER")
508  {
509  set_order_selection_type(INCREMENTAL_ORDER);
510  }
511  else if(new_order_selection_type == "GOLDEN_SECTION")
512  {
513  set_order_selection_type(GOLDEN_SECTION);
514  }
515  else if(new_order_selection_type == "SIMULATED_ANNEALING")
516  {
517  set_order_selection_type(SIMULATED_ANNEALING);
518  }
519  else
520  {
521  std::ostringstream buffer;
522 
523  buffer << "OpenNN Exception: ModelSelection class.\n"
524  << "void set_order_selection_type(const std::string&) method.\n"
525  << "Unknown order selection type: " << new_order_selection_type << ".\n";
526 
527  throw std::logic_error(buffer.str());
528  }
529 }
530 
531 // void set_inputs_selection_type(const InputSelectionType&) method
532 
535 
537 {
539 
540  inputs_selection_type = new_inputs_selection_type;
541 
542  switch (new_inputs_selection_type)
543  {
544  case NO_INPUTS_SELECTION:
545  {
546  // do nothing
547 
548  break;
549  }
550  case GROWING_INPUTS:
551  {
553 
554  break;
555  }
556  case PRUNING_INPUTS:
557  {
559 
560  break;
561  }
562  case GENETIC_ALGORITHM:
563  {
565 
566  break;
567  }
568  default:
569  {
570  std::ostringstream buffer;
571 
572  buffer << "OpenNN Exception: ModelSelection class.\n"
573  << "void set_inputs_selection_method(const InputsSelectionType&) const method.\n"
574  << "Unknow inputs selection method.\n";
575 
576  throw std::logic_error(buffer.str());
577 
578  break;
579  }
580  }
581 }
582 
583 // void set_inputs_selection_type(const std::string&) method
584 
587 
588 void ModelSelection::set_inputs_selection_type(const std::string& new_inputs_selection_type)
589 {
590  if(new_inputs_selection_type == "NO_INPUTS_SELECTION")
591  {
592  set_inputs_selection_type(NO_INPUTS_SELECTION);
593  }
594  else if(new_inputs_selection_type == "GROWING_INPUTS")
595  {
596  set_inputs_selection_type(GROWING_INPUTS);
597  }
598  else if(new_inputs_selection_type == "PRUNING_INPUTS")
599  {
600  set_inputs_selection_type(PRUNING_INPUTS);
601  }
602  else if(new_inputs_selection_type == "GENETIC_ALGORITHM")
603  {
604  set_inputs_selection_type(GENETIC_ALGORITHM);
605  }
606  else
607  {
608  std::ostringstream buffer;
609 
610  buffer << "OpenNN Exception: ModelSelection class.\n"
611  << "void set_inputs_selection_type(const std::string&) method.\n"
612  << "Unknown inputs selection type: " << new_inputs_selection_type << ".\n";
613 
614  throw std::logic_error(buffer.str());
615  }
616 }
617 
618 // void set_threshold_selection_type(const ThresholdSelectionType&) method
619 
622 
624 {
626 
627  threshold_selection_type = new_threshold_selection_type;
628 
629  switch (new_threshold_selection_type)
630  {
631  case NO_THRESHOLD_SELECTION:
632  {
633  // do nothing
634 
635  break;
636  }
637  case F1_SCORE_OPTIMIZATION:
638  {
640 
641  break;
642  }
643  case MATTHEW_CORRELATION:
644  {
646 
647  break;
648  }
649  case YOUDEN_INDEX:
650  {
652 
653  break;
654  }
655  case KAPPA_COEFFICIENT:
656  {
658 
659  break;
660  }
661  case ROC_CURVE_DISTANCE:
662  {
664 
665  break;
666  }
667  default:
668  {
669  std::ostringstream buffer;
670 
671  buffer << "OpenNN Exception: ModelSelection class.\n"
672  << "void set_threshold_selection_method(const ThresholdSelectionType&) const method.\n"
673  << "Unknow threshold selection method.\n";
674 
675  throw std::logic_error(buffer.str());
676 
677  break;
678  }
679  }
680 }
681 
682 // void set_threshold_selection_type(const std::string&) method
683 
686 
687 void ModelSelection::set_threshold_selection_type(const std::string& new_threshold_selection_type)
688 {
689  if(new_threshold_selection_type == "NO_THRESHOLD_SELECTION")
690  {
691  set_threshold_selection_type(NO_THRESHOLD_SELECTION);
692  }
693  else if(new_threshold_selection_type == "F1_SCORE_OPTIMIZATION")
694  {
695  set_threshold_selection_type(F1_SCORE_OPTIMIZATION);
696  }
697  else if(new_threshold_selection_type == "MATTHEW_CORRELATION")
698  {
699  set_threshold_selection_type(MATTHEW_CORRELATION);
700  }
701  else if(new_threshold_selection_type == "YOUDEN_INDEX")
702  {
703  set_threshold_selection_type(YOUDEN_INDEX);
704  }
705  else if(new_threshold_selection_type == "KAPPA_COEFFICIENT")
706  {
707  set_threshold_selection_type(KAPPA_COEFFICIENT);
708  }
709  else if(new_threshold_selection_type == "ROC_CURVE_DISTANCE")
710  {
711  set_threshold_selection_type(ROC_CURVE_DISTANCE);
712  }
713  else
714  {
715  std::ostringstream buffer;
716 
717  buffer << "OpenNN Exception: ModelSelection class.\n"
718  << "void set_threshold_selection_type(const std::string&) method.\n"
719  << "Unknown threshold selection type: " << new_threshold_selection_type << ".\n";
720 
721  throw std::logic_error(buffer.str());
722  }
723 }
724 
725 // void set_approximation(const bool&) method
726 
731 
732 void ModelSelection::set_approximation(const bool& new_approximation)
733 {
734  switch (inputs_selection_type)
735  {
736  case NO_INPUTS_SELECTION:
737  {
738  // do nothing
739 
740  break;
741  }
742  case GROWING_INPUTS:
743  {
744  growing_inputs_pointer->set_approximation(new_approximation);
745 
746  break;
747  }
748  case PRUNING_INPUTS:
749  {
750  pruning_inputs_pointer->set_approximation(new_approximation);
751 
752  break;
753  }
754  case GENETIC_ALGORITHM:
755  {
756  genetic_algorithm_pointer->set_approximation(new_approximation);
757 
758  break;
759  }
760  default:
761  {
762  std::ostringstream buffer;
763 
764  buffer << "OpenNN Exception: ModelSelection class.\n"
765  << "void set_approximation(const bool&) const method.\n"
766  << "Unknow inputs selection method.\n";
767 
768  throw std::logic_error(buffer.str());
769 
770  break;
771  }
772  }
773 }
774 
775 // void set_training_strategy_pointer(TrainingStrategy*) method
776 
779 
781 {
782  training_strategy_pointer = new_training_strategy_pointer;
783 
784  switch(order_selection_type)
785  {
786  case NO_ORDER_SELECTION:
787  {
788  // do nothing
789 
790  break;
791  }
792  case INCREMENTAL_ORDER:
793  {
794  incremental_order_pointer->set_training_strategy_pointer(new_training_strategy_pointer);
795  break;
796  }
797  case GOLDEN_SECTION:
798  {
799  golden_section_order_pointer->set_training_strategy_pointer(new_training_strategy_pointer);
800  break;
801  }
802  case SIMULATED_ANNEALING:
803  {
805  break;
806  }
807  default:
808  {
809  std::ostringstream buffer;
810 
811  buffer << "OpenNN Exception: ModelSelection class.\n"
812  << "void set_training_strategy_pointer(TrainingStrategy*) method.\n"
813  << "Unknown order selection type.\n";
814 
815  throw std::logic_error(buffer.str());
816  }
817  }
818 
819  switch(inputs_selection_type)
820  {
821  case NO_ORDER_SELECTION:
822  {
823  // do nothing
824 
825  break;
826  }
827  case GROWING_INPUTS:
828  {
829  growing_inputs_pointer->set_training_strategy_pointer(new_training_strategy_pointer);
830  break;
831  }
832  case PRUNING_INPUTS:
833  {
834  pruning_inputs_pointer->set_training_strategy_pointer(new_training_strategy_pointer);
835  break;
836  }
837  case GENETIC_ALGORITHM:
838  {
839  genetic_algorithm_pointer->set_training_strategy_pointer(new_training_strategy_pointer);
840  break;
841  }
842  default:
843  {
844  std::ostringstream buffer;
845 
846  buffer << "OpenNN Exception: ModelSelection class.\n"
847  << "void set_training_strategy_pointer(TrainingStrategy*) method.\n"
848  << "Unknown inputs selection type.\n";
849 
850  throw std::logic_error(buffer.str());
851  }
852  }
853 
855  {
856  case NO_THRESHOLD_SELECTION:
857  {
858  // do nothing
859 
860  break;
861  }
862  case F1_SCORE_OPTIMIZATION:
863  {
865  break;
866  }
867  case MATTHEW_CORRELATION:
868  {
870  break;
871  }
872  case YOUDEN_INDEX:
873  {
875  break;
876  }
877  case KAPPA_COEFFICIENT:
878  {
880  break;
881  }
882  case ROC_CURVE_DISTANCE:
883  {
885  break;
886  }
887  default:
888  {
889  std::ostringstream buffer;
890 
891  buffer << "OpenNN Exception: ModelSelection class.\n"
892  << "void set_training_strategy_pointer(TrainingStrategy*) method.\n"
893  << "Unknown threshold selection type.\n";
894 
895  throw std::logic_error(buffer.str());
896  }
897  }
898 }
899 
900 #ifdef __OPENNN_MPI__
901 
902 void ModelSelection::set_MPI(TrainingStrategy* new_training_strategy, const ModelSelection* model_selection)
903 {
904 
905  set_training_strategy_pointer(new_training_strategy);
906 
907  // Inputs selection
908 
909  set_inputs_selection_MPI(model_selection);
910 
911  // Order Selection
912 
913  set_order_selection_MPI(model_selection);
914 
915  // Threshold selection
916 
917  set_threshold_selection_MPI(model_selection);
918 
919  int rank;
920  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
921 
922  if(rank != 0)
923  {
924  set_display(false);
925  }
926 }
927 
928 void ModelSelection::set_inputs_selection_MPI(const ModelSelection* model_selection)
929 {
930 
931  int size;
932  MPI_Comm_size(MPI_COMM_WORLD, &size);
933 
934  int rank;
935  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
936 
937  int original_inputs_selection_type;
938 
939  // Growing/Pruning inputs parameters
940 
941  int maximum_selection_failures;
942  int max_min_inputs_number;
943  double minimum_correlation;
944  double maximum_correlation;
945 
946  // Genetic algorithm parameters
947 
948  int population_size;
949  int initialization_method;
950  int fitness_assignment_method;
951  int crossover_method;
952  int elitism_size;
953  double selective_pressure;
954  double mutation_rate;
955  int reserve_generation_mean_history;
956  int reserve_generation_standard_deviation_history;
957 
958  // General parameters
959 
960  int trials_number;
961  double tolerance;
962  double selection_loss_goal;
963  int maximum_iterations_number;
964  int maximum_time;
965  int reserve_loss_loss_history;
966  int reserve_selection_loss_loss_history;
967 
968  if(rank == 0)
969  {
970  // Variables to send initialization
971 
972  original_inputs_selection_type = (int)model_selection->get_inputs_selection_type();
973 
974  switch (original_inputs_selection_type)
975  {
976  case (int)ModelSelection::GROWING_INPUTS:
977  {
978  GrowingInputs* original_growing_inputs = model_selection->get_growing_inputs_pointer();
979 
980  trials_number = (int)original_growing_inputs->get_trials_number();
981  tolerance = original_growing_inputs->get_tolerance();
982  selection_loss_goal = original_growing_inputs->get_selection_loss_goal();
983  maximum_selection_failures = (int)original_growing_inputs->get_maximum_selection_failures();
984  max_min_inputs_number = (int)original_growing_inputs->get_maximum_inputs_number();
985  minimum_correlation = original_growing_inputs->get_minimum_correlation();
986  maximum_correlation = original_growing_inputs->get_maximum_correlation();
987  maximum_iterations_number = (int)original_growing_inputs->get_maximum_iterations_number();
988  maximum_time = (int)original_growing_inputs->get_maximum_time();
989  reserve_loss_loss_history = original_growing_inputs->get_reserve_loss_data();
990  reserve_selection_loss_loss_history = original_growing_inputs->get_reserve_selection_loss_data();
991  }
992  break;
993 
994  case (int)ModelSelection::PRUNING_INPUTS:
995  {
996  PruningInputs* original_pruning_inputs = model_selection->get_pruning_inputs_pointer();
997 
998  trials_number = (int)original_pruning_inputs->get_trials_number();
999  tolerance = original_pruning_inputs->get_tolerance();
1000  selection_loss_goal = original_pruning_inputs->get_selection_loss_goal();
1001  maximum_selection_failures = (int)original_pruning_inputs->get_maximum_selection_failures();
1002  max_min_inputs_number = (int)original_pruning_inputs->get_minimum_inputs_number();
1003  minimum_correlation = original_pruning_inputs->get_minimum_correlation();
1004  maximum_correlation = original_pruning_inputs->get_maximum_correlation();
1005  maximum_iterations_number = (int)original_pruning_inputs->get_maximum_iterations_number();
1006  maximum_time = (int)original_pruning_inputs->get_maximum_time();
1007  reserve_loss_loss_history = original_pruning_inputs->get_reserve_loss_data();
1008  reserve_selection_loss_loss_history = original_pruning_inputs->get_reserve_selection_loss_data();
1009  }
1010  break;
1011 
1012  case (int)ModelSelection::GENETIC_ALGORITHM:
1013  {
1014  GeneticAlgorithm* original_genetic_algorithm = model_selection->get_genetic_algorithm_pointer();
1015 
1016  trials_number = (int)original_genetic_algorithm->get_trials_number();
1017  tolerance = original_genetic_algorithm->get_tolerance();
1018  population_size = (int)original_genetic_algorithm->get_population_size();
1019  initialization_method = original_genetic_algorithm->get_initialization_method();
1020  fitness_assignment_method = original_genetic_algorithm->get_fitness_assignment_method();
1021  crossover_method = original_genetic_algorithm->get_crossover_method();
1022  elitism_size = (int)original_genetic_algorithm->get_elitism_size();
1023  selective_pressure = original_genetic_algorithm->get_selective_pressure();
1024  mutation_rate = original_genetic_algorithm->get_mutation_rate();
1025  selection_loss_goal = original_genetic_algorithm->get_selection_loss_goal();
1026  maximum_iterations_number = (int)original_genetic_algorithm->get_maximum_iterations_number();
1027  maximum_time = (int)original_genetic_algorithm->get_maximum_time();
1028  reserve_loss_loss_history = original_genetic_algorithm->get_reserve_loss_data();
1029  reserve_selection_loss_loss_history = original_genetic_algorithm->get_reserve_selection_loss_data();
1030  reserve_generation_mean_history = original_genetic_algorithm->get_reserve_generation_mean();
1031  reserve_generation_standard_deviation_history = original_genetic_algorithm->get_reserve_generation_standard_deviation();
1032  }
1033  break;
1034 
1035  default:
1036  break;
1037  }
1038  }
1039 
1040  // Send variables
1041 
1042  MPI_Barrier(MPI_COMM_WORLD);
1043 
1044  if(rank > 0)
1045  {
1046  MPI_Recv(&original_inputs_selection_type, 1, MPI_INT, rank-1, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
1047 
1048  MPI_Request req[9];
1049 
1050  switch (original_inputs_selection_type)
1051  {
1052  case (int)ModelSelection::GROWING_INPUTS:
1053 
1054  MPI_Irecv(&maximum_selection_failures, 1, MPI_INT, rank-1, 1, MPI_COMM_WORLD, &req[0]);
1055  MPI_Irecv(&max_min_inputs_number, 1, MPI_INT, rank-1, 2, MPI_COMM_WORLD, &req[1]);
1056  MPI_Irecv(&minimum_correlation, 1, MPI_DOUBLE, rank-1, 3, MPI_COMM_WORLD, &req[2]);
1057  MPI_Irecv(&maximum_correlation, 1, MPI_DOUBLE, rank-1, 4, MPI_COMM_WORLD, &req[3]);
1058 
1059  MPI_Waitall(4, req, MPI_STATUS_IGNORE);
1060 
1061  break;
1062 
1063  case (int)ModelSelection::PRUNING_INPUTS:
1064 
1065  MPI_Irecv(&maximum_selection_failures, 1, MPI_INT, rank-1, 1, MPI_COMM_WORLD, &req[0]);
1066  MPI_Irecv(&max_min_inputs_number, 1, MPI_INT, rank-1, 2, MPI_COMM_WORLD, &req[1]);
1067  MPI_Irecv(&minimum_correlation, 1, MPI_DOUBLE, rank-1, 3, MPI_COMM_WORLD, &req[2]);
1068  MPI_Irecv(&maximum_correlation, 1, MPI_DOUBLE, rank-1, 4, MPI_COMM_WORLD, &req[3]);
1069 
1070  MPI_Waitall(4, req, MPI_STATUS_IGNORE);
1071 
1072  break;
1073 
1074  case (int)ModelSelection::GENETIC_ALGORITHM:
1075 
1076  MPI_Irecv(&population_size, 1, MPI_INT, rank-1, 1, MPI_COMM_WORLD, &req[0]);
1077  MPI_Irecv(&initialization_method, 1, MPI_INT, rank-1, 2, MPI_COMM_WORLD, &req[1]);
1078  MPI_Irecv(&fitness_assignment_method, 1, MPI_INT, rank-1, 3, MPI_COMM_WORLD, &req[2]);
1079  MPI_Irecv(&crossover_method, 1, MPI_INT, rank-1, 4, MPI_COMM_WORLD, &req[3]);
1080  MPI_Irecv(&elitism_size, 1, MPI_INT, rank-1, 5, MPI_COMM_WORLD, &req[4]);
1081  MPI_Irecv(&selective_pressure, 1, MPI_DOUBLE, rank-1, 6, MPI_COMM_WORLD, &req[5]);
1082  MPI_Irecv(&mutation_rate, 1, MPI_DOUBLE, rank-1, 7, MPI_COMM_WORLD, &req[6]);
1083  MPI_Irecv(&reserve_generation_mean_history, 1, MPI_INT, rank-1, 8, MPI_COMM_WORLD, &req[7]);
1084  MPI_Irecv(&reserve_generation_standard_deviation_history, 1, MPI_INT, rank-1, 9, MPI_COMM_WORLD, &req[8]);
1085 
1086  MPI_Waitall(9, req, MPI_STATUS_IGNORE);
1087 
1088  break;
1089 
1090  default:
1091  break;
1092  }
1093 
1094  MPI_Irecv(&trials_number, 1, MPI_INT, rank-1, 10, MPI_COMM_WORLD, &req[0]);
1095  MPI_Irecv(&tolerance, 1, MPI_DOUBLE, rank-1, 11, MPI_COMM_WORLD, &req[1]);
1096  MPI_Irecv(&selection_loss_goal, 1, MPI_DOUBLE, rank-1, 12, MPI_COMM_WORLD, &req[2]);
1097  MPI_Irecv(&maximum_iterations_number, 1, MPI_INT, rank-1, 13, MPI_COMM_WORLD, &req[3]);
1098  MPI_Irecv(&maximum_time, 1, MPI_INT, rank-1, 14, MPI_COMM_WORLD, &req[4]);
1099  MPI_Irecv(&reserve_loss_loss_history, 1, MPI_INT, rank-1, 15, MPI_COMM_WORLD, &req[5]);
1100  MPI_Irecv(&reserve_selection_loss_loss_history, 1, MPI_INT, rank-1, 16, MPI_COMM_WORLD, &req[6]);
1101 
1102  MPI_Waitall(7, req, MPI_STATUS_IGNORE);
1103  }
1104 
1105  if(rank < size-1)
1106  {
1107  MPI_Send(&original_inputs_selection_type, 1, MPI_INT, rank+1, 1, MPI_COMM_WORLD);
1108 
1109  MPI_Request req[9];
1110 
1111  switch (original_inputs_selection_type)
1112  {
1113  case (int)ModelSelection::GROWING_INPUTS:
1114 
1115  MPI_Isend(&maximum_selection_failures, 1, MPI_INT, rank+1, 1, MPI_COMM_WORLD, &req[0]);
1116  MPI_Isend(&max_min_inputs_number, 1, MPI_INT, rank+1, 2, MPI_COMM_WORLD, &req[1]);
1117  MPI_Isend(&minimum_correlation, 1, MPI_DOUBLE, rank+1, 3, MPI_COMM_WORLD, &req[2]);
1118  MPI_Isend(&maximum_correlation, 1, MPI_DOUBLE, rank+1, 4, MPI_COMM_WORLD, &req[3]);
1119 
1120  MPI_Waitall(4, req, MPI_STATUS_IGNORE);
1121 
1122  break;
1123 
1124  case (int)ModelSelection::PRUNING_INPUTS:
1125 
1126  MPI_Isend(&maximum_selection_failures, 1, MPI_INT, rank+1, 1, MPI_COMM_WORLD, &req[0]);
1127  MPI_Isend(&max_min_inputs_number, 1, MPI_INT, rank+1, 2, MPI_COMM_WORLD, &req[1]);
1128  MPI_Isend(&minimum_correlation, 1, MPI_DOUBLE, rank+1, 3, MPI_COMM_WORLD, &req[2]);
1129  MPI_Isend(&maximum_correlation, 1, MPI_DOUBLE, rank+1, 4, MPI_COMM_WORLD, &req[3]);
1130 
1131  MPI_Waitall(4, req, MPI_STATUS_IGNORE);
1132 
1133  break;
1134 
1135  case (int)ModelSelection::GENETIC_ALGORITHM:
1136 
1137  MPI_Isend(&population_size, 1, MPI_INT, rank+1, 1, MPI_COMM_WORLD, &req[0]);
1138  MPI_Isend(&initialization_method, 1, MPI_INT, rank+1, 2, MPI_COMM_WORLD, &req[1]);
1139  MPI_Isend(&fitness_assignment_method, 1, MPI_INT, rank+1, 3, MPI_COMM_WORLD, &req[2]);
1140  MPI_Isend(&crossover_method, 1, MPI_INT, rank+1, 4, MPI_COMM_WORLD, &req[3]);
1141  MPI_Isend(&elitism_size, 1, MPI_INT, rank+1, 5, MPI_COMM_WORLD, &req[4]);
1142  MPI_Isend(&selective_pressure, 1, MPI_DOUBLE, rank+1, 6, MPI_COMM_WORLD, &req[5]);
1143  MPI_Isend(&mutation_rate, 1, MPI_DOUBLE, rank+1, 7, MPI_COMM_WORLD, &req[6]);
1144  MPI_Isend(&reserve_generation_mean_history, 1, MPI_INT, rank+1, 8, MPI_COMM_WORLD, &req[7]);
1145  MPI_Isend(&reserve_generation_standard_deviation_history, 1, MPI_INT, rank+1, 9, MPI_COMM_WORLD, &req[8]);
1146 
1147  MPI_Waitall(9, req, MPI_STATUS_IGNORE);
1148 
1149  break;
1150 
1151  default:
1152  break;
1153  }
1154 
1155  MPI_Isend(&trials_number, 1, MPI_INT, rank+1, 10, MPI_COMM_WORLD, &req[0]);
1156  MPI_Isend(&tolerance, 1, MPI_DOUBLE, rank+1, 11, MPI_COMM_WORLD, &req[1]);
1157  MPI_Isend(&selection_loss_goal, 1, MPI_DOUBLE, rank+1, 12, MPI_COMM_WORLD, &req[2]);
1158  MPI_Isend(&maximum_iterations_number, 1, MPI_INT, rank+1, 13, MPI_COMM_WORLD, &req[3]);
1159  MPI_Isend(&maximum_time, 1, MPI_INT, rank+1, 14, MPI_COMM_WORLD, &req[4]);
1160  MPI_Isend(&reserve_loss_loss_history, 1, MPI_INT, rank+1, 15, MPI_COMM_WORLD, &req[5]);
1161  MPI_Isend(&reserve_selection_loss_loss_history, 1, MPI_INT, rank+1, 16, MPI_COMM_WORLD, &req[6]);
1162 
1163  MPI_Waitall(7, req, MPI_STATUS_IGNORE);
1164  }
1165 
1166  MPI_Barrier(MPI_COMM_WORLD);
1167 
1168  // Set variables
1169 
1170  set_inputs_selection_type((ModelSelection::InputsSelectionType)original_inputs_selection_type);
1171 
1172  switch (original_inputs_selection_type)
1173  {
1174  case (int)ModelSelection::GROWING_INPUTS:
1175  {
1176  growing_inputs_pointer->set_trials_number(trials_number);
1178  growing_inputs_pointer->set_selection_loss_goal(selection_loss_goal);
1179  growing_inputs_pointer->set_maximum_selection_failures(maximum_selection_failures);
1180  growing_inputs_pointer->set_maximum_inputs_number(max_min_inputs_number);
1181  growing_inputs_pointer->set_minimum_correlation(minimum_correlation);
1182  growing_inputs_pointer->set_maximum_correlation(maximum_correlation);
1183  growing_inputs_pointer->set_maximum_iterations_number(maximum_iterations_number);
1185  growing_inputs_pointer->set_reserve_loss_data(reserve_loss_loss_history == 1);
1186  growing_inputs_pointer->set_reserve_selection_loss_data(reserve_selection_loss_loss_history == 1);
1187  }
1188  break;
1189 
1190  case (int)ModelSelection::PRUNING_INPUTS:
1191  {
1192  pruning_inputs_pointer->set_trials_number(trials_number);
1194  pruning_inputs_pointer->set_selection_loss_goal(selection_loss_goal);
1195  pruning_inputs_pointer->set_maximum_selection_failures(maximum_selection_failures);
1196  pruning_inputs_pointer->set_minimum_inputs_number(max_min_inputs_number);
1197  pruning_inputs_pointer->set_minimum_correlation(minimum_correlation);
1198  pruning_inputs_pointer->set_maximum_correlation(maximum_correlation);
1199  pruning_inputs_pointer->set_maximum_iterations_number(maximum_iterations_number);
1201  pruning_inputs_pointer->set_reserve_loss_data(reserve_loss_loss_history == 1);
1202  pruning_inputs_pointer->set_reserve_selection_loss_data(reserve_selection_loss_loss_history == 1);
1203  }
1204  break;
1205 
1206  case (int)ModelSelection::GENETIC_ALGORITHM:
1207  {
1217  genetic_algorithm_pointer->set_selection_loss_goal(selection_loss_goal);
1218  genetic_algorithm_pointer->set_maximum_iterations_number(maximum_iterations_number);
1220  genetic_algorithm_pointer->set_reserve_loss_data(reserve_loss_loss_history == 1);
1221  genetic_algorithm_pointer->set_reserve_selection_loss_data(reserve_selection_loss_loss_history == 1);
1222  genetic_algorithm_pointer->set_reserve_generation_mean(reserve_generation_mean_history == 1);
1223  genetic_algorithm_pointer->set_reserve_generation_standard_deviation(reserve_generation_standard_deviation_history == 1);
1224  }
1225  break;
1226 
1227  default:
1228  break;
1229  }
1230 }
1231 
1232 void ModelSelection::set_order_selection_MPI(const ModelSelection* model_selection)
1233 {
1234  int size;
1235  MPI_Comm_size(MPI_COMM_WORLD, &size);
1236 
1237  int rank;
1238  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
1239 
1240  int original_order_selection_type;
1241 
1242  // Incremental order parameters
1243 
1244  int step;
1245  int maximum_selection_failures;
1246 
1247  // Simulated annealing parameters
1248 
1249  double cooling_rate;
1250  double minimum_temperature;
1251  int maximum_iterations_number;
1252 
1253  // General parameters
1254 
1255  int minimum_order;
1256  int maximum_order;
1257  int trials_number;
1258  double tolerance;
1259  double selection_loss_goal;
1260  int maximum_time;
1261  int reserve_loss_loss_history;
1262  int reserve_selection_loss_loss_history;
1263 
1264  if(rank == 0)
1265  {
1266  // Variables to send initialization
1267 
1268  original_order_selection_type = (int)model_selection->get_order_selection_type();
1269 
1270  switch (original_order_selection_type)
1271  {
1272  case (int)ModelSelection::INCREMENTAL_ORDER:
1273  {
1274  IncrementalOrder* original_incremental_order = model_selection->get_incremental_order_pointer();
1275 
1276  minimum_order = (int)original_incremental_order->get_minimum_order();
1277  maximum_order = (int)original_incremental_order->get_maximum_order();
1278  step = (int)original_incremental_order->get_step();
1279  trials_number = (int)original_incremental_order->get_trials_number();
1280  tolerance = original_incremental_order->get_tolerance();
1281  selection_loss_goal = original_incremental_order->get_selection_loss_goal();
1282  maximum_selection_failures = (int)original_incremental_order->get_maximum_selection_failures();
1283  maximum_time = (int)original_incremental_order->get_maximum_time();
1284  reserve_loss_loss_history = original_incremental_order->get_reserve_loss_data();
1285  reserve_selection_loss_loss_history = original_incremental_order->get_reserve_selection_loss_data();
1286  }
1287  break;
1288 
1289  case (int)ModelSelection::GOLDEN_SECTION:
1290  {
1291  GoldenSectionOrder* original_golden_section_order = model_selection->get_golden_section_order_pointer();
1292 
1293  minimum_order = (int)original_golden_section_order->get_minimum_order();
1294  maximum_order = (int)original_golden_section_order->get_maximum_order();
1295  trials_number = (int)original_golden_section_order->get_trials_number();
1296  tolerance = original_golden_section_order->get_tolerance();
1297  selection_loss_goal = original_golden_section_order->get_selection_loss_goal();
1298  maximum_time = (int)original_golden_section_order->get_maximum_time();
1299  reserve_loss_loss_history = original_golden_section_order->get_reserve_loss_data();
1300  reserve_selection_loss_loss_history = original_golden_section_order->get_reserve_selection_loss_data();
1301  }
1302  break;
1303 
1304  case (int)ModelSelection::SIMULATED_ANNEALING:
1305  {
1306  SimulatedAnnealingOrder* original_simulated_annealing = model_selection->get_simulated_annealing_order_pointer();
1307 
1308  minimum_order = (int)original_simulated_annealing->get_minimum_order();
1309  maximum_order = (int)original_simulated_annealing->get_maximum_order();
1310  cooling_rate = original_simulated_annealing->get_cooling_rate();
1311  trials_number = (int)original_simulated_annealing->get_trials_number();
1312  tolerance = original_simulated_annealing->get_tolerance();
1313  selection_loss_goal = original_simulated_annealing->get_selection_loss_goal();
1314  minimum_temperature = original_simulated_annealing->get_minimum_temperature();
1315  maximum_iterations_number = (int)original_simulated_annealing->get_maximum_iterations_number();
1316  maximum_time = (int)original_simulated_annealing->get_maximum_time();
1317  reserve_loss_loss_history = original_simulated_annealing->get_reserve_loss_data();
1318  reserve_selection_loss_loss_history = original_simulated_annealing->get_reserve_selection_loss_data();
1319  }
1320  break;
1321 
1322  default:
1323  break;
1324  }
1325  }
1326 
1327  // Send variables
1328 
1329  MPI_Barrier(MPI_COMM_WORLD);
1330 
1331  if(rank > 0)
1332  {
1333  MPI_Recv(&original_order_selection_type, 1, MPI_INT, rank-1, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
1334 
1335  MPI_Request req[8];
1336 
1337  switch (original_order_selection_type)
1338  {
1339  case (int)ModelSelection::INCREMENTAL_ORDER:
1340 
1341  MPI_Irecv(&step, 1, MPI_INT, rank-1, 1, MPI_COMM_WORLD, &req[0]);
1342  MPI_Irecv(&maximum_selection_failures, 1, MPI_INT, rank-1, 2, MPI_COMM_WORLD, &req[1]);
1343 
1344  MPI_Waitall(2, req, MPI_STATUS_IGNORE);
1345 
1346  break;
1347 
1348  case (int)ModelSelection::SIMULATED_ANNEALING:
1349 
1350  MPI_Irecv(&cooling_rate, 1, MPI_DOUBLE, rank-1, 1, MPI_COMM_WORLD, &req[0]);
1351  MPI_Irecv(&minimum_temperature, 1, MPI_DOUBLE, rank-1, 2, MPI_COMM_WORLD, &req[1]);
1352  MPI_Irecv(&maximum_iterations_number, 1, MPI_INT, rank-1, 3, MPI_COMM_WORLD, &req[2]);
1353 
1354  MPI_Waitall(3, req, MPI_STATUS_IGNORE);
1355 
1356  break;
1357 
1358  default:
1359  break;
1360  }
1361 
1362  MPI_Irecv(&minimum_order, 1, MPI_INT, rank-1, 4, MPI_COMM_WORLD, &req[0]);
1363  MPI_Irecv(&maximum_order, 1, MPI_INT, rank-1, 5, MPI_COMM_WORLD, &req[1]);
1364  MPI_Irecv(&trials_number, 1, MPI_INT, rank-1, 6, MPI_COMM_WORLD, &req[2]);
1365  MPI_Irecv(&tolerance, 1, MPI_DOUBLE, rank-1, 7, MPI_COMM_WORLD, &req[3]);
1366  MPI_Irecv(&selection_loss_goal, 1, MPI_DOUBLE, rank-1, 8, MPI_COMM_WORLD, &req[4]);
1367  MPI_Irecv(&maximum_time, 1, MPI_INT, rank-1, 9, MPI_COMM_WORLD, &req[5]);
1368  MPI_Irecv(&reserve_loss_loss_history, 1, MPI_INT, rank-1, 10, MPI_COMM_WORLD, &req[6]);
1369  MPI_Irecv(&reserve_selection_loss_loss_history, 1, MPI_INT, rank-1, 11, MPI_COMM_WORLD, &req[7]);
1370 
1371  MPI_Waitall(8, req, MPI_STATUS_IGNORE);
1372  }
1373 
1374  if(rank < size-1)
1375  {
1376  MPI_Send(&original_order_selection_type, 1, MPI_INT, rank+1, 1, MPI_COMM_WORLD);
1377 
1378  MPI_Request req[8];
1379 
1380  switch (original_order_selection_type)
1381  {
1382  case (int)ModelSelection::INCREMENTAL_ORDER:
1383 
1384  MPI_Isend(&step, 1, MPI_INT, rank+1, 1, MPI_COMM_WORLD, &req[0]);
1385  MPI_Isend(&maximum_selection_failures, 1, MPI_INT, rank+1, 2, MPI_COMM_WORLD, &req[1]);
1386 
1387  MPI_Waitall(2, req, MPI_STATUS_IGNORE);
1388 
1389  break;
1390 
1391  case (int)ModelSelection::SIMULATED_ANNEALING:
1392 
1393  MPI_Isend(&cooling_rate, 1, MPI_DOUBLE, rank+1, 1, MPI_COMM_WORLD, &req[0]);
1394  MPI_Isend(&minimum_temperature, 1, MPI_DOUBLE, rank+1, 2, MPI_COMM_WORLD, &req[1]);
1395  MPI_Isend(&maximum_iterations_number, 1, MPI_INT, rank+1, 3, MPI_COMM_WORLD, &req[2]);
1396 
1397  MPI_Waitall(3, req, MPI_STATUS_IGNORE);
1398 
1399  break;
1400 
1401  default:
1402  break;
1403  }
1404 
1405  MPI_Isend(&minimum_order, 1, MPI_INT, rank+1, 4, MPI_COMM_WORLD, &req[0]);
1406  MPI_Isend(&maximum_order, 1, MPI_INT, rank+1, 5, MPI_COMM_WORLD, &req[1]);
1407  MPI_Isend(&trials_number, 1, MPI_INT, rank+1, 6, MPI_COMM_WORLD, &req[2]);
1408  MPI_Isend(&tolerance, 1, MPI_DOUBLE, rank+1, 7, MPI_COMM_WORLD, &req[3]);
1409  MPI_Isend(&selection_loss_goal, 1, MPI_DOUBLE, rank+1, 8, MPI_COMM_WORLD, &req[4]);
1410  MPI_Isend(&maximum_time, 1, MPI_INT, rank+1, 9, MPI_COMM_WORLD, &req[5]);
1411  MPI_Isend(&reserve_loss_loss_history, 1, MPI_INT, rank+1, 10, MPI_COMM_WORLD, &req[6]);
1412  MPI_Isend(&reserve_selection_loss_loss_history, 1, MPI_INT, rank+1, 11, MPI_COMM_WORLD, &req[7]);
1413 
1414  MPI_Waitall(8, req, MPI_STATUS_IGNORE);
1415  }
1416 
1417  MPI_Barrier(MPI_COMM_WORLD);
1418 
1419  // Set variables
1420 
1421  set_order_selection_type((ModelSelection::OrderSelectionType)original_order_selection_type);
1422 
1423  switch (original_order_selection_type)
1424  {
1425  case (int)ModelSelection::INCREMENTAL_ORDER:
1426  {
1432  incremental_order_pointer->set_selection_loss_goal(selection_loss_goal);
1433  incremental_order_pointer->set_maximum_selection_failures(maximum_selection_failures);
1435  incremental_order_pointer->set_reserve_loss_data(reserve_loss_loss_history == 1);
1436  incremental_order_pointer->set_reserve_selection_loss_data(reserve_selection_loss_loss_history == 1);
1437  }
1438  break;
1439 
1440  case (int)ModelSelection::GOLDEN_SECTION:
1441  {
1448  golden_section_order_pointer->set_reserve_loss_data(reserve_loss_loss_history == 1);
1449  golden_section_order_pointer->set_reserve_selection_loss_data(reserve_selection_loss_loss_history == 1);
1450  }
1451  break;
1452 
1453  case (int)ModelSelection::SIMULATED_ANNEALING:
1454  {
1464  simulated_annelaing_order_pointer->set_reserve_loss_data(reserve_loss_loss_history == 1);
1465  simulated_annelaing_order_pointer->set_reserve_selection_loss_data(reserve_selection_loss_loss_history == 1);
1466  }
1467  break;
1468 
1469  default:
1470  break;
1471  }
1472 }
1473 
1474 void ModelSelection::set_threshold_selection_MPI(const ModelSelection* model_selection)
1475 {
1476  int size;
1477  MPI_Comm_size(MPI_COMM_WORLD, &size);
1478 
1479  int rank;
1480  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
1481 
1482  int original_threshold_selection_type;
1483 
1484  // General parameters
1485 
1486  double minimum_threshold;
1487  double maximum_threshold;
1488  double step;
1489  int reserve_function_history;
1490 
1491  if(rank == 0)
1492  {
1493  // Variables to send initialization
1494 
1495  original_threshold_selection_type = (int)model_selection->get_threshold_selection_type();
1496 
1497  switch (original_threshold_selection_type)
1498  {
1499  case (int)ModelSelection::F1_SCORE_OPTIMIZATION:
1500  {
1501  F1ScoreOptimizationThreshold* original_f1_score_optimization = model_selection->get_f1_score_optimization_threshold_pointer();
1502 
1503  minimum_threshold = original_f1_score_optimization->get_minimum_threshold();
1504  maximum_threshold = original_f1_score_optimization->get_maximum_threshold();
1505  step = original_f1_score_optimization->get_step();
1506  reserve_function_history = original_f1_score_optimization->get_reserve_function_data();
1507  }
1508  break;
1509 
1510  case (int)ModelSelection::MATTHEW_CORRELATION:
1511  {
1512  MatthewCorrelationOptimizationThreshold* original_matthew_correlation_optimization = model_selection->get_matthew_correlation_optimization_threshold();
1513 
1514  minimum_threshold = original_matthew_correlation_optimization->get_minimum_threshold();
1515  maximum_threshold = original_matthew_correlation_optimization->get_maximum_threshold();
1516  step = original_matthew_correlation_optimization->get_step();
1517  reserve_function_history = original_matthew_correlation_optimization->get_reserve_function_data();
1518  }
1519  break;
1520 
1521  case (int)ModelSelection::YOUDEN_INDEX:
1522  {
1523  YoudenIndexOptimizationThreshold* original_youden_index_optimization = model_selection->get_youden_index_optimization_threshold();
1524 
1525  minimum_threshold = original_youden_index_optimization->get_minimum_threshold();
1526  maximum_threshold = original_youden_index_optimization->get_maximum_threshold();
1527  step = original_youden_index_optimization->get_step();
1528  reserve_function_history = original_youden_index_optimization->get_reserve_function_data();
1529  }
1530  break;
1531 
1532  case (int)ModelSelection::KAPPA_COEFFICIENT:
1533  {
1534  KappaCoefficientOptimizationThreshold* original_kappa_coefficient_optimization = model_selection->get_kappa_coefficient_optimization_threshold();
1535 
1536  minimum_threshold = original_kappa_coefficient_optimization->get_minimum_threshold();
1537  maximum_threshold = original_kappa_coefficient_optimization->get_maximum_threshold();
1538  step = original_kappa_coefficient_optimization->get_step();
1539  reserve_function_history = original_kappa_coefficient_optimization->get_reserve_function_data();
1540  }
1541  break;
1542 
1543  case (int)ModelSelection::ROC_CURVE_DISTANCE:
1544  {
1545  ROCCurveOptimizationThreshold* original_roc_curve_optimization = model_selection->get_roc_curve_optimization_threshold();
1546 
1547  minimum_threshold = original_roc_curve_optimization->get_minimum_threshold();
1548  maximum_threshold = original_roc_curve_optimization->get_maximum_threshold();
1549  step = original_roc_curve_optimization->get_step();
1550  reserve_function_history = original_roc_curve_optimization->get_reserve_function_data();
1551  }
1552  break;
1553 
1554  default:
1555  break;
1556  }
1557  }
1558 
1559  // Send variables
1560 
1561  MPI_Barrier(MPI_COMM_WORLD);
1562 
1563  if(rank > 0)
1564  {
1565  MPI_Recv(&original_threshold_selection_type, 1, MPI_INT, rank-1, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
1566 
1567  MPI_Request req[4];
1568 
1569  MPI_Irecv(&minimum_threshold, 1, MPI_INT, rank-1, 2, MPI_COMM_WORLD, &req[0]);
1570  MPI_Irecv(&maximum_threshold, 1, MPI_INT, rank-1, 3, MPI_COMM_WORLD, &req[1]);
1571  MPI_Irecv(&step, 1, MPI_INT, rank-1, 4, MPI_COMM_WORLD, &req[2]);
1572  MPI_Irecv(&reserve_function_history, 1, MPI_INT, rank-1, 5, MPI_COMM_WORLD, &req[3]);
1573 
1574  MPI_Waitall(4, req, MPI_STATUS_IGNORE);
1575  }
1576 
1577  if(rank < size-1)
1578  {
1579  MPI_Send(&original_threshold_selection_type, 1, MPI_INT, rank+1, 1, MPI_COMM_WORLD);
1580 
1581  MPI_Request req[4];
1582 
1583  MPI_Isend(&minimum_threshold, 1, MPI_INT, rank+1, 2, MPI_COMM_WORLD, &req[0]);
1584  MPI_Isend(&maximum_threshold, 1, MPI_INT, rank+1, 3, MPI_COMM_WORLD, &req[1]);
1585  MPI_Isend(&step, 1, MPI_INT, rank+1, 4, MPI_COMM_WORLD, &req[2]);
1586  MPI_Isend(&reserve_function_history, 1, MPI_INT, rank+1, 5, MPI_COMM_WORLD, &req[3]);
1587 
1588  MPI_Waitall(4, req, MPI_STATUS_IGNORE);
1589  }
1590 
1591  MPI_Barrier(MPI_COMM_WORLD);
1592 
1593  // Set variables
1594 
1595  set_threshold_selection_type((ModelSelection::ThresholdSelectionType)original_threshold_selection_type);
1596 
1597  switch (original_threshold_selection_type)
1598  {
1599  case (int)ModelSelection::F1_SCORE_OPTIMIZATION:
1600  {
1605  }
1606  break;
1607 
1608  case (int)ModelSelection::MATTHEW_CORRELATION:
1609  {
1614  }
1615  break;
1616 
1617  case (int)ModelSelection::YOUDEN_INDEX:
1618  {
1623  }
1624  break;
1625 
1626  case (int)ModelSelection::KAPPA_COEFFICIENT:
1627  {
1632  }
1633  break;
1634 
1635  case (int)ModelSelection::ROC_CURVE_DISTANCE:
1636  {
1641  }
1642  break;
1643 
1644  default:
1645  break;
1646  }
1647 }
1648 #endif
1649 
1650 // void destruct_order_selection(void) method
1651 
1653 
1655 {
1659 
1663 
1664  order_selection_type = NO_ORDER_SELECTION;
1665 }
1666 
1667 // void destruct_inputs_selection(void) method
1668 
1670 
1672 {
1673  delete growing_inputs_pointer;
1674  delete pruning_inputs_pointer;
1676 
1677  growing_inputs_pointer = NULL;
1678  pruning_inputs_pointer = NULL;
1680 
1681  inputs_selection_type = NO_INPUTS_SELECTION;
1682 }
1683 
1684 // void destruct_threshold_selection(void) method
1685 
1687 
1689 {
1695 
1701 
1702  threshold_selection_type = NO_THRESHOLD_SELECTION;
1703 }
1704 
1705 // void check(void) const method
1706 
1708 
1709 void ModelSelection::check(void) const
1710 {
1711 
1712  // Training algorithm stuff
1713 
1714  std::ostringstream buffer;
1715 
1717  {
1718  buffer << "OpenNN Exception: ModelSelection class.\n"
1719  << "void check(void) const method.\n"
1720  << "Pointer to training strategy is NULL.\n";
1721 
1722  throw std::logic_error(buffer.str());
1723  }
1724 
1725  // Loss index stuff
1726 
1727  const LossIndex* loss_index_pointer = training_strategy_pointer->get_loss_index_pointer();
1728 
1729  if(!loss_index_pointer)
1730  {
1731  buffer << "OpenNN Exception: ModelSelection class.\n"
1732  << "void check(void) const method.\n"
1733  << "Pointer to loss functional is NULL.\n";
1734 
1735  throw std::logic_error(buffer.str());
1736  }
1737 
1738  // Neural network stuff
1739 
1740  const NeuralNetwork* neural_network_pointer = loss_index_pointer->get_neural_network_pointer();
1741 
1742  if(!neural_network_pointer)
1743  {
1744  buffer << "OpenNN Exception: ModelSelection class.\n"
1745  << "void check(void) const method.\n"
1746  << "Pointer to neural network is NULL.\n";
1747 
1748  throw std::logic_error(buffer.str());
1749  }
1750 
1751  const MultilayerPerceptron* multilayer_perceptron_pointer = neural_network_pointer->get_multilayer_perceptron_pointer();
1752 
1753  if(!multilayer_perceptron_pointer)
1754  {
1755  buffer << "OpenNN Exception: ModelSelection class.\n"
1756  << "void check(void) const method.\n"
1757  << "Pointer to multilayer perceptron is NULL.\n";
1758 
1759  throw std::logic_error(buffer.str());
1760  }
1761 
1762  if(multilayer_perceptron_pointer->is_empty())
1763  {
1764  buffer << "OpenNN Exception: ModelSelection class.\n"
1765  << "void check(void) const method.\n"
1766  << "Multilayer Perceptron is empty.\n";
1767 
1768  throw std::logic_error(buffer.str());
1769  }
1770 
1771  // Data set stuff
1772 
1773  const DataSet* data_set_pointer = loss_index_pointer->get_data_set_pointer();
1774 
1775  if(!data_set_pointer)
1776  {
1777  buffer << "OpenNN Exception: ModelSelection class.\n"
1778  << "void check(void) const method.\n"
1779  << "Pointer to data set is NULL.\n";
1780 
1781  throw std::logic_error(buffer.str());
1782  }
1783 
1784  const Instances& instances = data_set_pointer->get_instances();
1785 
1786  const size_t selection_instances_number = instances.count_selection_instances_number();
1787 
1788  if(selection_instances_number == 0)
1789  {
1790  buffer << "OpenNN Exception: ModelSelection class.\n"
1791  << "void check(void) const method.\n"
1792  << "Number of selection instances is zero.\n";
1793 
1794  throw std::logic_error(buffer.str());
1795  }
1796 
1797 }
1798 
1799 // Vector<double> calculate_inputs_importance(void) const method
1800 
1802 
1804 {
1805 #ifdef __OPENNN_DEBUG__
1806 
1807  check();
1808 
1809 #endif
1810 
1812 
1813  NeuralNetwork* neural_network_pointer = loss_index_pointer->get_neural_network_pointer();
1814 
1815  const size_t inputs_number = neural_network_pointer->get_inputs_number();
1816 
1817  Vector<double> input_importance(inputs_number, 0.0);
1818 
1819  Vector< Statistics<double> > statistics;
1820 
1821  const bool has_scaling_layer = neural_network_pointer->has_scaling_layer();
1822 
1823  NeuralNetwork neural_network_copy(*neural_network_pointer);
1824 
1825  LossIndex loss_index_copy(*loss_index_pointer);
1826 
1827  loss_index_copy.set_neural_network_pointer(&neural_network_copy);
1828 
1829  TrainingStrategy training_strategy_copy(&loss_index_copy);
1830 
1831  const size_t parameters_number = neural_network_copy.count_parameters_number();
1832 
1833  neural_network_copy.set_parameters(Vector<double>(parameters_number, 0.0));
1834 
1835  if(has_scaling_layer)
1836  {
1837  statistics = neural_network_pointer->get_scaling_layer_pointer()->get_statistics();
1838  }
1839 
1840  training_strategy_copy.set_display(false);
1841 
1842  neural_network_copy.randomize_parameters_normal(0.0, 1.0);
1843 
1844  training_strategy_copy.perform_training();
1845 
1846  const Vector<double> parameters = neural_network_copy.arrange_parameters();
1847 
1848  const double trained_selection_error = loss_index_copy.calculate_selection_error();
1849 
1850  for (size_t i = 0; i < inputs_number; i++)
1851  {
1852  neural_network_copy.prune_input(i);
1853 
1854  const double current_selection_error = loss_index_copy.calculate_selection_error();
1855 
1856  if(current_selection_error > trained_selection_error)
1857  {
1858  input_importance[i] = 1;
1859  }
1860  else if(current_selection_error < trained_selection_error)
1861  {
1862  input_importance[i] = 0;
1863  }
1864  else
1865  {
1866  input_importance[i] = current_selection_error/trained_selection_error;
1867  }
1868 
1869  neural_network_copy.grow_input();
1870 
1871  neural_network_copy.set_parameters(parameters);
1872  }
1873 
1874  if(has_scaling_layer)
1875  {
1876  neural_network_pointer->get_scaling_layer_pointer()->set_statistics(statistics);
1877  }
1878 
1879  return input_importance;
1880 }
1881 
1882 // ModelSelectionResults perform_order_selection(void) method
1883 
1886 
1888 {
1889 #ifdef __OPENNN_DEBUG__
1890 
1891  std::ostringstream buffer;
1892 
1893  if(order_selection_type == NO_ORDER_SELECTION)
1894  {
1895  buffer << "OpenNN Exception: ModelSelection class.\n"
1896  << "ModelSelectionResults perform_order_selection(void) const method.\n"
1897  << "None order selection term is used.\n";
1898 
1899  throw std::logic_error(buffer.str());
1900  }
1901 
1902  check();
1903 
1904 #endif
1905 
1906  ModelSelectionResults results;
1907 
1908  switch(order_selection_type)
1909  {
1910  case INCREMENTAL_ORDER:
1911  {
1913 
1915  break;
1916  }
1917  case GOLDEN_SECTION:
1918  {
1920 
1922  break;
1923  }
1924  case SIMULATED_ANNEALING:
1925  {
1927 
1929  break;
1930  }
1931  default:
1932  {
1933  std::ostringstream buffer;
1934 
1935  buffer << "OpenNN Exception: ModelSelection class.\n"
1936  << "ModelSelectionResults perform_order_selection(void) method.\n"
1937  << "Unknown order selection method.\n";
1938 
1939  throw std::logic_error(buffer.str());
1940 
1941  break;
1942  }
1943  }
1944 
1945  return(results);
1946 }
1947 
1948 // ModelSelectionResults perform_inputs_selection(void) method
1949 
1952 
1954 {
1955 #ifdef __OPENNN_DEBUG__
1956 
1957  std::ostringstream buffer;
1958 
1959  if(inputs_selection_type == NO_INPUTS_SELECTION)
1960  {
1961  buffer << "OpenNN Exception: ModelSelection class.\n"
1962  << "ModelSelectionResults perform_inputs_selection(void) const method.\n"
1963  << "None inputs selection term is used.\n";
1964 
1965  throw std::logic_error(buffer.str());
1966  }
1967 
1968  check();
1969 
1970 #endif
1971 
1972  ModelSelectionResults results;
1973 
1974  switch(inputs_selection_type)
1975  {
1976  case GROWING_INPUTS:
1977  {
1979 
1981 
1982  break;
1983  }
1984  case PRUNING_INPUTS:
1985  {
1987 
1989 
1990  break;
1991  }
1992  case GENETIC_ALGORITHM:
1993  {
1995 
1997 
1998  break;
1999  }
2000  default:
2001  {
2002  std::ostringstream buffer;
2003 
2004  buffer << "OpenNN Exception: ModelSelection class.\n"
2005  << "ModelSelectionResults perform_inputs_selection(void) method.\n"
2006  << "Unknown inputs selection method.\n";
2007 
2008  throw std::logic_error(buffer.str());
2009 
2010  break;
2011  }
2012  }
2013 
2014  return(results);
2015 }
2016 
2017 // ModelSelectionResults perform_threshold_selection(void) method
2018 
2021 
2023 {
2024 #ifdef __OPENNN_DEBUG__
2025 
2026  std::ostringstream buffer;
2027 
2028  if(threshold_selection_type == NO_THRESHOLD_SELECTION)
2029  {
2030  buffer << "OpenNN Exception: ModelSelection class.\n"
2031  << "ModelSelectionResults perform_threshold_selection(void) const method.\n"
2032  << "None threshold selection term is used.\n";
2033 
2034  throw std::logic_error(buffer.str());
2035  }
2036 
2037  check();
2038 
2039 #endif
2040 
2041  ModelSelectionResults results;
2042 
2043  switch(threshold_selection_type)
2044  {
2045  case F1_SCORE_OPTIMIZATION:
2046  {
2048 
2050 
2051  break;
2052  }
2053  case MATTHEW_CORRELATION:
2054  {
2056 
2058 
2059  break;
2060  }
2061  case YOUDEN_INDEX:
2062  {
2064 
2066 
2067  break;
2068  }
2069  case KAPPA_COEFFICIENT:
2070  {
2072 
2074 
2075  break;
2076  }
2077  case ROC_CURVE_DISTANCE:
2078  {
2080 
2082 
2083  break;
2084  }
2085  default:
2086  {
2087  std::ostringstream buffer;
2088 
2089  buffer << "OpenNN Exception: ModelSelection class.\n"
2090  << "ModelSelectionResults perform_threshold_selection(void) method.\n"
2091  << "Unknown threshold selection method.\n";
2092 
2093  throw std::logic_error(buffer.str());
2094 
2095  break;
2096  }
2097  }
2098 
2099  return(results);
2100 }
2101 
2102 // ModelSelectionResults perform_model_selection(void) const method
2103 
2106 
2108 {
2109  ModelSelectionResults model_selection_results;
2110 
2111  model_selection_results = perform_order_selection();
2112 
2113  return(model_selection_results);
2114 }
2115 
2116 
2117 // tinyxml2::XMLDocument* to_XML(void) const method
2118 
2121 
2122 tinyxml2::XMLDocument* ModelSelection::to_XML(void) const
2123 {
2124  std::ostringstream buffer;
2125 
2126  tinyxml2::XMLDocument* document = new tinyxml2::XMLDocument;
2127 
2128  // Training strategy
2129 
2130  tinyxml2::XMLElement* model_selection_element = document->NewElement("ModelSelection");
2131 
2132  document->InsertFirstChild(model_selection_element);
2133 
2134  // Inputs Selection
2135 
2136  switch(inputs_selection_type)
2137  {
2138  case NO_INPUTS_SELECTION:
2139  {
2140  tinyxml2::XMLElement* inputs_selection_element = document->NewElement("InputsSelection");
2141  model_selection_element->LinkEndChild(inputs_selection_element);
2142 
2143  inputs_selection_element->SetAttribute("Type", "NO_INPUTS_SELECTION");
2144  }
2145  break;
2146 
2147  case GROWING_INPUTS:
2148  {
2149  tinyxml2::XMLElement* inputs_selection_element = document->NewElement("InputsSelection");
2150  model_selection_element->LinkEndChild(inputs_selection_element);
2151 
2152  inputs_selection_element->SetAttribute("Type", "GROWING_INPUTS");
2153 
2154  const tinyxml2::XMLDocument* growing_inputs_document = growing_inputs_pointer->to_XML();
2155 
2156  const tinyxml2::XMLElement* growing_inputs_element = growing_inputs_document->FirstChildElement("GrowingInputs");
2157 
2158  DeepClone(inputs_selection_element, growing_inputs_element, document, NULL);
2159 
2160  delete growing_inputs_document;
2161  }
2162  break;
2163 
2164  case PRUNING_INPUTS:
2165  {
2166  tinyxml2::XMLElement* inputs_selection_element = document->NewElement("InputsSelection");
2167  model_selection_element->LinkEndChild(inputs_selection_element);
2168 
2169  inputs_selection_element->SetAttribute("Type", "PRUNING_INPUTS");
2170 
2171  const tinyxml2::XMLDocument* pruning_inputs_document = pruning_inputs_pointer->to_XML();
2172 
2173  const tinyxml2::XMLElement* pruning_inputs_element = pruning_inputs_document->FirstChildElement("PruningInputs");
2174 
2175  DeepClone(inputs_selection_element, pruning_inputs_element, document, NULL);
2176 
2177  delete pruning_inputs_document;
2178  }
2179  break;
2180 
2181  case GENETIC_ALGORITHM:
2182  {
2183  tinyxml2::XMLElement* inputs_selection_element = document->NewElement("InputsSelection");
2184  model_selection_element->LinkEndChild(inputs_selection_element);
2185 
2186  inputs_selection_element->SetAttribute("Type", "GENETIC_ALGORITHM");
2187 
2188  const tinyxml2::XMLDocument* genetic_algorithm_document = genetic_algorithm_pointer->to_XML();
2189 
2190  const tinyxml2::XMLElement* genetic_algorithm_element = genetic_algorithm_document->FirstChildElement("GeneticAlgorithm");
2191 
2192  DeepClone(inputs_selection_element, genetic_algorithm_element, document, NULL);
2193 
2194  delete genetic_algorithm_document;
2195  }
2196  break;
2197 
2198  default:
2199  {
2200  std::ostringstream buffer;
2201 
2202  buffer << "OpenNN Exception: ModelSelection class.\n"
2203  << "tinyxml2::XMLDocument* to_XML(void) const method.\n"
2204  << "Unknown inputs selection type.\n";
2205 
2206  throw std::logic_error(buffer.str());
2207  }
2208  break;
2209  }
2210 
2211  // Order Selection
2212 
2213  switch(order_selection_type)
2214  {
2215  case NO_ORDER_SELECTION:
2216  {
2217  tinyxml2::XMLElement* order_selection_element = document->NewElement("OrderSelection");
2218  model_selection_element->LinkEndChild(order_selection_element);
2219 
2220  order_selection_element->SetAttribute("Type", "NO_ORDER_SELECTION");
2221  }
2222  break;
2223 
2224  case INCREMENTAL_ORDER:
2225  {
2226  tinyxml2::XMLElement* order_selection_element = document->NewElement("OrderSelection");
2227  model_selection_element->LinkEndChild(order_selection_element);
2228 
2229  order_selection_element->SetAttribute("Type", "INCREMENTAL_ORDER");
2230 
2231  const tinyxml2::XMLDocument* incremental_order_document = incremental_order_pointer->to_XML();
2232 
2233  const tinyxml2::XMLElement* incremental_order_element = incremental_order_document->FirstChildElement("IncrementalOrder");
2234 
2235  DeepClone(order_selection_element, incremental_order_element, document, NULL);
2236 
2237  delete incremental_order_document;
2238  }
2239  break;
2240 
2241  case GOLDEN_SECTION:
2242  {
2243  tinyxml2::XMLElement* order_selection_element = document->NewElement("OrderSelection");
2244  model_selection_element->LinkEndChild(order_selection_element);
2245 
2246  order_selection_element->SetAttribute("Type", "GOLDEN_SECTION");
2247 
2248  const tinyxml2::XMLDocument* golden_section_order_document = golden_section_order_pointer->to_XML();
2249 
2250  const tinyxml2::XMLElement* golden_section_order_element = golden_section_order_document->FirstChildElement("GoldenSectionOrder");
2251 
2252  DeepClone(order_selection_element, golden_section_order_element, document, NULL);
2253 
2254  delete golden_section_order_document;
2255  }
2256  break;
2257 
2258  case SIMULATED_ANNEALING:
2259  {
2260  tinyxml2::XMLElement* order_selection_element = document->NewElement("OrderSelection");
2261  model_selection_element->LinkEndChild(order_selection_element);
2262 
2263  order_selection_element->SetAttribute("Type", "SIMULATED_ANNEALING");
2264 
2265  const tinyxml2::XMLDocument* simulated_annealing_order_document = simulated_annelaing_order_pointer->to_XML();
2266 
2267  const tinyxml2::XMLElement* simulated_annealing_order_element = simulated_annealing_order_document->FirstChildElement("SimulatedAnnealingOrder");
2268 
2269  DeepClone(order_selection_element, simulated_annealing_order_element, document, NULL);
2270 
2271  delete simulated_annealing_order_document;
2272  }
2273  break;
2274 
2275  default:
2276  {
2277  std::ostringstream buffer;
2278 
2279  buffer << "OpenNN Exception: ModelSelection class.\n"
2280  << "tinyxml2::XMLDocument* to_XML(void) const method.\n"
2281  << "Unknown order selection type.\n";
2282 
2283  throw std::logic_error(buffer.str());
2284  }
2285  break;
2286  }
2287 
2288  // Threshold Selection
2289 
2290  switch(threshold_selection_type)
2291  {
2292  case NO_ORDER_SELECTION:
2293  {
2294  tinyxml2::XMLElement* order_selection_element = document->NewElement("ThresholdSelection");
2295  model_selection_element->LinkEndChild(order_selection_element);
2296 
2297  order_selection_element->SetAttribute("Type", "NO_ORDER_SELECTION");
2298  }
2299  break;
2300 
2301  case F1_SCORE_OPTIMIZATION:
2302  {
2303  tinyxml2::XMLElement* threshold_selection_element = document->NewElement("ThresholdSelection");
2304  model_selection_element->LinkEndChild(threshold_selection_element);
2305 
2306  threshold_selection_element->SetAttribute("Type", "F1_SCORE_OPTIMIZATION");
2307 
2308  const tinyxml2::XMLDocument* f1_score_optimization_document = f1_score_optimization_threshold_pointer->to_XML();
2309 
2310  const tinyxml2::XMLElement* f1_score_optimization_element = f1_score_optimization_document->FirstChildElement("F1ScoreOptimizationThreshold");
2311 
2312  DeepClone(threshold_selection_element, f1_score_optimization_element, document, NULL);
2313 
2314  delete f1_score_optimization_document;
2315  }
2316  break;
2317 
2318  case MATTHEW_CORRELATION:
2319  {
2320  tinyxml2::XMLElement* threshold_selection_element = document->NewElement("ThresholdSelection");
2321  model_selection_element->LinkEndChild(threshold_selection_element);
2322 
2323  threshold_selection_element->SetAttribute("Type", "MATTHEW_CORRELATION");
2324 
2325  const tinyxml2::XMLDocument* matthew_correlation_optimization_document = matthew_correlation_optimization_threshold_pointer->to_XML();
2326 
2327  const tinyxml2::XMLElement* matthew_correlation_optimization_element = matthew_correlation_optimization_document->FirstChildElement("MatthewCorrelationOptimizationThreshold");
2328 
2329  DeepClone(threshold_selection_element, matthew_correlation_optimization_element, document, NULL);
2330 
2331  delete matthew_correlation_optimization_document;
2332  }
2333  break;
2334 
2335  case YOUDEN_INDEX:
2336  {
2337  tinyxml2::XMLElement* threshold_selection_element = document->NewElement("ThresholdSelection");
2338  model_selection_element->LinkEndChild(threshold_selection_element);
2339 
2340  threshold_selection_element->SetAttribute("Type", "YOUDEN_INDEX");
2341 
2342  const tinyxml2::XMLDocument* youden_index_optimization_document = youden_index_optimization_threshold_pointer->to_XML();
2343 
2344  const tinyxml2::XMLElement* youden_index_optimization_element = youden_index_optimization_document->FirstChildElement("YoudenIndexOptimizationThreshold");
2345 
2346  DeepClone(threshold_selection_element, youden_index_optimization_element, document, NULL);
2347 
2348  delete youden_index_optimization_document;
2349  }
2350  break;
2351 
2352  case KAPPA_COEFFICIENT:
2353  {
2354  tinyxml2::XMLElement* threshold_selection_element = document->NewElement("ThresholdSelection");
2355  model_selection_element->LinkEndChild(threshold_selection_element);
2356 
2357  threshold_selection_element->SetAttribute("Type", "KAPPA_COEFFICIENT");
2358 
2359  const tinyxml2::XMLDocument* kappa_coefficient_optimization_document = kappa_coefficient_optimization_threshold_pointer->to_XML();
2360 
2361  const tinyxml2::XMLElement* kappa_coefficient_optimization_element = kappa_coefficient_optimization_document->FirstChildElement("KappaCoefficientOptimizationThreshold");
2362 
2363  DeepClone(threshold_selection_element, kappa_coefficient_optimization_element, document, NULL);
2364 
2365  delete kappa_coefficient_optimization_document;
2366  }
2367  break;
2368 
2369  case ROC_CURVE_DISTANCE:
2370  {
2371  tinyxml2::XMLElement* threshold_selection_element = document->NewElement("ThresholdSelection");
2372  model_selection_element->LinkEndChild(threshold_selection_element);
2373 
2374  threshold_selection_element->SetAttribute("Type", "ROC_CURVE_DISTANCE");
2375 
2376  const tinyxml2::XMLDocument* roc_curve_optimization_document = roc_curve_optimization_threshold_pointer->to_XML();
2377 
2378  const tinyxml2::XMLElement* roc_curve_optimization_element = roc_curve_optimization_document->FirstChildElement("ROCCurveOptimizationThreshold");
2379 
2380  DeepClone(threshold_selection_element, roc_curve_optimization_element, document, NULL);
2381 
2382  delete roc_curve_optimization_document;
2383  }
2384  break;
2385 
2386  default:
2387  {
2388  std::ostringstream buffer;
2389 
2390  buffer << "OpenNN Exception: ModelSelection class.\n"
2391  << "tinyxml2::XMLDocument* to_XML(void) const method.\n"
2392  << "Unknown threshold selection type.\n";
2393 
2394  throw std::logic_error(buffer.str());
2395  }
2396  break;
2397  }
2398 
2399  return(document);
2400 }
2401 
2402 
2403 // void write_XML(tinyxml2::XMLPrinter&) const method
2404 
2407 
2408 void ModelSelection::write_XML(tinyxml2::XMLPrinter& file_stream) const
2409 {
2410  file_stream.OpenElement("ModelSelection");
2411 
2412  // Inputs Selection
2413 
2414  switch(inputs_selection_type)
2415  {
2416  case NO_INPUTS_SELECTION:
2417  {
2418  file_stream.OpenElement("InputsSelection");
2419 
2420  file_stream.PushAttribute("Type", "NO_INPUTS_SELECTION");
2421 
2422  file_stream.CloseElement();
2423  }
2424  break;
2425 
2426  case GROWING_INPUTS:
2427  {
2428  file_stream.OpenElement("InputsSelection");
2429 
2430  file_stream.PushAttribute("Type", "GROWING_INPUTS");
2431 
2432  growing_inputs_pointer->write_XML(file_stream);
2433 
2434  file_stream.CloseElement();
2435  }
2436  break;
2437 
2438  case PRUNING_INPUTS:
2439  {
2440  file_stream.OpenElement("InputsSelection");
2441 
2442  file_stream.PushAttribute("Type", "PRUNING_INPUTS");
2443 
2444  pruning_inputs_pointer->write_XML(file_stream);
2445 
2446  file_stream.CloseElement();
2447  }
2448  break;
2449 
2450  case GENETIC_ALGORITHM:
2451  {
2452  file_stream.OpenElement("InputsSelection");
2453 
2454  file_stream.PushAttribute("Type", "GENETIC_ALGORITHM");
2455 
2456  genetic_algorithm_pointer->write_XML(file_stream);
2457 
2458  file_stream.CloseElement();
2459  }
2460  break;
2461 
2462  default:
2463  {
2464  std::ostringstream buffer;
2465 
2466  file_stream.CloseElement();
2467 
2468  buffer << "OpenNN Exception: ModelSelection class.\n"
2469  << "void write_XML(tinyxml2::XMLPrinter&) const method.\n"
2470  << "Unknown inputs selection type.\n";
2471 
2472  throw std::logic_error(buffer.str());
2473  }
2474  break;
2475  }
2476 
2477  // Order Selection
2478 
2479  switch(order_selection_type)
2480  {
2481  case NO_ORDER_SELECTION:
2482  {
2483  file_stream.OpenElement("OrderSelection");
2484 
2485  file_stream.PushAttribute("Type", "NO_ORDER_SELECTION");
2486 
2487  file_stream.CloseElement();
2488  }
2489  break;
2490 
2491  case INCREMENTAL_ORDER:
2492  {
2493  file_stream.OpenElement("OrderSelection");
2494 
2495  file_stream.PushAttribute("Type", "INCREMENTAL_ORDER");
2496 
2497  incremental_order_pointer->write_XML(file_stream);
2498 
2499  file_stream.CloseElement();
2500  }
2501  break;
2502 
2503  case GOLDEN_SECTION:
2504  {
2505  file_stream.OpenElement("OrderSelection");
2506 
2507  file_stream.PushAttribute("Type", "GOLDEN_SECTION");
2508 
2510 
2511  file_stream.CloseElement();
2512  }
2513  break;
2514 
2515  case SIMULATED_ANNEALING:
2516  {
2517  file_stream.OpenElement("OrderSelection");
2518 
2519  file_stream.PushAttribute("Type", "SIMULATED_ANNEALING");
2520 
2522 
2523  file_stream.CloseElement();
2524  }
2525  break;
2526 
2527  default:
2528  {
2529  std::ostringstream buffer;
2530 
2531  file_stream.CloseElement();
2532 
2533  buffer << "OpenNN Exception: ModelSelection class.\n"
2534  << "void write_XML(tinyxml2::XMLPrinter&) const method.\n"
2535  << "Unknown order selection type.\n";
2536 
2537  throw std::logic_error(buffer.str());
2538  }
2539  break;
2540  }
2541 
2542  // Threshold Selection
2543 
2544  switch(threshold_selection_type)
2545  {
2546  case NO_THRESHOLD_SELECTION:
2547  {
2548  file_stream.OpenElement("ThresholdSelection");
2549 
2550  file_stream.PushAttribute("Type", "NO_THRESHOLD_SELECTION");
2551 
2552  file_stream.CloseElement();
2553  }
2554  break;
2555 
2556  case F1_SCORE_OPTIMIZATION:
2557  {
2558  file_stream.OpenElement("ThresholdSelection");
2559 
2560  file_stream.PushAttribute("Type", "F1_SCORE_OPTIMIZATION");
2561 
2563 
2564  file_stream.CloseElement();
2565  }
2566  break;
2567 
2568  case MATTHEW_CORRELATION:
2569  {
2570  file_stream.OpenElement("ThresholdSelection");
2571 
2572  file_stream.PushAttribute("Type", "MATTHEW_CORRELATION");
2573 
2575 
2576  file_stream.CloseElement();
2577  }
2578  break;
2579 
2580  case YOUDEN_INDEX:
2581  {
2582  file_stream.OpenElement("ThresholdSelection");
2583 
2584  file_stream.PushAttribute("Type", "YOUDEN_INDEX");
2585 
2587 
2588  file_stream.CloseElement();
2589  }
2590  break;
2591 
2592  case KAPPA_COEFFICIENT:
2593  {
2594  file_stream.OpenElement("ThresholdSelection");
2595 
2596  file_stream.PushAttribute("Type", "KAPPA_COEFFICIENT");
2597 
2599 
2600  file_stream.CloseElement();
2601  }
2602  break;
2603 
2604  case ROC_CURVE_DISTANCE:
2605  {
2606  file_stream.OpenElement("ThresholdSelection");
2607 
2608  file_stream.PushAttribute("Type", "ROC_CURVE_DISTANCE");
2609 
2611 
2612  file_stream.CloseElement();
2613  }
2614  break;
2615 
2616  default:
2617  {
2618  std::ostringstream buffer;
2619 
2620  file_stream.CloseElement();
2621 
2622  buffer << "OpenNN Exception: ModelSelection class.\n"
2623  << "void write_XML(tinyxml2::XMLPrinter&) const method.\n"
2624  << "Unknown order selection type.\n";
2625 
2626  throw std::logic_error(buffer.str());
2627  }
2628  break;
2629  }
2630 
2631  file_stream.CloseElement();
2632 }
2633 
2634 // void from_XML(const tinyxml2::XMLDocument&) method
2635 
2638 
2639 void ModelSelection::from_XML(const tinyxml2::XMLDocument& document)
2640 {
2641  const tinyxml2::XMLElement* root_element = document.FirstChildElement("ModelSelection");
2642 
2643  if(!root_element)
2644  {
2645  std::ostringstream buffer;
2646 
2647  buffer << "OpenNN Exception: ModelSelection class.\n"
2648  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
2649  << "Model Selection element is NULL.\n";
2650 
2651  throw std::logic_error(buffer.str());
2652  }
2653 
2654  // Inputs Selection
2655  {
2656  const tinyxml2::XMLElement* element = root_element->FirstChildElement("InputsSelection");
2657 
2658  if(element)
2659  {
2660  const std::string new_inputs_selection_type = element->Attribute("Type");
2661 
2662  set_inputs_selection_type(new_inputs_selection_type);
2663 
2664  switch(inputs_selection_type)
2665  {
2666  case NO_INPUTS_SELECTION:
2667  {
2668  // do nothing
2669  }
2670  break;
2671  case GROWING_INPUTS:
2672  {
2673  tinyxml2::XMLDocument new_document;
2674 
2675  tinyxml2::XMLElement* element_clone = new_document.NewElement("GrowingInputs");
2676  new_document.InsertFirstChild(element_clone);
2677 
2678  DeepClone(element_clone, element, &new_document, NULL);
2679 
2680  growing_inputs_pointer->from_XML(new_document);
2681  }
2682  break;
2683  case PRUNING_INPUTS:
2684  {
2685  tinyxml2::XMLDocument new_document;
2686 
2687  tinyxml2::XMLElement* element_clone = new_document.NewElement("PruningInputs");
2688  new_document.InsertFirstChild(element_clone);
2689 
2690  DeepClone(element_clone, element, &new_document, NULL);
2691 
2692  pruning_inputs_pointer->from_XML(new_document);
2693  }
2694  break;
2695  case GENETIC_ALGORITHM:
2696  {
2697  tinyxml2::XMLDocument new_document;
2698 
2699  tinyxml2::XMLElement* element_clone = new_document.NewElement("GeneticAlgorithm");
2700  new_document.InsertFirstChild(element_clone);
2701 
2702  DeepClone(element_clone, element, &new_document, NULL);
2703 
2704  genetic_algorithm_pointer->from_XML(new_document);
2705  }
2706  break;
2707  default:
2708  {
2709  std::ostringstream buffer;
2710 
2711  buffer << "OpenNN Exception: ModelSelection class.\n"
2712  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
2713  << "Unknown inputs selection type.\n";
2714 
2715  throw std::logic_error(buffer.str());
2716  }
2717  break;
2718  }
2719  }
2720  }
2721 
2722  // Order Selection
2723  {
2724  const tinyxml2::XMLElement* element = root_element->FirstChildElement("OrderSelection");
2725 
2726  if(element)
2727  {
2728  const std::string new_order_selection_type = element->Attribute("Type");
2729 
2730  set_order_selection_type(new_order_selection_type);
2731 
2732  switch(order_selection_type)
2733  {
2734  case NO_ORDER_SELECTION:
2735  {
2736  // do nothing
2737  }
2738  break;
2739  case INCREMENTAL_ORDER:
2740  {
2741  tinyxml2::XMLDocument new_document;
2742 
2743  tinyxml2::XMLElement* element_clone = new_document.NewElement("IncrementalOrder");
2744  new_document.InsertFirstChild(element_clone);
2745 
2746  DeepClone(element_clone, element, &new_document, NULL);
2747 
2748  incremental_order_pointer->from_XML(new_document);
2749  }
2750  break;
2751  case GOLDEN_SECTION:
2752  {
2753  tinyxml2::XMLDocument new_document;
2754 
2755  tinyxml2::XMLElement* element_clone = new_document.NewElement("GoldenSectionOrder");
2756  new_document.InsertFirstChild(element_clone);
2757 
2758  DeepClone(element_clone, element, &new_document, NULL);
2759 
2760  golden_section_order_pointer->from_XML(new_document);
2761  }
2762  break;
2763  case SIMULATED_ANNEALING:
2764  {
2765  tinyxml2::XMLDocument new_document;
2766 
2767  tinyxml2::XMLElement* element_clone = new_document.NewElement("SimulatedAnnealingOrder");
2768  new_document.InsertFirstChild(element_clone);
2769 
2770  DeepClone(element_clone, element, &new_document, NULL);
2771 
2773  }
2774  break;
2775  default:
2776  {
2777  std::ostringstream buffer;
2778 
2779  buffer << "OpenNN Exception: ModelSelection class.\n"
2780  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
2781  << "Unknown order selection type.\n";
2782 
2783  throw std::logic_error(buffer.str());
2784  }
2785  break;
2786  }
2787  }
2788  }
2789 
2790  // Threshold Selection
2791  {
2792  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ThresholdSelection");
2793 
2794  if(element)
2795  {
2796  const std::string new_threshold_selection_type = element->Attribute("Type");
2797 
2798  set_threshold_selection_type(new_threshold_selection_type);
2799 
2800  switch(threshold_selection_type)
2801  {
2802  case NO_THRESHOLD_SELECTION:
2803  {
2804  // do nothing
2805  }
2806  break;
2807  case F1_SCORE_OPTIMIZATION:
2808  {
2809  tinyxml2::XMLDocument new_document;
2810 
2811  tinyxml2::XMLElement* element_clone = new_document.NewElement("F1ScoreOptimizationThreshold");
2812  new_document.InsertFirstChild(element_clone);
2813 
2814  DeepClone(element_clone, element, &new_document, NULL);
2815 
2817  }
2818  break;
2819  case MATTHEW_CORRELATION:
2820  {
2821  tinyxml2::XMLDocument new_document;
2822 
2823  tinyxml2::XMLElement* element_clone = new_document.NewElement("MatthewCorrelationOptimizationThreshold");
2824  new_document.InsertFirstChild(element_clone);
2825 
2826  DeepClone(element_clone, element, &new_document, NULL);
2827 
2829  }
2830  break;
2831  case YOUDEN_INDEX:
2832  {
2833  tinyxml2::XMLDocument new_document;
2834 
2835  tinyxml2::XMLElement* element_clone = new_document.NewElement("YoudenIndexOptimizationThreshold");
2836  new_document.InsertFirstChild(element_clone);
2837 
2838  DeepClone(element_clone, element, &new_document, NULL);
2839 
2841  }
2842  break;
2843  case KAPPA_COEFFICIENT:
2844  {
2845  tinyxml2::XMLDocument new_document;
2846 
2847  tinyxml2::XMLElement* element_clone = new_document.NewElement("KappaCoefficientOptimizationThreshold");
2848  new_document.InsertFirstChild(element_clone);
2849 
2850  DeepClone(element_clone, element, &new_document, NULL);
2851 
2853  }
2854  break;
2855  case ROC_CURVE_DISTANCE:
2856  {
2857  tinyxml2::XMLDocument new_document;
2858 
2859  tinyxml2::XMLElement* element_clone = new_document.NewElement("ROCCurveOptimizationThreshold");
2860  new_document.InsertFirstChild(element_clone);
2861 
2862  DeepClone(element_clone, element, &new_document, NULL);
2863 
2865  }
2866  break;
2867  default:
2868  {
2869  std::ostringstream buffer;
2870 
2871  buffer << "OpenNN Exception: ModelSelection class.\n"
2872  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
2873  << "Unknown order selection type.\n";
2874 
2875  throw std::logic_error(buffer.str());
2876  }
2877  break;
2878  }
2879  }
2880  }
2881 }
2882 
2883 
2884 // void print(void) method
2885 
2887 
2888 void ModelSelection::print(void) const
2889 {
2890  std::cout << to_XML();
2891 }
2892 
2893 
2894 // void save(const std::string&) const method
2895 
2898 
2899 void ModelSelection::save(const std::string& file_name) const
2900 {
2901  tinyxml2::XMLDocument* document = to_XML();
2902 
2903  document->SaveFile(file_name.c_str());
2904 
2905  delete document;
2906 }
2907 
2908 
2909 // void load(const std::string&) method
2910 
2913 
2914 void ModelSelection::load(const std::string& file_name)
2915 {
2916  tinyxml2::XMLDocument document;
2917 
2918  if(document.LoadFile(file_name.c_str()))
2919  {
2920  std::ostringstream buffer;
2921 
2922  buffer << "OpenNN Exception: ModelSelection class.\n"
2923  << "void load(const std::string&) method.\n"
2924  << "Cannot load XML file " << file_name << ".\n";
2925 
2926  throw std::logic_error(buffer.str());
2927  }
2928 
2929  from_XML(document);
2930 }
2931 
2932 // void ModelSelectionResults::save(const std::string&) const method
2933 
2936 
2937 void ModelSelection::ModelSelectionResults::save(const std::string& file_name) const
2938 {
2939  std::ofstream file(file_name.c_str());
2940 
2941  file << "% Model Selection Results\n";
2942 
2943  file << "\n% Order Selection Results\n";
2944 
2945  if(incremental_order_results_pointer)
2946  {
2947  file << incremental_order_results_pointer->to_string();
2948  }
2949 
2950  if(golden_section_order_results_pointer)
2951  {
2952  file << golden_section_order_results_pointer->to_string();
2953  }
2954 
2955  if(simulated_annealing_order_results_pointer)
2956  {
2957  file << simulated_annealing_order_results_pointer->to_string();
2958  }
2959 
2960  file << "\n% Inputs Selection Results\n";
2961 
2962  if(growing_inputs_results_pointer)
2963  {
2964  file << growing_inputs_results_pointer->to_string();
2965  }
2966 
2967  if(pruning_inputs_results_pointer)
2968  {
2969  file << pruning_inputs_results_pointer->to_string();
2970  }
2971 
2972  if(genetic_algorithm_results_pointer)
2973  {
2974  file << genetic_algorithm_results_pointer->to_string();
2975  }
2976 
2977  file << "\n% Threhold Selection Results\n";
2978 
2979  if(f1_score_opimization_results_pointer)
2980  {
2981  file << f1_score_opimization_results_pointer->to_string();
2982  }
2983 
2984  if(matthew_correlation_optimization_results_pointer)
2985  {
2986  file << matthew_correlation_optimization_results_pointer->to_string();
2987  }
2988 
2989  if(youden_index_optimization_results_pointer)
2990  {
2991  file << youden_index_optimization_results_pointer->to_string();
2992  }
2993 
2994  if(kappa_coefficient_optimization_results_pointer)
2995  {
2996  file << kappa_coefficient_optimization_results_pointer->to_string();
2997  }
2998 
2999  if(roc_curve_optimization_results_pointer)
3000  {
3001  file << roc_curve_optimization_results_pointer->to_string();
3002  }
3003 
3004  file.close();
3005 }
3006 
3007 }
void set_training_strategy_pointer(TrainingStrategy *)
const double & get_selective_pressure(void) const
Returns the selective pressure used for the fitness assignment.
const ThresholdSelectionType & get_threshold_selection_type(void) const
Returns the type of algorithm for the threshold selection.
const double & get_maximum_correlation(void) const
Return the maximum correlation for the algorithm.
void set_reserve_generation_mean(const bool &)
void from_XML(const tinyxml2::XMLDocument &)
size_t get_inputs_number(void) const
Returns the number of inputs to the neural network.
const double & get_minimum_correlation(void) const
Return the minimum correlation for the algorithm.
const InputsSelectionType & get_inputs_selection_type(void) const
Returns the type of algorithm for the inputs selection.
void set_maximum_selection_failures(const size_t &)
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
void set_display(const bool &)
KappaCoefficientOptimizationThresholdResults * perform_threshold_selection(void)
Perform the decision threshold selection optimizing the kappa coefficient.
const double & get_maximum_threshold(void) const
Returns the maximum threshold of the algorithm.
void set_reserve_generation_standard_deviation(const bool &)
Vector< double > calculate_inputs_importance(void) const
Calculate the importance of the inputs, returns a vector with the selection loss of the neural networ...
const double & get_step(void) const
Returns the step for the sucesive iterations of the algorithm.
size_t count_parameters_number(void) const
const FitnessAssignment & get_fitness_assignment_method(void) const
Returns the method for the fitness assignment of the population.
Vector< double > arrange_parameters(void) const
bool has_scaling_layer(void) const
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
void set_elitism_size(const size_t &)
const size_t & get_minimum_order(void) const
Returns the minimum of the hidden perceptrons number used in the order selection. ...
tinyxml2::XMLDocument * to_XML(void) const
const size_t & get_trials_number(void) const
Returns the number of trials for each network architecture.
const double & get_minimum_threshold(void) const
Returns the minimum threshold of the algorithm.
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
void set_maximum_selection_failures(const size_t &)
IncrementalOrder * incremental_order_pointer
Pointer to a incremental order object to be used in the order selection.
void write_XML(tinyxml2::XMLPrinter &) const
PruningInputs * pruning_inputs_pointer
Pointer to a pruning inputs object to be used in the inputs selection.
void set_mutation_rate(const double &)
ThresholdSelectionType
Enumeration of all the available types of threshold selection algorithms.
const size_t & get_maximum_selection_failures(void) const
Returns the maximum number of selection failures in the pruning inputs algorithm. ...
const double & get_minimum_threshold(void) const
Returns the minimum threshold of the algorithm.
const double & get_maximum_time(void) const
Returns the maximum time in the inputs selection algorithm.
const double & get_step(void) const
Returns the step for the sucesive iterations of the algorithm.
const double & get_mutation_rate(void) const
Returns the rate used in the mutation.
GrowingInputs::GrowingInputsResults * growing_inputs_results_pointer
Pointer to a structure with the results from the growing inputs selection algorithm.
const bool & get_reserve_function_data(void) const
Returns true if the function values to optimize are to be reserved, and false otherwise.
ThresholdSelectionType threshold_selection_type
Type of threshold selection algorithm.
IncrementalOrderResults * perform_order_selection(void)
Perform the order selection with the Incremental method.
SimulatedAnnealingOrderResults * perform_order_selection(void)
Perform the order selection with the simulated annealing method.
MatthewCorrelationOptimizationThreshold::MatthewCorrelationOptimizationThresholdResults * matthew_correlation_optimization_results_pointer
Pointer to a structure with the results from the matthew correlation optimization threshold selection...
const double & get_tolerance(void) const
Return the tolerance of error for the order selection algorithm.
const double & get_minimum_threshold(void) const
Returns the minimum threshold of the algorithm.
GeneticAlgorithm::GeneticAlgorithmResults * genetic_algorithm_results_pointer
Pointer to a structure with the results from the genetic inputs selection algorithm.
const double & get_maximum_time(void) const
Returns the maximum time in the order selection algorithm.
void set_minimum_inputs_number(const size_t &)
const double & get_minimum_threshold(void) const
Returns the minimum threshold of the algorithm.
GoldenSectionOrderResults * perform_order_selection(void)
Perform the order selection with the golden section method.
const bool & get_reserve_selection_loss_data(void) const
Returns true if the selection losss are to be reserved, and false otherwise.
InputsSelectionType inputs_selection_type
Type of inputs selection algorithm.
OrderSelectionType order_selection_type
Type of order selection algorithm.
const double & get_selection_loss_goal(void) const
Returns the goal for the selection loss in the order selection algorithm.
GeneticAlgorithm * genetic_algorithm_pointer
Pointer to a genetic algorithm object to be used in the inputs selection.
LossIndex * get_loss_index_pointer(void) const
Returns a pointer to the loss functional object to which the training strategy is associated...
const double & get_tolerance(void) const
Return the tolerance of error for the algorithm.
YoudenIndexOptimizationThresholdResults * perform_threshold_selection(void)
Perform the decision threshold selection optimizing the Youden index.
const double & get_maximum_threshold(void) const
Returns the maximum threshold of the algorithm.
const double & get_maximum_threshold(void) const
Returns the maximum threshold of the algorithm.
const size_t & get_maximum_selection_failures(void) const
Returns the maximum number of selection failures in the model order selection algorithm.
const size_t & get_elitism_size(void) const
Returns the size of the elite in the 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.
const size_t & get_maximum_selection_failures(void) const
Returns the maximum number of selection failures in the growing inputs selection algorithm.
const size_t & get_step(void) const
Returns the number of the hidden perceptrons pointed in each iteration of the Incremental algorithm...
const InitializationMethod & get_initialization_method(void) const
Returns the method for the initialization of the population.
void set_statistics(const Vector< Statistics< double > > &)
F1ScoreOptimizationThreshold * get_f1_score_optimization_threshold_pointer(void) const
Returns a pointer to the f1 score optimiztion threshold selection algorithm.
void write_XML(tinyxml2::XMLPrinter &) const
void set_default(void)
Sets the members of the model selection object to their default values.
void from_XML(const tinyxml2::XMLDocument &)
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.
void from_XML(const tinyxml2::XMLDocument &)
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 from_XML(const tinyxml2::XMLDocument &)
const double & get_maximum_threshold(void) const
Returns the maximum threshold of the algorithm.
const double & get_minimum_temperature(void) const
Returns the minimum temperature reached in the simulated annealing model order selection algorithm...
void save(const std::string &) const
void set_inputs_selection_type(const InputsSelectionType &)
CrossoverMethod
Enumeration of available methods for the crossover of the population.
MatthewCorrelationOptimizationThreshold * get_matthew_correlation_optimization_threshold(void) const
Returns a pointer to the matthew correlation optimiztion threshold selection algorithm.
void set_inicialization_method(const InitializationMethod &)
double calculate_selection_error(void) const
Returns the evaluation of the error term on the selection instances of the associated data set...
const double & get_minimum_threshold(void) const
Returns the minimum threshold of the algorithm.
void prune_input(const size_t &)
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.
const size_t & get_population_size(void) const
Returns the size of the population.
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.
PruningInputsResults * perform_inputs_selection(void)
Perform the inputs selection with the pruning inputs method.
TrainingStrategy * get_training_strategy_pointer(void) const
Returns a pointer to the training strategy object.
const size_t & get_maximum_inputs_number(void) const
Returns the maximum number of inputs in the growing inputs selection algorithm.
MatthewCorrelationOptimizationThresholdResults * perform_threshold_selection(void)
Perform the decision threshold selection optimizing the Matthew correlation.
const double & get_selection_loss_goal(void) const
Returns the goal for the selection loss in the inputs selection algorithm.
GrowingInputsResults * perform_inputs_selection(void)
Perform the inputs selection with the growing inputs method.
void set_maximum_selection_failures(const size_t &)
F1ScoreOptimizationThreshold * f1_score_optimization_threshold_pointer
Pointer to a f1 score optimization object to be used in the inputs selection.
void write_XML(tinyxml2::XMLPrinter &) const
void write_XML(tinyxml2::XMLPrinter &) const
InitializationMethod
Enumeration of available methods for the initialization of the population.
void from_XML(const tinyxml2::XMLDocument &)
void set_crossover_method(const CrossoverMethod &)
tinyxml2::XMLDocument * to_XML(void) const
YoudenIndexOptimizationThreshold * youden_index_optimization_threshold_pointer
Pointer to a youden index optimization object to be used in the threshold selection.
tinyxml2::XMLDocument * to_XML(void) const
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 set_maximum_inputs_number(const size_t &)
const bool & get_reserve_selection_loss_data(void) const
Returns true if the loss functional selection losss are to be reserved, and false otherwise...
size_t count_selection_instances_number(void) const
Returns the number of instances in the data set which will be used for selection. ...
Definition: instances.cpp:425
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.
void set_training_strategy_pointer(TrainingStrategy *)
void from_XML(const tinyxml2::XMLDocument &)
KappaCoefficientOptimizationThreshold::KappaCoefficientOptimizationThresholdResults * kappa_coefficient_optimization_results_pointer
Pointer to a structure with the results from the kappa coefficient optimization threshold selection a...
FitnessAssignment
Enumeration of available methods for the fitness assignement of the population.
const size_t & get_minimum_inputs_number(void) const
Returns the minimum number of inputs in the pruning inputs selection algorithm.
SimulatedAnnealingOrder * get_simulated_annealing_order_pointer(void) const
Returns a pointer to the simulated annealing order selection algorithm.
const bool & get_reserve_generation_standard_deviation(void) const
Returns true if the generation standard deviation of the selection losss are to be reserved...
const size_t & get_maximum_order(void) const
Returns the maximum of the hidden perceptrons number used in the order order selection.
Vector< Statistics< double > > get_statistics(void) const
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 from_XML(const tinyxml2::XMLDocument &)
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.
const double & get_maximum_threshold(void) const
Returns the maximum threshold of the algorithm.
const double & get_cooling_rate(void) const
Returns the temperature reduction factor for the simulated annealing method.
void set_fitness_assignment_method(const FitnessAssignment &)
void set_selective_pressure(const double &)
void grow_input(const Statistics< double > &new_statistics=Statistics< double >())
void set_step(const size_t &)
const double & get_step(void) const
Returns the step for the sucesive iterations of the algorithm.
void randomize_parameters_normal(void)
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...
const double & get_step(void) const
Returns the step for the sucesive iterations of the 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.
ROCCurveOptimizationThresholdResults * perform_threshold_selection(void)
Perform the decision threshold selection optimizing the ROC curve distance.
void set_threshold_selection_type(const ThresholdSelectionType &)
const bool & get_reserve_loss_data(void) const
Returns true if the loss functional losss are to be reserved, and false otherwise.
const double & get_step(void) const
Returns the step for the sucesive iterations of the algorithm.
const size_t & get_maximum_iterations_number(void) const
Returns the maximum number of iterations in the inputs selection algorithm.
void set_order_selection_type(const OrderSelectionType &)
void set_neural_network_pointer(NeuralNetwork *)
GeneticAlgorithm * get_genetic_algorithm_pointer(void) const
Returns a pointer to the genetic inputs selection algorithm.
tinyxml2::XMLDocument * to_XML(void) const
ROCCurveOptimizationThreshold::ROCCurveOptimizationThresholdResults * roc_curve_optimization_results_pointer
Pointer to a structure with the results from the roc curve optimization threshold selection algorithm...
const bool & get_reserve_loss_data(void) const
Returns true if the loss functional losss are to be reserved, and false otherwise.
const bool & get_reserve_generation_mean(void) const
Returns true if the generation mean of the selection losss are to be reserved, and false otherwise...
void set_population_size(const size_t &)
const CrossoverMethod & get_crossover_method(void) const
Returns the method for the crossover of the population.
void set_display(const bool &)
const size_t & get_trials_number(void) const
Returns the number of trials for each network architecture.
void write_XML(tinyxml2::XMLPrinter &) const
void write_XML(tinyxml2::XMLPrinter &) const
tinyxml2::XMLDocument * to_XML(void) const
YoudenIndexOptimizationThreshold::YoudenIndexOptimizationThresholdResults * youden_index_optimization_results_pointer
Pointer to a structure with the results from the youden index optimization threshold selection algori...
const size_t & get_maximum_iterations_number(void) const
Returns the maximum number of iterations in the order selection algorithm.
tinyxml2::XMLDocument * to_XML(void) const
tinyxml2::XMLDocument * to_XML(void) const
NeuralNetwork * get_neural_network_pointer(void) const
Returns a pointer to the neural network associated to the loss functional.
Definition: loss_index.h:195
void set_approximation(const bool &)
GeneticAlgorithmResults * perform_inputs_selection(void)
Perform the inputs selection with the genetic method.
F1ScoreOptimizationThresholdResults * perform_threshold_selection(void)
Perform the decision threshold selection optimizing the F1 score.
ScalingLayer * get_scaling_layer_pointer(void) const
Returns a pointer to the scaling layer composing this neural network.
void set_parameters(const Vector< double > &)