00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <string>
00019 #include <sstream>
00020 #include <iostream>
00021 #include <fstream>
00022 #include <algorithm>
00023 #include <functional>
00024 #include <cmath>
00025 #include <ctime>
00026
00027
00028
00029 #include "random_search.h"
00030
00031 namespace OpenNN
00032 {
00033
00034
00035
00039
00040 RandomSearch::RandomSearch(void)
00041 : TrainingAlgorithm()
00042 {
00043 set_default();
00044 }
00045
00046
00047
00048
00053
00054 RandomSearch::RandomSearch(PerformanceFunctional* new_performance_functional_pointer)
00055 : TrainingAlgorithm(new_performance_functional_pointer)
00056 {
00057 set_default();
00058 }
00059
00060
00061
00062
00067
00068 RandomSearch::RandomSearch(TiXmlElement* random_search_element) : TrainingAlgorithm(random_search_element)
00069 {
00070 from_XML(random_search_element);
00071 }
00072
00073
00074
00075
00078
00079 RandomSearch::~RandomSearch(void)
00080 {
00081
00082 }
00083
00084
00085
00086
00088
00089 const double& RandomSearch::get_warning_parameters_norm(void) const
00090 {
00091 return(warning_parameters_norm);
00092 }
00093
00094
00095
00096
00098
00099 const double& RandomSearch::get_warning_training_rate(void) const
00100 {
00101 return(warning_training_rate);
00102 }
00103
00104
00105
00106
00109
00110 const double& RandomSearch::get_error_parameters_norm(void) const
00111 {
00112 return(error_parameters_norm);
00113 }
00114
00115
00116
00117
00120
00121 const double& RandomSearch::get_error_training_rate(void) const
00122 {
00123 return(error_training_rate);
00124 }
00125
00126
00127
00128
00130
00131 const double& RandomSearch::get_minimum_parameters_increment_norm(void) const
00132 {
00133 return(minimum_parameters_increment_norm);
00134 }
00135
00136
00137
00138
00140
00141 const double& RandomSearch::get_minimum_performance_increase(void) const
00142 {
00143 return(minimum_performance_increase);
00144 }
00145
00146
00147
00148
00151
00152 const double& RandomSearch::get_performance_goal(void) const
00153 {
00154 return(performance_goal);
00155 }
00156
00157
00158
00159
00161
00162 const unsigned int& RandomSearch::get_maximum_generalization_evaluation_decreases(void) const
00163 {
00164 return(maximum_generalization_evaluation_decreases);
00165 }
00166
00167
00168
00169
00171
00172 const unsigned int& RandomSearch::get_maximum_epochs_number(void) const
00173 {
00174 return(maximum_epochs_number);
00175 }
00176
00177
00178
00179
00181
00182 const double& RandomSearch::get_maximum_time(void) const
00183 {
00184 return(maximum_time);
00185 }
00186
00187
00188
00189
00191
00192 const bool& RandomSearch::get_reserve_parameters_history(void) const
00193 {
00194 return(reserve_parameters_history);
00195 }
00196
00197
00198
00199
00201
00202 const bool& RandomSearch::get_reserve_parameters_norm_history(void) const
00203 {
00204 return(reserve_parameters_norm_history);
00205 }
00206
00207
00208
00209
00211
00212 const bool& RandomSearch::get_reserve_evaluation_history(void) const
00213 {
00214 return(reserve_evaluation_history);
00215 }
00216
00217
00218
00219
00221
00222 const bool& RandomSearch::get_reserve_training_direction_history(void) const
00223 {
00224 return(reserve_training_direction_history);
00225 }
00226
00227
00228
00229
00231
00232 const bool& RandomSearch::get_reserve_training_rate_history(void) const
00233 {
00234 return(reserve_training_rate_history);
00235 }
00236
00237
00238
00239
00241
00242 const bool& RandomSearch::get_reserve_elapsed_time_history(void) const
00243 {
00244 return(reserve_elapsed_time_history);
00245 }
00246
00247
00248
00249
00251
00252 const bool& RandomSearch::get_reserve_generalization_evaluation_history(void) const
00253 {
00254 return(reserve_generalization_evaluation_history);
00255 }
00256
00257
00258
00259
00261
00262 const unsigned int& RandomSearch::get_display_period(void) const
00263 {
00264 return(display_period);
00265 }
00266
00267
00268
00269
00271
00272 const double& RandomSearch::get_training_rate_reduction_factor(void) const
00273 {
00274 return(training_rate_reduction_factor);
00275 }
00276
00277
00278
00279
00281
00282 const unsigned int& RandomSearch::get_training_rate_reduction_period(void) const
00283 {
00284 return(training_rate_reduction_period);
00285 }
00286
00287
00288
00289
00305
00306 void RandomSearch::set_default(void)
00307 {
00308
00309
00310 first_training_rate = 0.01;
00311
00312 training_rate_reduction_factor = 0.9;
00313 training_rate_reduction_period = 10;
00314
00315
00316
00317 minimum_performance_increase = 0.0;
00318 performance_goal = -1.0e99;
00319
00320 maximum_epochs_number = 100;
00321 maximum_time = 1000.0;
00322
00323
00324
00325 reserve_parameters_history = false;
00326 reserve_parameters_norm_history = false;
00327
00328 reserve_evaluation_history = true;
00329
00330 reserve_training_direction_history = false;
00331 reserve_training_rate_history = false;
00332 reserve_elapsed_time_history = false;
00333
00334
00335
00336 display = true;
00337 display_period = 10;
00338 }
00339
00340
00341
00342
00345
00346 void RandomSearch::set_training_rate_reduction_factor(const double& new_training_rate_reduction_factor)
00347 {
00348 training_rate_reduction_factor = new_training_rate_reduction_factor;
00349 }
00350
00351
00352
00353
00356
00357 void RandomSearch::set_training_rate_reduction_period(const unsigned int& new_training_rate_reduction_period)
00358 {
00359 training_rate_reduction_period = new_training_rate_reduction_period;
00360 }
00361
00362
00363
00364
00367
00368 void RandomSearch::set_reserve_parameters_history(const bool& new_reserve_parameters_history)
00369 {
00370 reserve_parameters_history = new_reserve_parameters_history;
00371 }
00372
00373
00374
00375
00379
00380 void RandomSearch::set_reserve_parameters_norm_history(const bool& new_reserve_parameters_norm_history)
00381 {
00382 reserve_parameters_norm_history = new_reserve_parameters_norm_history;
00383 }
00384
00385
00386
00387
00391
00392 void RandomSearch::set_reserve_evaluation_history(const bool& new_reserve_evaluation_history)
00393 {
00394 reserve_evaluation_history = new_reserve_evaluation_history;
00395 }
00396
00397
00398
00399
00403
00404 void RandomSearch::set_reserve_all_training_history(const bool& new_reserve_all_training_history)
00405 {
00406
00407
00408 reserve_parameters_history = new_reserve_all_training_history;
00409 reserve_parameters_norm_history = new_reserve_all_training_history;
00410
00411
00412
00413 reserve_evaluation_history = new_reserve_all_training_history;
00414 reserve_evaluation_history = new_reserve_all_training_history;
00415
00416
00417
00418 reserve_elapsed_time_history = new_reserve_all_training_history;
00419 }
00420
00421
00422
00423
00427
00428 void RandomSearch::set_warning_parameters_norm(const double& new_warning_parameters_norm)
00429 {
00430
00431
00432 #ifdef _DEBUG
00433
00434 if(new_warning_parameters_norm < 0.0)
00435 {
00436 std::ostringstream buffer;
00437
00438 buffer << "OpenNN Exception: RandomSearch class.\n"
00439 << "void set_warning_parameters_norm(const double&) method.\n"
00440 << "Warning parameters norm must be equal or greater than 0.\n";
00441
00442 throw std::logic_error(buffer.str().c_str());
00443 }
00444
00445 #endif
00446
00447
00448
00449 warning_parameters_norm = new_warning_parameters_norm;
00450 }
00451
00452
00453
00454
00455
00459
00460 void RandomSearch::set_warning_training_rate(const double& new_warning_training_rate)
00461 {
00462
00463
00464 #ifdef _DEBUG
00465
00466 if(new_warning_training_rate < 0.0)
00467 {
00468 std::ostringstream buffer;
00469
00470 buffer << "OpenNN Exception: RandomSearch class.\n"
00471 << "void set_warning_training_rate(const double&) method.\n"
00472 << "Warning training rate must be equal or greater than 0.\n";
00473
00474 throw std::logic_error(buffer.str().c_str());
00475 }
00476
00477 #endif
00478
00479 warning_training_rate = new_warning_training_rate;
00480 }
00481
00482
00483
00484
00488
00489 void RandomSearch::set_error_parameters_norm(const double& new_error_parameters_norm)
00490 {
00491
00492
00493 #ifdef _DEBUG
00494
00495 if(new_error_parameters_norm < 0.0)
00496 {
00497 std::ostringstream buffer;
00498
00499 buffer << "OpenNN Exception: RandomSearch class.\n"
00500 << "void set_error_parameters_norm(const double&) method.\n"
00501 << "Error parameters norm must be equal or greater than 0.\n";
00502
00503 throw std::logic_error(buffer.str().c_str());
00504 }
00505
00506 #endif
00507
00508
00509
00510 error_parameters_norm = new_error_parameters_norm;
00511 }
00512
00513
00514
00515
00519
00520 void RandomSearch::set_error_training_rate(const double& new_error_training_rate)
00521 {
00522
00523
00524 #ifdef _DEBUG
00525
00526 if(new_error_training_rate < 0.0)
00527 {
00528 std::ostringstream buffer;
00529
00530 buffer << "OpenNN Exception: RandomSearch class.\n"
00531 << "void set_error_training_rate(const double&) method.\n"
00532 << "Error training rate must be equal or greater than 0.\n";
00533
00534 throw std::logic_error(buffer.str().c_str());
00535 }
00536
00537 #endif
00538
00539
00540
00541 error_training_rate = new_error_training_rate;
00542 }
00543
00544
00545
00546
00549
00550 void RandomSearch::set_minimum_parameters_increment_norm(const double& new_minimum_parameters_increment_norm)
00551 {
00552
00553
00554 #ifdef _DEBUG
00555
00556 if(new_minimum_parameters_increment_norm < 0.0)
00557 {
00558 std::ostringstream buffer;
00559
00560 buffer << "OpenNN Exception: RandomSearch class.\n"
00561 << "void new_minimum_parameters_increment_norm(const double&) method.\n"
00562 << "Minimum parameters increment norm must be equal or greater than 0.\n";
00563
00564 throw std::logic_error(buffer.str().c_str());
00565 }
00566
00567 #endif
00568
00569
00570
00571 minimum_parameters_increment_norm = new_minimum_parameters_increment_norm;
00572 }
00573
00574
00575
00576
00579
00580 void RandomSearch::set_minimum_performance_increase(const double& new_minimum_performance_increase)
00581 {
00582
00583
00584 #ifdef _DEBUG
00585
00586 if(new_minimum_performance_increase < 0.0)
00587 {
00588 std::ostringstream buffer;
00589
00590 buffer << "OpenNN Exception: RandomSearch class.\n"
00591 << "void set_minimum_performance_increase(const double&) method.\n"
00592 << "Minimum performance improvement must be equal or greater than 0.\n";
00593
00594 throw std::logic_error(buffer.str().c_str());
00595 }
00596
00597 #endif
00598
00599
00600
00601 minimum_performance_increase = new_minimum_performance_increase;
00602 }
00603
00604
00605
00606
00610
00611 void RandomSearch::set_performance_goal(const double& new_performance_goal)
00612 {
00613 performance_goal = new_performance_goal;
00614 }
00615
00616
00617
00618
00621
00622 void RandomSearch::set_maximum_generalization_evaluation_decreases(const unsigned int& new_maximum_generalization_evaluation_decreases)
00623 {
00624
00625
00626 #ifdef _DEBUG
00627
00628 if(new_maximum_generalization_evaluation_decreases < 0)
00629 {
00630 std::ostringstream buffer;
00631
00632 buffer << "OpenNN Exception: RandomSearch class.\n"
00633 << "void set_maximum_generalization_evaluation_decreases(const unsigned int&) method.\n"
00634 << "Number of generalization performance decreases must be equal or greater than 0.\n";
00635
00636 throw std::logic_error(buffer.str().c_str());
00637 }
00638
00639 #endif
00640
00641
00642
00643 maximum_generalization_evaluation_decreases = new_maximum_generalization_evaluation_decreases;
00644 }
00645
00646
00647
00648
00651
00652 void RandomSearch::set_maximum_epochs_number(const unsigned int& new_maximum_epochs_number)
00653 {
00654
00655
00656 #ifdef _DEBUG
00657
00658 if(new_maximum_epochs_number < 0)
00659 {
00660 std::ostringstream buffer;
00661
00662 buffer << "OpenNN Exception: RandomSearch class.\n"
00663 << "void set_maximum_epochs_number(const unsigned int&) method.\n"
00664 << "Number of epochs must be equal or greater than 0.\n";
00665
00666 throw std::logic_error(buffer.str().c_str());
00667 }
00668
00669 #endif
00670
00671
00672
00673 maximum_epochs_number = new_maximum_epochs_number;
00674 }
00675
00676
00677
00678
00681
00682 void RandomSearch::set_maximum_time(const double& new_maximum_time)
00683 {
00684
00685
00686 #ifdef _DEBUG
00687
00688 if(new_maximum_time < 0.0)
00689 {
00690 std::ostringstream buffer;
00691
00692 buffer << "OpenNN Exception: RandomSearch class.\n"
00693 << "void set_maximum_time(const double&) method.\n"
00694 << "Maximum time must be equal or greater than 0.\n";
00695
00696 throw std::logic_error(buffer.str().c_str());
00697 }
00698
00699 #endif
00700
00701
00702
00703 maximum_time = new_maximum_time;
00704 }
00705
00706
00707
00708
00712
00713 void RandomSearch::set_reserve_training_direction_history(const bool& new_reserve_training_direction_history)
00714 {
00715 reserve_training_direction_history = new_reserve_training_direction_history;
00716 }
00717
00718
00719
00720
00724
00725 void RandomSearch::set_reserve_training_rate_history(const bool& new_reserve_training_rate_history)
00726 {
00727 reserve_training_rate_history = new_reserve_training_rate_history;
00728 }
00729
00730
00731
00732
00736
00737 void RandomSearch::set_reserve_elapsed_time_history(const bool& new_reserve_elapsed_time_history)
00738 {
00739 reserve_elapsed_time_history = new_reserve_elapsed_time_history;
00740 }
00741
00742
00743
00744
00748
00749 void RandomSearch::set_reserve_generalization_evaluation_history(const bool& new_reserve_generalization_evaluation_history)
00750 {
00751 reserve_generalization_evaluation_history = new_reserve_generalization_evaluation_history;
00752 }
00753
00754
00755
00756
00760
00761 void RandomSearch::set_display_period(const unsigned int& new_display_period)
00762 {
00763
00764
00765 #ifdef _DEBUG
00766
00767 if(new_display_period <= 0)
00768 {
00769 std::ostringstream buffer;
00770
00771 buffer << "OpenNN Exception: RandomSearch class.\n"
00772 << "void set_display_period(const double&) method.\n"
00773 << "First training rate must be greater than 0.\n";
00774
00775 throw std::logic_error(buffer.str().c_str());
00776 }
00777
00778 #endif
00779
00780 display_period = new_display_period;
00781 }
00782
00783
00784
00785
00786
00788
00789 Vector<double> RandomSearch::calculate_training_direction(void)
00790 {
00791 const NeuralNetwork* neural_network_pointer = performance_functional_pointer->get_neural_network_pointer();
00792
00793 unsigned int parameters_number = neural_network_pointer->count_parameters_number();
00794
00795 Vector<double> random(parameters_number);
00796 double random_norm;
00797
00798 do
00799 {
00800 random.initialize_uniform();
00801 random_norm = random.calculate_norm();
00802 }while(random_norm > 1.0);
00803
00804 return(random/random_norm);
00805 }
00806
00807
00808
00809
00812
00813 void RandomSearch::RandomSearchResults::resize_training_history(const unsigned int& new_size)
00814 {
00815 parameters_history.resize(new_size);
00816 parameters_norm_history.resize(new_size);
00817
00818 evaluation_history.resize(new_size);
00819 generalization_evaluation_history.resize(new_size);
00820
00821 training_direction_history.resize(new_size);
00822 training_rate_history.resize(new_size);
00823 elapsed_time_history.resize(new_size);
00824 }
00825
00826
00827
00828
00830
00831 std::string RandomSearch::RandomSearchResults::to_string(void) const
00832 {
00833 std::ostringstream buffer;
00834
00835
00836
00837 if(!parameters_history.empty())
00838 {
00839 if(!parameters_history.empty())
00840 {
00841 buffer << "% Parameters history:\n"
00842 << parameters_history << "\n";
00843 }
00844 }
00845
00846
00847
00848 if(!parameters_norm_history.empty())
00849 {
00850 buffer << "% Parameters norm history:\n"
00851 << parameters_norm_history << "\n";
00852 }
00853
00854
00855
00856 if(!evaluation_history.empty())
00857 {
00858 buffer << "% Evaluation history:\n"
00859 << evaluation_history << "\n";
00860 }
00861
00862
00863
00864 if(!generalization_evaluation_history.empty())
00865 {
00866 buffer << "% Generalization evaluation history:\n"
00867 << generalization_evaluation_history << "\n";
00868 }
00869
00870
00871
00872 if(!training_direction_history.empty())
00873 {
00874 if(!training_direction_history[0].empty())
00875 {
00876 buffer << "% Training direction history:\n"
00877 << training_direction_history << "\n";
00878 }
00879 }
00880
00881
00882
00883 if(!training_rate_history.empty())
00884 {
00885 buffer << "% Training rate history:\n"
00886 << training_rate_history << "\n";
00887 }
00888
00889
00890
00891 if(!elapsed_time_history.empty())
00892 {
00893 buffer << "% Elapsed time history:\n"
00894 << elapsed_time_history << "\n";
00895 }
00896
00897 return(buffer.str());
00898 }
00899
00900
00901
00902
00905
00906 RandomSearch::RandomSearchResults* RandomSearch::perform_training(void)
00907 {
00908
00909
00910 #ifdef _DEBUG
00911
00912 check();
00913
00914 #endif
00915
00916 RandomSearchResults* random_search_training_results_pointer = new RandomSearchResults;
00917
00918
00919
00920 if(display)
00921 {
00922 std::cout << "Training with random search...\n";
00923 }
00924
00925 random_search_training_results_pointer->resize_training_history(1+maximum_epochs_number);
00926
00927
00928
00929 time_t beginning_time, current_time;
00930 time(&beginning_time);
00931 double elapsed_time;
00932
00933
00934
00935 NeuralNetwork* neural_network_pointer = performance_functional_pointer->get_neural_network_pointer();
00936
00937 #ifdef _DEBUG
00938
00939 if(neural_network_pointer == NULL)
00940 {
00941 std::ostringstream buffer;
00942
00943 buffer << "OpenNN Exception: RandomSearch class.\n"
00944 << "RandomSearchResults* perform_training(void) method.\n"
00945 << "Pointer to neural network in performance functional is NULL.\n";
00946
00947 throw std::logic_error(buffer.str().c_str());
00948 }
00949
00950 #endif
00951
00952 const unsigned int parameters_number = neural_network_pointer->count_parameters_number();
00953
00954 Vector<double> parameters(parameters_number);
00955
00956 double parameters_norm = 0.0;
00957
00958
00959
00960 double performance = 0.0;
00961
00962
00963
00964 Vector<double> training_direction(parameters_number);
00965 double training_rate = 0.0;
00966
00967 Vector<double> parameters_increment(parameters_number);
00968
00969 bool stop_training = false;
00970
00971
00972
00973 for(unsigned int epoch = 0; epoch <= maximum_epochs_number; epoch++)
00974 {
00975 if(epoch == 0)
00976 {
00977 parameters = neural_network_pointer->arrange_parameters();
00978
00979 parameters_norm = parameters.calculate_norm();
00980 }
00981
00982
00983
00984 if(epoch == 0)
00985 {
00986 performance = performance_functional_pointer->calculate_evaluation();
00987 }
00988 else
00989 {
00990 performance = performance_functional_pointer->calculate_evaluation(parameters);
00991 }
00992
00993 if(performance < performance)
00994 {
00995 parameters = parameters;
00996
00997 neural_network_pointer->set_parameters(parameters);
00998
00999 performance = performance;
01000 }
01001
01002
01003
01004 training_direction = calculate_training_direction();
01005
01006 if(epoch == 0)
01007 {
01008 training_rate = 1.0;
01009 }
01010 else if(epoch%training_rate_reduction_period == 0)
01011 {
01012 training_rate *= training_rate_reduction_factor;
01013 }
01014
01015 parameters_increment = training_direction*training_rate;
01016
01017
01018
01019 time(¤t_time);
01020 elapsed_time = difftime(current_time, beginning_time);
01021
01022
01023
01024 if(reserve_parameters_history)
01025 {
01026 random_search_training_results_pointer->parameters_history[epoch] = parameters;
01027 }
01028
01029 if(reserve_parameters_history)
01030 {
01031 random_search_training_results_pointer->parameters_history[epoch] = parameters;
01032 }
01033
01034 if(reserve_parameters_norm_history)
01035 {
01036 random_search_training_results_pointer->parameters_norm_history[epoch] = parameters_norm;
01037 }
01038
01039 if(reserve_parameters_norm_history)
01040 {
01041 random_search_training_results_pointer->parameters_norm_history[epoch] = parameters_norm;
01042 }
01043
01044
01045
01046 if(reserve_evaluation_history)
01047 {
01048 random_search_training_results_pointer->evaluation_history[epoch] = performance;
01049 }
01050
01051 if(reserve_evaluation_history)
01052 {
01053 random_search_training_results_pointer->evaluation_history[epoch] = performance;
01054 }
01055
01056
01057
01058 if(reserve_training_direction_history)
01059 {
01060 random_search_training_results_pointer->training_direction_history[epoch] = training_direction;
01061 }
01062
01063 if(reserve_training_rate_history)
01064 {
01065 random_search_training_results_pointer->training_rate_history[epoch] = training_rate;
01066 }
01067
01068 if(reserve_elapsed_time_history)
01069 {
01070 random_search_training_results_pointer->elapsed_time_history[epoch] = elapsed_time;
01071 }
01072
01073
01074
01075 if(performance <= performance_goal)
01076 {
01077 if(display)
01078 {
01079 std::cout << "Epoch " << epoch << ": Performance goal reached.\n";
01080 }
01081
01082 stop_training = true;
01083 }
01084
01085 else if(epoch == maximum_epochs_number)
01086 {
01087 if(display)
01088 {
01089 std::cout << "Epoch " << epoch << ": Maximum number of epochs reached.\n";
01090 }
01091
01092 stop_training = true;
01093 }
01094
01095 else if(elapsed_time >= maximum_time)
01096 {
01097 if(display)
01098 {
01099 std::cout << "Epoch " << epoch << ": Maximum training time reached.\n";
01100 }
01101
01102 stop_training = true;
01103 }
01104
01105 if(stop_training)
01106 {
01107 random_search_training_results_pointer->final_parameters = parameters;
01108 random_search_training_results_pointer->final_parameters_norm = parameters_norm;
01109
01110 random_search_training_results_pointer->final_evaluation = performance;
01111
01112
01113 random_search_training_results_pointer->final_training_direction = training_direction;
01114 random_search_training_results_pointer->final_training_rate = training_rate;
01115 random_search_training_results_pointer->elapsed_time = elapsed_time;
01116
01117 if(display)
01118 {
01119 std::cout << "Potential parameters norm: " << parameters_norm << "\n"
01120 << "Parameters norm: " << parameters_norm << "\n"
01121 << "Potential performance: " << performance << "\n"
01122 << "Performance: " << performance << "\n"
01123 << performance_functional_pointer->write_information()
01124 << "Training rate: " << training_rate << "\n"
01125 << "Elapsed time: " << elapsed_time << std::endl;
01126 }
01127
01128 break;
01129 }
01130
01131 else if(display && epoch % display_period == 0)
01132 {
01133 std::cout << "Epoch " << epoch << ";\n"
01134 << "Potential parameters norm: " << parameters_norm << "\n"
01135 << "Parameters norm: " << parameters_norm << "\n"
01136 << "Potential performance: " << performance << "\n"
01137 << "Performance: " << performance << "\n"
01138 << performance_functional_pointer->write_information()
01139 << "Training rate: " << training_rate << "\n"
01140 << "Elapsed time: " << elapsed_time << std::endl;
01141 }
01142
01143
01144
01145 parameters = parameters + parameters_increment;
01146 parameters_norm = parameters.calculate_norm();
01147 }
01148
01149 return(random_search_training_results_pointer);
01150 }
01151
01152
01153
01154
01155 std::string RandomSearch::write_training_algorithm_type(void) const
01156 {
01157 return("RANDOM_SEARCH");
01158 }
01159
01160
01161
01162
01165
01166 TiXmlElement* RandomSearch::to_XML(void) const
01167 {
01168 std::ostringstream buffer;
01169
01170
01171
01172 TiXmlElement* random_search_element = new TiXmlElement("RandomSearch");
01173 random_search_element->SetAttribute("Version", 4);
01174
01175
01176
01177 TiXmlElement* training_rate_reduction_factor_element = new TiXmlElement("TrainingRateReductionFactor");
01178 random_search_element->LinkEndChild(training_rate_reduction_factor_element);
01179
01180 buffer.str("");
01181 buffer << training_rate_reduction_factor;
01182
01183 TiXmlText* training_rate_reduction_factor_text = new TiXmlText(buffer.str().c_str());
01184 training_rate_reduction_factor_element->LinkEndChild(training_rate_reduction_factor_text);
01185
01186
01187
01188 TiXmlElement* training_rate_reduction_period_element = new TiXmlElement("TrainingRateReductionPeriod");
01189 random_search_element->LinkEndChild(training_rate_reduction_period_element);
01190
01191 buffer.str("");
01192 buffer << training_rate_reduction_period;
01193
01194 TiXmlText* training_rate_reduction_period_text = new TiXmlText(buffer.str().c_str());
01195 training_rate_reduction_period_element->LinkEndChild(training_rate_reduction_period_text);
01196
01197
01198
01199 TiXmlElement* first_training_rate_element = new TiXmlElement("FirstTrainingRate");
01200 random_search_element->LinkEndChild(first_training_rate_element);
01201
01202 buffer.str("");
01203 buffer << first_training_rate;
01204
01205 TiXmlText* first_training_rate_text = new TiXmlText(buffer.str().c_str());
01206 first_training_rate_element->LinkEndChild(first_training_rate_text);
01207
01208
01209
01210 TiXmlElement* warning_parameters_norm_element = new TiXmlElement("WarningParametersNorm");
01211 random_search_element->LinkEndChild(warning_parameters_norm_element);
01212
01213 buffer.str("");
01214 buffer << warning_parameters_norm;
01215
01216 TiXmlText* warning_parameters_norm_text = new TiXmlText(buffer.str().c_str());
01217 warning_parameters_norm_element->LinkEndChild(warning_parameters_norm_text);
01218
01219
01220
01221 TiXmlElement* warning_training_rate_element = new TiXmlElement("WarningTrainingRate");
01222 random_search_element->LinkEndChild(warning_training_rate_element);
01223
01224 buffer.str("");
01225 buffer << warning_training_rate;
01226
01227 TiXmlText* warning_training_rate_text = new TiXmlText(buffer.str().c_str());
01228 warning_training_rate_element->LinkEndChild(warning_training_rate_text);
01229
01230
01231
01232 TiXmlElement* error_parameters_norm_element = new TiXmlElement("ErrorParametersNorm");
01233 random_search_element->LinkEndChild(error_parameters_norm_element);
01234
01235 buffer.str("");
01236 buffer << error_parameters_norm;
01237
01238 TiXmlText* error_parameters_norm_text = new TiXmlText(buffer.str().c_str());
01239 error_parameters_norm_element->LinkEndChild(error_parameters_norm_text);
01240
01241
01242
01243 TiXmlElement* error_training_rate_element = new TiXmlElement("ErrorTrainingRate");
01244 random_search_element->LinkEndChild(error_training_rate_element);
01245
01246 buffer.str("");
01247 buffer << error_training_rate;
01248
01249 TiXmlText* error_training_rate_text = new TiXmlText(buffer.str().c_str());
01250 error_training_rate_element->LinkEndChild(error_training_rate_text);
01251
01252
01253
01254 TiXmlElement* performance_goal_element = new TiXmlElement("PerformanceGoal");
01255 random_search_element->LinkEndChild(performance_goal_element);
01256
01257 buffer.str("");
01258 buffer << performance_goal;
01259
01260 TiXmlText* performance_goal_text = new TiXmlText(buffer.str().c_str());
01261 performance_goal_element->LinkEndChild(performance_goal_text);
01262
01263
01264
01265 TiXmlElement* maximum_epochs_number_element = new TiXmlElement("MaximumEpochsNumber");
01266 random_search_element->LinkEndChild(maximum_epochs_number_element);
01267
01268 buffer.str("");
01269 buffer << maximum_epochs_number;
01270
01271 TiXmlText* maximum_epochs_number_text = new TiXmlText(buffer.str().c_str());
01272 maximum_epochs_number_element->LinkEndChild(maximum_epochs_number_text);
01273
01274
01275
01276 TiXmlElement* maximum_time_element = new TiXmlElement("MaximumTime");
01277 random_search_element->LinkEndChild(maximum_time_element);
01278
01279 buffer.str("");
01280 buffer << maximum_time;
01281
01282 TiXmlText* maximum_time_text = new TiXmlText(buffer.str().c_str());
01283 maximum_time_element->LinkEndChild(maximum_time_text);
01284
01285
01286
01287 TiXmlElement* reserve_parameters_history_element = new TiXmlElement("ReserveParametersHistory");
01288 random_search_element->LinkEndChild(reserve_parameters_history_element);
01289
01290 buffer.str("");
01291 buffer << reserve_parameters_history;
01292
01293 TiXmlText* reserve_parameters_history_text = new TiXmlText(buffer.str().c_str());
01294 reserve_parameters_history_element->LinkEndChild(reserve_parameters_history_text);
01295
01296
01297
01298 TiXmlElement* reserve_parameters_norm_history_element = new TiXmlElement("ReserveParametersNormHistory");
01299 random_search_element->LinkEndChild(reserve_parameters_norm_history_element);
01300
01301 buffer.str("");
01302 buffer << reserve_parameters_norm_history;
01303
01304 TiXmlText* reserve_parameters_norm_history_text = new TiXmlText(buffer.str().c_str());
01305 reserve_parameters_norm_history_element->LinkEndChild(reserve_parameters_norm_history_text);
01306
01307
01308
01309 TiXmlElement* reserve_evaluation_history_element = new TiXmlElement("ReservePerformanceHistory");
01310 random_search_element->LinkEndChild(reserve_evaluation_history_element);
01311
01312 buffer.str("");
01313 buffer << reserve_evaluation_history;
01314
01315 TiXmlText* reserve_evaluation_history_text = new TiXmlText(buffer.str().c_str());
01316 reserve_evaluation_history_element->LinkEndChild(reserve_evaluation_history_text);
01317
01318
01319
01320 TiXmlElement* reserve_training_direction_history_element = new TiXmlElement("ReserveTrainingDirectionHistory");
01321 random_search_element->LinkEndChild(reserve_training_direction_history_element);
01322
01323 buffer.str("");
01324 buffer << reserve_training_direction_history;
01325
01326 TiXmlText* reserve_training_direction_history_text = new TiXmlText(buffer.str().c_str());
01327 reserve_training_direction_history_element->LinkEndChild(reserve_training_direction_history_text);
01328
01329
01330
01331 TiXmlElement* reserve_training_rate_history_element = new TiXmlElement("ReserveTrainingRateHistory");
01332 random_search_element->LinkEndChild(reserve_training_rate_history_element);
01333
01334 buffer.str("");
01335 buffer << reserve_training_rate_history;
01336
01337 TiXmlText* reserve_training_rate_history_text = new TiXmlText(buffer.str().c_str());
01338 reserve_training_rate_history_element->LinkEndChild(reserve_training_rate_history_text);
01339
01340
01341
01342 TiXmlElement* reserve_elapsed_time_history_element = new TiXmlElement("ReserveElapsedTimeHistory");
01343 random_search_element->LinkEndChild(reserve_elapsed_time_history_element);
01344
01345 buffer.str("");
01346 buffer << reserve_elapsed_time_history;
01347
01348 TiXmlText* reserve_elapsed_time_history_text = new TiXmlText(buffer.str().c_str());
01349 reserve_elapsed_time_history_element->LinkEndChild(reserve_elapsed_time_history_text);
01350
01351
01352
01353 TiXmlElement* reserve_generalization_evaluation_history_element = new TiXmlElement("ReserveGeneralizationPerformanceHistory");
01354 random_search_element->LinkEndChild(reserve_generalization_evaluation_history_element);
01355
01356 buffer.str("");
01357 buffer << reserve_generalization_evaluation_history;
01358
01359 TiXmlText* reserve_generalization_evaluation_history_text = new TiXmlText(buffer.str().c_str());
01360 reserve_generalization_evaluation_history_element->LinkEndChild(reserve_generalization_evaluation_history_text);
01361
01362
01363
01364 TiXmlElement* display_period_element = new TiXmlElement("DisplayPeriod");
01365 random_search_element->LinkEndChild(display_period_element);
01366
01367 buffer.str("");
01368 buffer << display_period;
01369
01370 TiXmlText* display_period_text = new TiXmlText(buffer.str().c_str());
01371 display_period_element->LinkEndChild(display_period_text);
01372
01373
01374
01375 TiXmlElement* display_element = new TiXmlElement("Display");
01376 random_search_element->LinkEndChild(display_element);
01377
01378 buffer.str("");
01379 buffer << display;
01380
01381 TiXmlText* display_text = new TiXmlText(buffer.str().c_str());
01382 display_element->LinkEndChild(display_text);
01383
01384 return(random_search_element);
01385 }
01386
01387
01388
01389
01390 void RandomSearch::from_XML(TiXmlElement*)
01391 {
01392
01393 }
01394
01395 }
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413