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 <cmath>
00022
00023
00024
00025 #include "../utilities/vector.h"
00026 #include "../utilities/matrix.h"
00027
00028 #include "../utilities/numerical_differentiation.h"
00029
00030 #include "performance_functional.h"
00031 #include "sum_squared_error.h"
00032 #include "mean_squared_error.h"
00033 #include "root_mean_squared_error.h"
00034 #include "normalized_squared_error.h"
00035 #include "minkowski_error.h"
00036 #include "cross_entropy_error.h"
00037
00038 #include "inverse_sum_squared_error.h"
00039
00040 #include "neural_parameters_norm.h"
00041 #include "outputs_integrals.h"
00042 #include "independent_parameters_error.h"
00043
00044 #include "final_solutions_error.h"
00045 #include "solutions_error.h"
00046
00047
00048
00049 #include "../../parsers/tinyxml/tinyxml.h"
00050
00051
00052 namespace OpenNN
00053 {
00054
00055
00056
00060
00061 PerformanceFunctional::PerformanceFunctional(void)
00062 : neural_network_pointer(NULL)
00063 , objective_term_pointer(NULL)
00064 , regularization_term_pointer(NULL)
00065 , constraints_term_pointer(NULL)
00066 {
00067 set_default();
00068
00069 construct_objective_term(objective_term_type);
00070 }
00071
00072
00073
00074
00080
00081 PerformanceFunctional::PerformanceFunctional(NeuralNetwork* new_neural_network_pointer)
00082 : neural_network_pointer(new_neural_network_pointer)
00083 , objective_term_pointer(NULL)
00084 , regularization_term_pointer(NULL)
00085 , constraints_term_pointer(NULL)
00086 {
00087 set_default();
00088
00089 construct_objective_term(objective_term_type);
00090 }
00091
00092
00093
00094
00101
00102 PerformanceFunctional::PerformanceFunctional(NeuralNetwork* new_neural_network_pointer, DataSet* new_data_set_pointer)
00103 : neural_network_pointer(new_neural_network_pointer)
00104 , objective_term_pointer(NULL)
00105 , regularization_term_pointer(NULL)
00106 , constraints_term_pointer(NULL)
00107 {
00108 set_default();
00109
00110 construct_objective_term(objective_term_type);
00111 objective_term_pointer->set_data_set_pointer(new_data_set_pointer);
00112 }
00113
00114
00115
00116
00123
00124 PerformanceFunctional::PerformanceFunctional(NeuralNetwork* new_neural_network_pointer, MathematicalModel* new_mathematical_model_pointer)
00125 : neural_network_pointer(new_neural_network_pointer)
00126 , objective_term_pointer(NULL)
00127 , regularization_term_pointer(NULL)
00128 , constraints_term_pointer(NULL)
00129 {
00130 set_default();
00131
00132 construct_objective_term(objective_term_type);
00133 objective_term_pointer->set_mathematical_model_pointer(new_mathematical_model_pointer);
00134 }
00135
00136
00137
00138
00146
00147 PerformanceFunctional::PerformanceFunctional(NeuralNetwork* new_neural_network_pointer, MathematicalModel* new_mathematical_model_pointer, DataSet* new_data_set_pointer)
00148 : neural_network_pointer(new_neural_network_pointer)
00149 , objective_term_pointer(NULL)
00150 , regularization_term_pointer(NULL)
00151 , constraints_term_pointer(NULL)
00152 {
00153 set_default();
00154
00155 construct_objective_term(objective_term_type, new_mathematical_model_pointer, new_data_set_pointer);
00156 }
00157
00158
00159
00160
00165
00166 PerformanceFunctional::PerformanceFunctional(PerformanceTerm* new_objective_term_pointer)
00167 : neural_network_pointer(NULL)
00168 , objective_term_pointer(new_objective_term_pointer)
00169 , regularization_term_pointer(NULL)
00170 , constraints_term_pointer(NULL)
00171 {
00172 set_default();
00173
00174 objective_term_type = PerformanceFunctional::USER_PERFORMANCE_TERM;
00175 }
00176
00177
00178
00179
00184
00185 PerformanceFunctional::PerformanceFunctional(const std::string& filename)
00186 : neural_network_pointer(NULL)
00187 , objective_term_pointer(NULL)
00188 , regularization_term_pointer(NULL)
00189 , constraints_term_pointer(NULL)
00190 {
00191 set_default();
00192
00193 load(filename);
00194 }
00195
00196
00197
00198
00203
00204 PerformanceFunctional::PerformanceFunctional(const PerformanceFunctional& other_performance_functional)
00205 : neural_network_pointer(NULL)
00206 , objective_term_pointer(NULL)
00207 , regularization_term_pointer(NULL)
00208 , constraints_term_pointer(NULL)
00209 {
00210 neural_network_pointer = other_performance_functional.neural_network_pointer;
00211
00212 objective_term_type = other_performance_functional.objective_term_type;
00213 regularization_term_type = other_performance_functional.regularization_term_type;
00214 constraints_term_type = other_performance_functional.constraints_term_type;
00215
00216 if(other_performance_functional.objective_term_pointer)
00217 {
00218 construct_objective_term(objective_term_type);
00219
00220 objective_term_pointer->set(*other_performance_functional.objective_term_pointer);
00221 }
00222
00223 if(other_performance_functional.regularization_term_pointer)
00224 {
00225 construct_regularization_term(regularization_term_type);
00226
00227 regularization_term_pointer->set(*other_performance_functional.regularization_term_pointer);
00228 }
00229
00230 if(other_performance_functional.constraints_term_pointer)
00231 {
00232 construct_constraints_term(constraints_term_type);
00233
00234 constraints_term_pointer->set(*other_performance_functional.constraints_term_pointer);
00235 }
00236
00237 objective_term_flag = other_performance_functional.objective_term_flag;
00238
00239 regularization_term_flag = other_performance_functional.regularization_term_flag;
00240
00241 constraints_term_flag = other_performance_functional.constraints_term_flag;
00242
00243 display = other_performance_functional.display;
00244 }
00245
00246
00247
00248
00251
00252 PerformanceFunctional::~PerformanceFunctional(void)
00253 {
00254 delete objective_term_pointer;
00255 delete regularization_term_pointer;
00256 delete constraints_term_pointer;
00257 }
00258
00259
00260
00261
00262
00263
00265
00266 const PerformanceFunctional::PerformanceTermType& PerformanceFunctional::get_objective_term_type(void) const
00267 {
00268 return(objective_term_type);
00269 }
00270
00271
00272
00273
00275
00276 const PerformanceFunctional::PerformanceTermType& PerformanceFunctional::get_regularization_term_type(void) const
00277 {
00278 return(regularization_term_type);
00279 }
00280
00281
00282
00283
00285
00286 const PerformanceFunctional::PerformanceTermType& PerformanceFunctional::get_constraints_term_type(void) const
00287 {
00288 return(constraints_term_type);
00289 }
00290
00291
00292
00293
00295
00296 std::string PerformanceFunctional::write_objective_term_type(void) const
00297 {
00298 if(objective_term_type == NONE)
00299 {
00300 return("NONE");
00301 }
00302 else if(objective_term_type == SUM_SQUARED_ERROR)
00303 {
00304 return("SUM_SQUARED_ERROR");
00305 }
00306 else if(objective_term_type == MEAN_SQUARED_ERROR)
00307 {
00308 return("MEAN_SQUARED_ERROR");
00309 }
00310 else if(objective_term_type == ROOT_MEAN_SQUARED_ERROR)
00311 {
00312 return("ROOT_MEAN_SQUARED_ERROR");
00313 }
00314 else if(objective_term_type == NORMALIZED_SQUARED_ERROR)
00315 {
00316 return("NORMALIZED_SQUARED_ERROR");
00317 }
00318 else if(objective_term_type == MINKOWSKI_ERROR)
00319 {
00320 return("MINKOWSKI_ERROR");
00321 }
00322 else if(objective_term_type == CROSS_ENTROPY_ERROR)
00323 {
00324 return("CROSS_ENTROPY_ERROR");
00325 }
00326 else if(objective_term_type == NEURAL_PARAMETERS_NORM)
00327 {
00328 return("NEURAL_PARAMETERS_NORM");
00329 }
00330 else if(objective_term_type == OUTPUTS_INTEGRALS)
00331 {
00332 return("OUTPUTS_INTEGRALS");
00333 }
00334 else if(objective_term_type == SOLUTION_ERROR)
00335 {
00336 return("SOLUTION_ERROR");
00337 }
00338 else if(objective_term_type == FINAL_SOLUTIONS_ERROR)
00339 {
00340 return("FINAL_SOLUTIONS_ERROR");
00341 }
00342 else if(objective_term_type == INDEPENDENT_PARAMETERS_ERROR)
00343 {
00344 return("INDEPENDENT_PARAMETERS_ERROR");
00345 }
00346 else if(objective_term_type == INVERSE_SUM_SQUARED_ERROR)
00347 {
00348 return("INVERSE_SUM_SQUARED_ERROR");
00349 }
00350 else if(objective_term_type == USER_PERFORMANCE_TERM)
00351 {
00352 return("USER_PERFORMANCE_TERM");
00353 }
00354 else
00355 {
00356 std::ostringstream buffer;
00357
00358 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
00359 << "std::string write_objective_term_type(void) const method.\n"
00360 << "Unknown performance term type.\n";
00361
00362 throw std::logic_error(buffer.str());
00363 }
00364 }
00365
00366
00367
00368
00370
00371 std::string PerformanceFunctional::write_regularization_term_type(void) const
00372 {
00373 if(regularization_term_type == NONE)
00374 {
00375 return("NONE");
00376 }
00377 else if(regularization_term_type == SUM_SQUARED_ERROR)
00378 {
00379 return("SUM_SQUARED_ERROR");
00380 }
00381 else if(regularization_term_type == MEAN_SQUARED_ERROR)
00382 {
00383 return("MEAN_SQUARED_ERROR");
00384 }
00385 else if(regularization_term_type == ROOT_MEAN_SQUARED_ERROR)
00386 {
00387 return("ROOT_MEAN_SQUARED_ERROR");
00388 }
00389 else if(regularization_term_type == NORMALIZED_SQUARED_ERROR)
00390 {
00391 return("NORMALIZED_SQUARED_ERROR");
00392 }
00393 else if(regularization_term_type == MINKOWSKI_ERROR)
00394 {
00395 return("MINKOWSKI_ERROR");
00396 }
00397 else if(regularization_term_type == CROSS_ENTROPY_ERROR)
00398 {
00399 return("CROSS_ENTROPY_ERROR");
00400 }
00401 else if(regularization_term_type == NEURAL_PARAMETERS_NORM)
00402 {
00403 return("NEURAL_PARAMETERS_NORM");
00404 }
00405 else if(regularization_term_type == OUTPUTS_INTEGRALS)
00406 {
00407 return("OUTPUTS_INTEGRALS");
00408 }
00409 else if(regularization_term_type == SOLUTION_ERROR)
00410 {
00411 return("SOLUTION_ERROR");
00412 }
00413 else if(regularization_term_type == FINAL_SOLUTIONS_ERROR)
00414 {
00415 return("FINAL_SOLUTIONS_ERROR");
00416 }
00417 else if(regularization_term_type == INDEPENDENT_PARAMETERS_ERROR)
00418 {
00419 return("INDEPENDENT_PARAMETERS_ERROR");
00420 }
00421 else if(regularization_term_type == INVERSE_SUM_SQUARED_ERROR)
00422 {
00423 return("INVERSE_SUM_SQUARED_ERROR");
00424 }
00425 else if(regularization_term_type == USER_PERFORMANCE_TERM)
00426 {
00427 return("USER_PERFORMANCE_TERM");
00428 }
00429 else
00430 {
00431 std::ostringstream buffer;
00432
00433 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
00434 << "std::string write_regularization_term_type(void) const method.\n"
00435 << "Unknown performance term type.\n";
00436
00437 throw std::logic_error(buffer.str());
00438 }
00439 }
00440
00441
00442
00443
00445
00446 std::string PerformanceFunctional::write_constraints_term_type(void) const
00447 {
00448 if(constraints_term_type == NONE)
00449 {
00450 return("NONE");
00451 }
00452 else if(constraints_term_type == SUM_SQUARED_ERROR)
00453 {
00454 return("SUM_SQUARED_ERROR");
00455 }
00456 else if(constraints_term_type == MEAN_SQUARED_ERROR)
00457 {
00458 return("MEAN_SQUARED_ERROR");
00459 }
00460 else if(constraints_term_type == ROOT_MEAN_SQUARED_ERROR)
00461 {
00462 return("ROOT_MEAN_SQUARED_ERROR");
00463 }
00464 else if(constraints_term_type == NORMALIZED_SQUARED_ERROR)
00465 {
00466 return("NORMALIZED_SQUARED_ERROR");
00467 }
00468 else if(constraints_term_type == MINKOWSKI_ERROR)
00469 {
00470 return("MINKOWSKI_ERROR");
00471 }
00472 else if(constraints_term_type == CROSS_ENTROPY_ERROR)
00473 {
00474 return("CROSS_ENTROPY_ERROR");
00475 }
00476 else if(constraints_term_type == NEURAL_PARAMETERS_NORM)
00477 {
00478 return("NEURAL_PARAMETERS_NORM");
00479 }
00480 else if(constraints_term_type == OUTPUTS_INTEGRALS)
00481 {
00482 return("OUTPUTS_INTEGRALS");
00483 }
00484 else if(constraints_term_type == SOLUTION_ERROR)
00485 {
00486 return("SOLUTION_ERROR");
00487 }
00488 else if(constraints_term_type == FINAL_SOLUTIONS_ERROR)
00489 {
00490 return("FINAL_SOLUTIONS_ERROR");
00491 }
00492 else if(constraints_term_type == INDEPENDENT_PARAMETERS_ERROR)
00493 {
00494 return("INDEPENDENT_PARAMETERS_ERROR");
00495 }
00496 else if(constraints_term_type == INVERSE_SUM_SQUARED_ERROR)
00497 {
00498 return("INVERSE_SUM_SQUARED_ERROR");
00499 }
00500 else if(constraints_term_type == USER_PERFORMANCE_TERM)
00501 {
00502 return("USER_PERFORMANCE_TERM");
00503 }
00504 else
00505 {
00506 std::ostringstream buffer;
00507
00508 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
00509 << "std::string write_constraints_term_type(void) const method.\n"
00510 << "Unknown performance term type.\n";
00511
00512 throw std::logic_error(buffer.str());
00513 }
00514 }
00515
00516
00517
00518
00520
00521 const bool& PerformanceFunctional::get_objective_term_flag(void) const
00522 {
00523 return(objective_term_flag);
00524 }
00525
00526
00527
00528
00530
00531 const bool& PerformanceFunctional::get_regularization_term_flag(void) const
00532 {
00533 return(regularization_term_flag);
00534 }
00535
00536
00537
00538
00541
00542 const bool& PerformanceFunctional::get_constraints_term_flag(void) const
00543 {
00544 return(constraints_term_flag);
00545 }
00546
00547
00548
00549
00552
00553 const bool& PerformanceFunctional::get_display(void) const
00554 {
00555 return(display);
00556 }
00557
00558
00559
00560
00563
00564 void PerformanceFunctional::set_neural_network_pointer(NeuralNetwork* new_neural_network_pointer)
00565 {
00566 neural_network_pointer = new_neural_network_pointer;
00567 }
00568
00569
00570
00571
00574
00575 void PerformanceFunctional::set_objective_term_pointer(PerformanceTerm* new_objective_term_pointer)
00576 {
00577 destruct_objective_term();
00578
00579 objective_term_pointer = new_objective_term_pointer;
00580
00581 objective_term_flag = true;
00582
00583 std::string objective_term_type = new_objective_term_pointer->write_performance_term_type();
00584
00585 set_objective_term_type(objective_term_type);
00586 }
00587
00588
00589
00590
00593
00594 void PerformanceFunctional::set_regularization_term_pointer(PerformanceTerm* new_regularization_term_pointer)
00595 {
00596 destruct_regularization_term();
00597
00598 regularization_term_pointer = new_regularization_term_pointer;
00599
00600 regularization_term_flag = true;
00601
00602 std::string regularization_term_type = new_regularization_term_pointer->write_performance_term_type();
00603
00604 set_regularization_term_type(regularization_term_type);
00605 }
00606
00607
00608
00609
00612
00613 void PerformanceFunctional::set_constraints_term_pointer(PerformanceTerm* new_constraints_term_pointer)
00614 {
00615 destruct_constraints_term();
00616
00617 constraints_term_pointer = new_constraints_term_pointer;
00618
00619 constraints_term_flag = true;
00620
00621 std::string constraints_term_type = new_constraints_term_pointer->write_performance_term_type();
00622
00623 set_constraints_term_type(constraints_term_type);
00624 }
00625
00626
00627
00628
00630
00631 void PerformanceFunctional::set_default(void)
00632 {
00633 set_objective_term_type(NORMALIZED_SQUARED_ERROR);
00634 set_regularization_term_type(NONE);
00635 set_constraints_term_type(NONE);
00636
00637 objective_term_flag = true;
00638 regularization_term_flag = false;
00639 constraints_term_flag = false;
00640
00641 display = true;
00642 }
00643
00644
00645
00646
00649
00650 void PerformanceFunctional::set_objective_term_type(const PerformanceTermType& new_objective_term_type)
00651 {
00652 objective_term_type = new_objective_term_type;
00653 }
00654
00655
00656
00657
00660
00661 void PerformanceFunctional::set_regularization_term_type(const PerformanceTermType& new_regularization_term_type)
00662 {
00663 regularization_term_type = new_regularization_term_type;
00664 }
00665
00666
00667
00668
00671
00672 void PerformanceFunctional::set_constraints_term_type(const PerformanceTermType& new_constraints_term_type)
00673 {
00674 constraints_term_type = new_constraints_term_type;
00675 }
00676
00677
00678
00679
00682
00683 void PerformanceFunctional::set_objective_term_type(const std::string& new_objective_term_type)
00684 {
00685 if(new_objective_term_type == "NONE")
00686 {
00687 set_objective_term_type(NONE);
00688 }
00689 else if(new_objective_term_type == "SUM_SQUARED_ERROR")
00690 {
00691 set_objective_term_type(SUM_SQUARED_ERROR);
00692 }
00693 else if(new_objective_term_type == "MEAN_SQUARED_ERROR")
00694 {
00695 set_objective_term_type(MEAN_SQUARED_ERROR);
00696 }
00697 else if(new_objective_term_type == "ROOT_MEAN_SQUARED_ERROR")
00698 {
00699 set_objective_term_type(ROOT_MEAN_SQUARED_ERROR);
00700 }
00701 else if(new_objective_term_type == "NORMALIZED_SQUARED_ERROR")
00702 {
00703 set_objective_term_type(NORMALIZED_SQUARED_ERROR);
00704 }
00705 else if(new_objective_term_type == "MINKOWSKI_ERROR")
00706 {
00707 set_objective_term_type(MINKOWSKI_ERROR);
00708 }
00709 else if(new_objective_term_type == "MINKOWSKI_ERROR")
00710 {
00711 set_objective_term_type(MINKOWSKI_ERROR);
00712 }
00713 else if(new_objective_term_type == "NEURAL_PARAMETERS_NORM")
00714 {
00715 set_objective_term_type(NEURAL_PARAMETERS_NORM);
00716 }
00717 else if(new_objective_term_type == "OUTPUTS_INTEGRALS")
00718 {
00719 set_objective_term_type(OUTPUTS_INTEGRALS);
00720 }
00721 else if(new_objective_term_type == "SOLUTION_ERROR")
00722 {
00723 set_objective_term_type(SOLUTION_ERROR);
00724 }
00725 else if(new_objective_term_type == "FINAL_SOLUTIONS_ERROR")
00726 {
00727 set_objective_term_type(FINAL_SOLUTIONS_ERROR);
00728 }
00729 else if(new_objective_term_type == "INDEPENDENT_PARAMETERS_ERROR")
00730 {
00731 set_objective_term_type(INDEPENDENT_PARAMETERS_ERROR);
00732 }
00733 else if(new_objective_term_type == "INVERSE_SUM_SQUARED_ERROR")
00734 {
00735 set_objective_term_type(INVERSE_SUM_SQUARED_ERROR);
00736 }
00737 else if(new_objective_term_type == "USER_PERFORMANCE_TERM")
00738 {
00739 set_objective_term_type(USER_PERFORMANCE_TERM);
00740 }
00741 else
00742 {
00743 std::ostringstream buffer;
00744
00745 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
00746 << "void set_objective_term_type(const std::string&) method.\n"
00747 << "Unknown performance term type: " << new_objective_term_type << ".\n";
00748
00749 throw std::logic_error(buffer.str());
00750 }
00751 }
00752
00753
00754
00755
00758
00759 void PerformanceFunctional::set_regularization_term_type(const std::string& new_regularization_term_type)
00760 {
00761 if(new_regularization_term_type == "NONE")
00762 {
00763 set_regularization_term_type(NONE);
00764 }
00765 else if(new_regularization_term_type == "SUM_SQUARED_ERROR")
00766 {
00767 set_regularization_term_type(SUM_SQUARED_ERROR);
00768 }
00769 else if(new_regularization_term_type == "MEAN_SQUARED_ERROR")
00770 {
00771 set_regularization_term_type(MEAN_SQUARED_ERROR);
00772 }
00773 else if(new_regularization_term_type == "ROOT_MEAN_SQUARED_ERROR")
00774 {
00775 set_regularization_term_type(ROOT_MEAN_SQUARED_ERROR);
00776 }
00777 else if(new_regularization_term_type == "NORMALIZED_SQUARED_ERROR")
00778 {
00779 set_regularization_term_type(NORMALIZED_SQUARED_ERROR);
00780 }
00781 else if(new_regularization_term_type == "MINKOWSKI_ERROR")
00782 {
00783 set_regularization_term_type(MINKOWSKI_ERROR);
00784 }
00785 else if(new_regularization_term_type == "MINKOWSKI_ERROR")
00786 {
00787 set_regularization_term_type(MINKOWSKI_ERROR);
00788 }
00789 else if(new_regularization_term_type == "NEURAL_PARAMETERS_NORM")
00790 {
00791 set_regularization_term_type(NEURAL_PARAMETERS_NORM);
00792 }
00793 else if(new_regularization_term_type == "OUTPUTS_INTEGRALS")
00794 {
00795 set_regularization_term_type(OUTPUTS_INTEGRALS);
00796 }
00797 else if(new_regularization_term_type == "SOLUTION_ERROR")
00798 {
00799 set_regularization_term_type(SOLUTION_ERROR);
00800 }
00801 else if(new_regularization_term_type == "FINAL_SOLUTIONS_ERROR")
00802 {
00803 set_regularization_term_type(FINAL_SOLUTIONS_ERROR);
00804 }
00805 else if(new_regularization_term_type == "INDEPENDENT_PARAMETERS_ERROR")
00806 {
00807 set_regularization_term_type(INDEPENDENT_PARAMETERS_ERROR);
00808 }
00809 else if(new_regularization_term_type == "INVERSE_SUM_SQUARED_ERROR")
00810 {
00811 set_regularization_term_type(INVERSE_SUM_SQUARED_ERROR);
00812 }
00813 else if(new_regularization_term_type == "USER_PERFORMANCE_TERM")
00814 {
00815 set_regularization_term_type(USER_PERFORMANCE_TERM);
00816 }
00817 else
00818 {
00819 std::ostringstream buffer;
00820
00821 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
00822 << "void set_regularization_term_type(const std::string&) method.\n"
00823 << "Unknown performance functional type: " << new_regularization_term_type << ".\n";
00824
00825 throw std::logic_error(buffer.str());
00826 }
00827 }
00828
00829
00830
00831
00834
00835 void PerformanceFunctional::set_constraints_term_type(const std::string& new_constraints_term_type)
00836 {
00837 if(new_constraints_term_type == "NONE")
00838 {
00839 set_constraints_term_type(NONE);
00840 }
00841 else if(new_constraints_term_type == "SUM_SQUARED_ERROR")
00842 {
00843 set_constraints_term_type(SUM_SQUARED_ERROR);
00844 }
00845 else if(new_constraints_term_type == "MEAN_SQUARED_ERROR")
00846 {
00847 set_constraints_term_type(MEAN_SQUARED_ERROR);
00848 }
00849 else if(new_constraints_term_type == "ROOT_MEAN_SQUARED_ERROR")
00850 {
00851 set_constraints_term_type(ROOT_MEAN_SQUARED_ERROR);
00852 }
00853 else if(new_constraints_term_type == "NORMALIZED_SQUARED_ERROR")
00854 {
00855 set_constraints_term_type(NORMALIZED_SQUARED_ERROR);
00856 }
00857 else if(new_constraints_term_type == "MINKOWSKI_ERROR")
00858 {
00859 set_constraints_term_type(MINKOWSKI_ERROR);
00860 }
00861 else if(new_constraints_term_type == "MINKOWSKI_ERROR")
00862 {
00863 set_constraints_term_type(MINKOWSKI_ERROR);
00864 }
00865 else if(new_constraints_term_type == "NEURAL_PARAMETERS_NORM")
00866 {
00867 set_constraints_term_type(NEURAL_PARAMETERS_NORM);
00868 }
00869 else if(new_constraints_term_type == "OUTPUTS_INTEGRALS")
00870 {
00871 set_constraints_term_type(OUTPUTS_INTEGRALS);
00872 }
00873 else if(new_constraints_term_type == "SOLUTION_ERROR")
00874 {
00875 set_constraints_term_type(SOLUTION_ERROR);
00876 }
00877 else if(new_constraints_term_type == "FINAL_SOLUTIONS_ERROR")
00878 {
00879 set_constraints_term_type(FINAL_SOLUTIONS_ERROR);
00880 }
00881 else if(new_constraints_term_type == "INDEPENDENT_PARAMETERS_ERROR")
00882 {
00883 set_constraints_term_type(INDEPENDENT_PARAMETERS_ERROR);
00884 }
00885 else if(new_constraints_term_type == "INVERSE_SUM_SQUARED_ERROR")
00886 {
00887 set_constraints_term_type(INVERSE_SUM_SQUARED_ERROR);
00888 }
00889 else if(new_constraints_term_type == "USER_PERFORMANCE_TERM")
00890 {
00891 set_constraints_term_type(USER_PERFORMANCE_TERM);
00892 }
00893 else
00894 {
00895 std::ostringstream buffer;
00896
00897 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
00898 << "void set_constraints_term_type(const std::string&) method.\n"
00899 << "Unknown performance term type: " << new_constraints_term_type << ".\n";
00900
00901 throw std::logic_error(buffer.str());
00902 }
00903 }
00904
00905
00906
00907
00910
00911 void PerformanceFunctional::set_objective_term_flag(const bool& new_objective_term_flag)
00912 {
00913 objective_term_flag = new_objective_term_flag;
00914 }
00915
00916
00917
00918
00921
00922 void PerformanceFunctional::set_regularization_term_flag(const bool& new_regularization_term_flag)
00923 {
00924 regularization_term_flag = new_regularization_term_flag;
00925 }
00926
00927
00928
00929
00932
00933 void PerformanceFunctional::set_constraints_term_flag(const bool& new_constraints_term_flag)
00934 {
00935 constraints_term_flag = new_constraints_term_flag;
00936 }
00937
00938
00939
00940
00945
00946 void PerformanceFunctional::set_display(const bool& new_display)
00947 {
00948 display = new_display;
00949 }
00950
00951
00952
00953
00956
00957 void PerformanceFunctional::construct_objective_term(const PerformanceTermType& new_objective_term_type)
00958 {
00959 if(objective_term_pointer)
00960 {
00961 delete objective_term_pointer;
00962 }
00963
00964 objective_term_type = new_objective_term_type;
00965 objective_term_flag = true;
00966
00967 switch(new_objective_term_type)
00968 {
00969 case NONE:
00970 {
00971 objective_term_pointer = NULL;
00972 }
00973 break;
00974
00975 case SUM_SQUARED_ERROR:
00976 {
00977 objective_term_pointer = new SumSquaredError(neural_network_pointer);
00978 }
00979 break;
00980
00981 case MEAN_SQUARED_ERROR:
00982 {
00983 objective_term_pointer = new MeanSquaredError(neural_network_pointer);
00984 }
00985 break;
00986
00987 case ROOT_MEAN_SQUARED_ERROR:
00988 {
00989 objective_term_pointer = new RootMeanSquaredError(neural_network_pointer);
00990 }
00991 break;
00992
00993 case NORMALIZED_SQUARED_ERROR:
00994 {
00995 objective_term_pointer = new NormalizedSquaredError(neural_network_pointer);
00996 }
00997 break;
00998
00999 case MINKOWSKI_ERROR:
01000 {
01001 objective_term_pointer = new MinkowskiError(neural_network_pointer);
01002 }
01003 break;
01004
01005 case CROSS_ENTROPY_ERROR:
01006 {
01007 objective_term_pointer = new CrossEntropyError(neural_network_pointer);
01008 }
01009 break;
01010
01011 case NEURAL_PARAMETERS_NORM:
01012 {
01013 objective_term_pointer = new NeuralParametersNorm(neural_network_pointer);
01014 }
01015 break;
01016
01017 case OUTPUTS_INTEGRALS:
01018 {
01019 objective_term_pointer = new OutputsIntegrals(neural_network_pointer);
01020 }
01021 break;
01022
01023 case SOLUTION_ERROR:
01024 {
01025 objective_term_pointer = new SolutionsError(neural_network_pointer);
01026 }
01027 break;
01028
01029 case FINAL_SOLUTIONS_ERROR:
01030 {
01031 objective_term_pointer = new FinalSolutionsError(neural_network_pointer);
01032 }
01033 break;
01034
01035 case INDEPENDENT_PARAMETERS_ERROR:
01036 {
01037 objective_term_pointer = new IndependentParametersError(neural_network_pointer);
01038 }
01039 break;
01040
01041 case INVERSE_SUM_SQUARED_ERROR:
01042 {
01043 objective_term_pointer = new InverseSumSquaredError(neural_network_pointer);
01044 }
01045 break;
01046
01047 case USER_PERFORMANCE_TERM:
01048 {
01049 objective_term_pointer = NULL;
01050 }
01051 break;
01052
01053 default:
01054 {
01055 std::ostringstream buffer;
01056
01057 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01058 << "void construct_objective_term(const PerformanceTermType&) method.\n"
01059 << "Unknown performance term type.\n";
01060
01061 throw std::logic_error(buffer.str().c_str());
01062 }
01063 break;
01064 }
01065 }
01066
01067
01068
01069
01072
01073 void PerformanceFunctional::construct_regularization_term(const PerformanceTermType& new_regularization_term_type)
01074 {
01075 if(regularization_term_pointer)
01076 {
01077 delete regularization_term_pointer;
01078 }
01079
01080 regularization_term_type = new_regularization_term_type;
01081 regularization_term_flag = true;
01082
01083 switch(regularization_term_type)
01084 {
01085 case NONE:
01086 {
01087 regularization_term_pointer = NULL;
01088 }
01089 break;
01090
01091 case SUM_SQUARED_ERROR:
01092 {
01093 regularization_term_pointer = new SumSquaredError(neural_network_pointer);
01094 }
01095 break;
01096
01097 case MEAN_SQUARED_ERROR:
01098 {
01099 regularization_term_pointer = new MeanSquaredError(neural_network_pointer);
01100 }
01101 break;
01102
01103 case ROOT_MEAN_SQUARED_ERROR:
01104 {
01105 regularization_term_pointer = new RootMeanSquaredError(neural_network_pointer);
01106 }
01107 break;
01108
01109 case NORMALIZED_SQUARED_ERROR:
01110 {
01111 regularization_term_pointer = new NormalizedSquaredError(neural_network_pointer);
01112 }
01113 break;
01114
01115 case MINKOWSKI_ERROR:
01116 {
01117 regularization_term_pointer = new MinkowskiError(neural_network_pointer);
01118 }
01119 break;
01120
01121 case CROSS_ENTROPY_ERROR:
01122 {
01123 regularization_term_pointer = new CrossEntropyError(neural_network_pointer);
01124 }
01125 break;
01126
01127 case NEURAL_PARAMETERS_NORM:
01128 {
01129 regularization_term_pointer = new NeuralParametersNorm(neural_network_pointer);
01130 }
01131 break;
01132
01133 case OUTPUTS_INTEGRALS:
01134 {
01135 regularization_term_pointer = new OutputsIntegrals(neural_network_pointer);
01136 }
01137 break;
01138
01139 case SOLUTION_ERROR:
01140 {
01141 regularization_term_pointer = new SolutionsError(neural_network_pointer);
01142 }
01143 break;
01144
01145 case FINAL_SOLUTIONS_ERROR:
01146 {
01147 regularization_term_pointer = new FinalSolutionsError(neural_network_pointer);
01148 }
01149 break;
01150
01151 case INDEPENDENT_PARAMETERS_ERROR:
01152 {
01153 regularization_term_pointer = new IndependentParametersError(neural_network_pointer);
01154 }
01155 break;
01156
01157 case INVERSE_SUM_SQUARED_ERROR:
01158 {
01159 regularization_term_pointer = new InverseSumSquaredError(neural_network_pointer);
01160 }
01161 break;
01162
01163 case USER_PERFORMANCE_TERM:
01164 {
01165 regularization_term_pointer = NULL;
01166 }
01167 break;
01168
01169 default:
01170 {
01171 std::ostringstream buffer;
01172
01173 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01174 << "void set_regularization_term_type(const PerformanceTermType&) method.\n"
01175 << "Unknown performance term type.\n";
01176
01177 throw std::logic_error(buffer.str().c_str());
01178 }
01179 break;
01180 }
01181 }
01182
01183
01184
01185
01188
01189 void PerformanceFunctional::construct_constraints_term(const PerformanceTermType& new_constraints_term_type)
01190 {
01191 if(constraints_term_pointer)
01192 {
01193 delete constraints_term_pointer;
01194 }
01195
01196 constraints_term_type = new_constraints_term_type;
01197 constraints_term_flag = true;
01198
01199 switch(constraints_term_type)
01200 {
01201 case NONE:
01202 {
01203 constraints_term_pointer = NULL;
01204 }
01205 break;
01206
01207 case SUM_SQUARED_ERROR:
01208 {
01209 constraints_term_pointer = new SumSquaredError(neural_network_pointer);
01210 }
01211 break;
01212
01213 case MEAN_SQUARED_ERROR:
01214 {
01215 constraints_term_pointer = new MeanSquaredError(neural_network_pointer);
01216 }
01217 break;
01218
01219 case ROOT_MEAN_SQUARED_ERROR:
01220 {
01221 constraints_term_pointer = new RootMeanSquaredError(neural_network_pointer);
01222 }
01223 break;
01224
01225 case NORMALIZED_SQUARED_ERROR:
01226 {
01227 constraints_term_pointer = new NormalizedSquaredError(neural_network_pointer);
01228 }
01229 break;
01230
01231 case MINKOWSKI_ERROR:
01232 {
01233 constraints_term_pointer = new MinkowskiError(neural_network_pointer);
01234 }
01235 break;
01236
01237 case CROSS_ENTROPY_ERROR:
01238 {
01239 constraints_term_pointer = new CrossEntropyError(neural_network_pointer);
01240 }
01241 break;
01242
01243 case NEURAL_PARAMETERS_NORM:
01244 {
01245 constraints_term_pointer = new NeuralParametersNorm(neural_network_pointer);
01246 }
01247 break;
01248
01249 case OUTPUTS_INTEGRALS:
01250 {
01251 constraints_term_pointer = new OutputsIntegrals(neural_network_pointer);
01252 }
01253 break;
01254
01255 case SOLUTION_ERROR:
01256 {
01257 constraints_term_pointer = new SolutionsError(neural_network_pointer);
01258 }
01259 break;
01260
01261 case FINAL_SOLUTIONS_ERROR:
01262 {
01263 constraints_term_pointer = new FinalSolutionsError(neural_network_pointer);
01264 }
01265 break;
01266
01267 case INDEPENDENT_PARAMETERS_ERROR:
01268 {
01269 constraints_term_pointer = new IndependentParametersError(neural_network_pointer);
01270 }
01271 break;
01272
01273 case INVERSE_SUM_SQUARED_ERROR:
01274 {
01275 constraints_term_pointer = new InverseSumSquaredError(neural_network_pointer);
01276 }
01277 break;
01278
01279 case USER_PERFORMANCE_TERM:
01280 {
01281 constraints_term_pointer = NULL;
01282 }
01283 break;
01284
01285 default:
01286 {
01287 std::ostringstream buffer;
01288
01289 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01290 << "void set_constraints_term_type(const PerformanceTermType&) method.\n"
01291 << "Unknown performance term type.\n";
01292
01293 throw std::logic_error(buffer.str().c_str());
01294 }
01295 break;
01296 }
01297 }
01298
01299
01300
01301
01305
01306 void PerformanceFunctional::construct_objective_term(const PerformanceTermType& new_performance_term_type, MathematicalModel* new_mathematical_model_pointer)
01307 {
01308 construct_objective_term(new_performance_term_type);
01309
01310 objective_term_pointer->set_mathematical_model_pointer(new_mathematical_model_pointer);
01311 }
01312
01313
01314
01315
01319
01320 void PerformanceFunctional::construct_regularization_term(const PerformanceTermType& new_performance_term_type, MathematicalModel* new_mathematical_model_pointer)
01321 {
01322 construct_regularization_term(new_performance_term_type);
01323
01324 regularization_term_pointer->set_mathematical_model_pointer(new_mathematical_model_pointer);
01325 }
01326
01327
01328
01329
01333
01334 void PerformanceFunctional::construct_constraints_term(const PerformanceTermType& new_performance_term_type, MathematicalModel* new_mathematical_model_pointer)
01335 {
01336 construct_constraints_term(new_performance_term_type);
01337
01338 constraints_term_pointer->set_mathematical_model_pointer(new_mathematical_model_pointer);
01339 }
01340
01341
01342
01343
01347
01348 void PerformanceFunctional::construct_objective_term(const PerformanceTermType& new_performance_term_type, DataSet* new_data_set_pointer)
01349 {
01350 construct_objective_term(new_performance_term_type);
01351
01352 objective_term_pointer->set_data_set_pointer(new_data_set_pointer);
01353 }
01354
01355
01356
01357
01361
01362 void PerformanceFunctional::construct_regularization_term(const PerformanceTermType& new_performance_term_type, DataSet* new_data_set_pointer)
01363 {
01364 construct_regularization_term(new_performance_term_type);
01365
01366 regularization_term_pointer->set_data_set_pointer(new_data_set_pointer);
01367 }
01368
01369
01370
01371
01375
01376 void PerformanceFunctional::construct_constraints_term(const PerformanceTermType& new_performance_term_type, DataSet* new_data_set_pointer)
01377 {
01378 construct_constraints_term(new_performance_term_type);
01379
01380 constraints_term_pointer->set_data_set_pointer(new_data_set_pointer);
01381 }
01382
01383
01384
01385
01390
01391 void PerformanceFunctional::construct_objective_term(const PerformanceTermType& new_performance_term_type, MathematicalModel* new_mathematical_model_pointer, DataSet* new_data_set_pointer)
01392 {
01393 construct_objective_term(new_performance_term_type);
01394
01395 objective_term_pointer->set_mathematical_model_pointer(new_mathematical_model_pointer);
01396 objective_term_pointer->set_data_set_pointer(new_data_set_pointer);
01397 }
01398
01399
01400
01401
01406
01407 void PerformanceFunctional::construct_regularization_term(const PerformanceTermType& new_performance_term_type, MathematicalModel* new_mathematical_model_pointer, DataSet* new_data_set_pointer)
01408 {
01409 construct_regularization_term(new_performance_term_type);
01410
01411 regularization_term_pointer->set_mathematical_model_pointer(new_mathematical_model_pointer);
01412 regularization_term_pointer->set_data_set_pointer(new_data_set_pointer);
01413 }
01414
01415
01416
01417
01422
01423 void PerformanceFunctional::construct_constraints_term(const PerformanceTermType& new_performance_term_type, MathematicalModel* new_mathematical_model_pointer, DataSet* new_data_set_pointer)
01424 {
01425 construct_constraints_term(new_performance_term_type);
01426
01427 constraints_term_pointer->set_mathematical_model_pointer(new_mathematical_model_pointer);
01428 constraints_term_pointer->set_data_set_pointer(new_data_set_pointer);
01429 }
01430
01431
01432
01433
01436
01437 void PerformanceFunctional::construct_objective_term(const std::string& new_objective_term_type)
01438 {
01439 if(new_objective_term_type == "NONE")
01440 {
01441 construct_objective_term(NONE);
01442 }
01443 else if(new_objective_term_type == "SUM_SQUARED_ERROR")
01444 {
01445 construct_objective_term(SUM_SQUARED_ERROR);
01446 }
01447 else if(new_objective_term_type == "MEAN_SQUARED_ERROR")
01448 {
01449 construct_objective_term(MEAN_SQUARED_ERROR);
01450 }
01451 else if(new_objective_term_type == "ROOT_MEAN_SQUARED_ERROR")
01452 {
01453 construct_objective_term(ROOT_MEAN_SQUARED_ERROR);
01454 }
01455 else if(new_objective_term_type == "NORMALIZED_SQUARED_ERROR")
01456 {
01457 construct_objective_term(NORMALIZED_SQUARED_ERROR);
01458 }
01459 else if(new_objective_term_type == "MINKOWSKI_ERROR")
01460 {
01461 construct_objective_term(MINKOWSKI_ERROR);
01462 }
01463 else if(new_objective_term_type == "MINKOWSKI_ERROR")
01464 {
01465 construct_objective_term(MINKOWSKI_ERROR);
01466 }
01467 else if(new_objective_term_type == "NEURAL_PARAMETERS_NORM")
01468 {
01469 construct_objective_term(NEURAL_PARAMETERS_NORM);
01470 }
01471 else if(new_objective_term_type == "OUTPUTS_INTEGRALS")
01472 {
01473 construct_objective_term(OUTPUTS_INTEGRALS);
01474 }
01475 if(new_objective_term_type == "SOLUTION_ERROR")
01476 {
01477 construct_objective_term(SOLUTION_ERROR);
01478 }
01479 if(new_objective_term_type == "FINAL_SOLUTIONS_ERROR")
01480 {
01481 construct_objective_term(FINAL_SOLUTIONS_ERROR);
01482 }
01483 else if(new_objective_term_type == "INDEPENDENT_PARAMETERS_ERROR")
01484 {
01485 construct_objective_term(INDEPENDENT_PARAMETERS_ERROR);
01486 }
01487 else if(new_objective_term_type == "INVERSE_SUM_SQUARED_ERROR")
01488 {
01489 construct_objective_term(INVERSE_SUM_SQUARED_ERROR);
01490 }
01491 else if(new_objective_term_type == "USER_PERFORMANCE_TERM")
01492 {
01493 construct_objective_term(USER_PERFORMANCE_TERM);
01494 }
01495 else
01496 {
01497 std::ostringstream buffer;
01498
01499 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01500 << "void construct_objective_term(const std::string&) method.\n"
01501 << "Unknown objective term type: " << new_objective_term_type << ".\n";
01502
01503 throw std::logic_error(buffer.str());
01504 }
01505 }
01506
01507
01508
01509
01512
01513 void PerformanceFunctional::construct_regularization_term(const std::string& new_regularization_term_type)
01514 {
01515 if(new_regularization_term_type == "NONE")
01516 {
01517 construct_regularization_term(NONE);
01518 }
01519 else if(new_regularization_term_type == "SUM_SQUARED_ERROR")
01520 {
01521 construct_regularization_term(SUM_SQUARED_ERROR);
01522 }
01523 else if(new_regularization_term_type == "MEAN_SQUARED_ERROR")
01524 {
01525 construct_regularization_term(MEAN_SQUARED_ERROR);
01526 }
01527 else if(new_regularization_term_type == "ROOT_MEAN_SQUARED_ERROR")
01528 {
01529 construct_regularization_term(ROOT_MEAN_SQUARED_ERROR);
01530 }
01531 else if(new_regularization_term_type == "NORMALIZED_SQUARED_ERROR")
01532 {
01533 construct_regularization_term(NORMALIZED_SQUARED_ERROR);
01534 }
01535 else if(new_regularization_term_type == "MINKOWSKI_ERROR")
01536 {
01537 construct_regularization_term(MINKOWSKI_ERROR);
01538 }
01539 else if(new_regularization_term_type == "MINKOWSKI_ERROR")
01540 {
01541 construct_regularization_term(MINKOWSKI_ERROR);
01542 }
01543 else if(new_regularization_term_type == "NEURAL_PARAMETERS_NORM")
01544 {
01545 construct_regularization_term(NEURAL_PARAMETERS_NORM);
01546 }
01547 else if(new_regularization_term_type == "OUTPUTS_INTEGRALS")
01548 {
01549 construct_regularization_term(OUTPUTS_INTEGRALS);
01550 }
01551 if(new_regularization_term_type == "SOLUTION_ERROR")
01552 {
01553 construct_regularization_term(SOLUTION_ERROR);
01554 }
01555 if(new_regularization_term_type == "FINAL_SOLUTIONS_ERROR")
01556 {
01557 construct_regularization_term(FINAL_SOLUTIONS_ERROR);
01558 }
01559 else if(new_regularization_term_type == "INDEPENDENT_PARAMETERS_ERROR")
01560 {
01561 construct_regularization_term(INDEPENDENT_PARAMETERS_ERROR);
01562 }
01563 else if(new_regularization_term_type == "INVERSE_SUM_SQUARED_ERROR")
01564 {
01565 construct_regularization_term(INVERSE_SUM_SQUARED_ERROR);
01566 }
01567 else if(new_regularization_term_type == "USER_PERFORMANCE_TERM")
01568 {
01569 construct_regularization_term(USER_PERFORMANCE_TERM);
01570 }
01571 else
01572 {
01573 std::ostringstream buffer;
01574
01575 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01576 << "void construct_regularization_term(const std::string&) method.\n"
01577 << "Unknown regularization term type: " << new_regularization_term_type << ".\n";
01578
01579 throw std::logic_error(buffer.str());
01580 }
01581 }
01582
01583
01584
01585
01588
01589 void PerformanceFunctional::construct_constraints_term(const std::string& new_constraints_term_type)
01590 {
01591 if(new_constraints_term_type == "NONE")
01592 {
01593 construct_constraints_term(NONE);
01594 }
01595 else if(new_constraints_term_type == "SUM_SQUARED_ERROR")
01596 {
01597 construct_constraints_term(SUM_SQUARED_ERROR);
01598 }
01599 else if(new_constraints_term_type == "MEAN_SQUARED_ERROR")
01600 {
01601 construct_constraints_term(MEAN_SQUARED_ERROR);
01602 }
01603 else if(new_constraints_term_type == "ROOT_MEAN_SQUARED_ERROR")
01604 {
01605 construct_constraints_term(ROOT_MEAN_SQUARED_ERROR);
01606 }
01607 else if(new_constraints_term_type == "NORMALIZED_SQUARED_ERROR")
01608 {
01609 construct_constraints_term(NORMALIZED_SQUARED_ERROR);
01610 }
01611 else if(new_constraints_term_type == "MINKOWSKI_ERROR")
01612 {
01613 construct_constraints_term(MINKOWSKI_ERROR);
01614 }
01615 else if(new_constraints_term_type == "MINKOWSKI_ERROR")
01616 {
01617 construct_constraints_term(MINKOWSKI_ERROR);
01618 }
01619 else if(new_constraints_term_type == "NEURAL_PARAMETERS_NORM")
01620 {
01621 construct_constraints_term(NEURAL_PARAMETERS_NORM);
01622 }
01623 else if(new_constraints_term_type == "OUTPUTS_INTEGRALS")
01624 {
01625 construct_constraints_term(OUTPUTS_INTEGRALS);
01626 }
01627 if(new_constraints_term_type == "SOLUTION_ERROR")
01628 {
01629 construct_constraints_term(SOLUTION_ERROR);
01630 }
01631 if(new_constraints_term_type == "FINAL_SOLUTIONS_ERROR")
01632 {
01633 construct_constraints_term(FINAL_SOLUTIONS_ERROR);
01634 }
01635 else if(new_constraints_term_type == "INDEPENDENT_PARAMETERS_ERROR")
01636 {
01637 construct_constraints_term(INDEPENDENT_PARAMETERS_ERROR);
01638 }
01639 else if(new_constraints_term_type == "INVERSE_SUM_SQUARED_ERROR")
01640 {
01641 construct_constraints_term(INVERSE_SUM_SQUARED_ERROR);
01642 }
01643 else if(new_constraints_term_type == "USER_PERFORMANCE_TERM")
01644 {
01645 construct_constraints_term(USER_PERFORMANCE_TERM);
01646 }
01647 else
01648 {
01649 std::ostringstream buffer;
01650
01651 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01652 << "void construct_constraints_term(const std::string&) method.\n"
01653 << "Unknown constraints term type: " << new_constraints_term_type << ".\n";
01654
01655 throw std::logic_error(buffer.str());
01656 }
01657 }
01658
01659
01660
01661
01664
01665 void PerformanceFunctional::destruct_objective_term(void)
01666 {
01667 delete objective_term_pointer;
01668
01669 objective_term_type = NONE;
01670
01671 objective_term_pointer = NULL;
01672
01673 objective_term_flag = false;
01674 }
01675
01676
01677
01678
01681
01682 void PerformanceFunctional::destruct_regularization_term(void)
01683 {
01684 delete regularization_term_pointer;
01685
01686 regularization_term_type = NONE;
01687
01688 regularization_term_pointer = NULL;
01689
01690 regularization_term_flag = false;
01691 }
01692
01693
01694
01695
01698
01699 void PerformanceFunctional::destruct_constraints_term(void)
01700 {
01701 delete constraints_term_pointer;
01702
01703 constraints_term_type = NONE;
01704
01705 constraints_term_pointer = NULL;
01706
01707 constraints_term_flag = false;
01708 }
01709
01710
01711
01712
01714
01715 void PerformanceFunctional::destruct_all_terms(void)
01716 {
01717 destruct_objective_term();
01718 destruct_regularization_term();
01719 destruct_constraints_term();
01720 }
01721
01722
01723
01724
01727
01728 double PerformanceFunctional::calculate_evaluation(void) const
01729 {
01730
01731
01732 #ifdef _DEBUG
01733
01734 std::ostringstream buffer;
01735
01736 if(!neural_network_pointer)
01737 {
01738
01739 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01740 << "double calculate_evaluation(void) const method.\n"
01741 << "Pointer to neural network is NULL.\n";
01742
01743 throw std::logic_error(buffer.str().c_str());
01744 }
01745
01746 #endif
01747
01748 double performance = 0.0;
01749
01750 if(objective_term_flag)
01751 {
01752 #ifdef _DEBUG
01753
01754 if(!objective_term_pointer)
01755 {
01756 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01757 << "double calculate_evaluation(void) const method.\n"
01758 << "Pointer to performance term is NULL.\n";
01759
01760 throw std::logic_error(buffer.str().c_str());
01761 }
01762
01763 #endif
01764
01765 performance += objective_term_pointer->calculate_evaluation();
01766 }
01767
01768 if(regularization_term_flag)
01769 {
01770 #ifdef _DEBUG
01771
01772 if(!regularization_term_pointer)
01773 {
01774 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01775 << "double calculate_evaluation(void) const method.\n"
01776 << "Pointer to regularization functional is NULL.\n";
01777
01778 throw std::logic_error(buffer.str().c_str());
01779 }
01780
01781 #endif
01782
01783 performance += regularization_term_pointer->calculate_evaluation();
01784 }
01785
01786 if(constraints_term_flag)
01787 {
01788 #ifdef _DEBUG
01789
01790 if(!constraints_term_pointer)
01791 {
01792 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01793 << "double calculate_evaluation(void) const method.\n"
01794 << "Pointer to constraints functional is NULL.\n";
01795
01796 throw std::logic_error(buffer.str().c_str());
01797 }
01798
01799 #endif
01800
01801 performance += constraints_term_pointer->calculate_evaluation();
01802 }
01803
01804 return(performance);
01805 }
01806
01807
01808
01809
01813
01814 double PerformanceFunctional::calculate_evaluation(const Vector<double>& parameters)
01815 {
01816
01817
01818 #ifdef _DEBUG
01819
01820 const unsigned int size = parameters.size();
01821
01822 const unsigned int parameters_number = neural_network_pointer->count_parameters_number();
01823
01824 if(size != parameters_number)
01825 {
01826 std::ostringstream buffer;
01827
01828 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01829 << "double calculate_evaluation(const Vector<double>&) method.\n"
01830 << "Size (" << size << ") must be equal to number of parameters (" << parameters_number << ").\n";
01831
01832 throw std::logic_error(buffer.str().c_str());
01833 }
01834
01835 #endif
01836
01837 const Vector<double> original_parameters = neural_network_pointer->arrange_parameters();
01838
01839 neural_network_pointer->set_parameters(parameters);
01840
01841 const double performance = calculate_evaluation();
01842
01843 neural_network_pointer->set_parameters(original_parameters);
01844
01845 return(performance);
01846 }
01847
01848
01849
01850
01853
01854 double PerformanceFunctional::calculate_generalization_evaluation(void) const
01855 {
01856
01857
01858 #ifdef _DEBUG
01859
01860 if(!neural_network_pointer)
01861 {
01862 std::ostringstream buffer;
01863
01864 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01865 << "double calculate_generalization_evaluation(void) const method.\n"
01866 << "Pointer to neural network is NULL.\n";
01867
01868 throw std::logic_error(buffer.str().c_str());
01869 }
01870
01871 #endif
01872
01873 double generalization_peformance = 0.0;
01874
01875 if(objective_term_flag)
01876 {
01877 generalization_peformance += objective_term_pointer->calculate_generalization_evaluation();
01878 }
01879
01880 if(regularization_term_flag)
01881 {
01882 generalization_peformance += regularization_term_pointer->calculate_generalization_evaluation();
01883 }
01884
01885 if(constraints_term_flag)
01886 {
01887 generalization_peformance += constraints_term_pointer->calculate_generalization_evaluation();
01888 }
01889
01890 return(generalization_peformance);
01891 }
01892
01893
01894
01895
01897
01898 Vector<double> PerformanceFunctional::calculate_gradient(void) const
01899 {
01900
01901
01902 #ifdef _DEBUG
01903
01904 std::ostringstream buffer;
01905
01906 if(!neural_network_pointer)
01907 {
01908 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01909 << "Vector<double> calculate_gradient(void) const method.\n"
01910 << "Pointer to neural network is NULL.\n";
01911
01912 throw std::logic_error(buffer.str().c_str());
01913 }
01914
01915 #endif
01916
01917 const unsigned int& parameters_number = neural_network_pointer->count_parameters_number();
01918
01919 Vector<double> gradient(parameters_number, 0.0);
01920
01921 if(objective_term_flag)
01922 {
01923 #ifdef _DEBUG
01924
01925 if(!objective_term_pointer)
01926 {
01927 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01928 << "Vector<double> calculate_gradient(void) const method.\n"
01929 << "Pointer to objective term is NULL.\n";
01930
01931 throw std::logic_error(buffer.str().c_str());
01932 }
01933
01934 #endif
01935
01936 gradient += objective_term_pointer->calculate_gradient();
01937 }
01938
01939 if(regularization_term_flag)
01940 {
01941 #ifdef _DEBUG
01942
01943 if(!regularization_term_pointer)
01944 {
01945 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01946 << "Vector<double> calculate_gradient(void) const method.\n"
01947 << "Pointer to regularization term is NULL.\n";
01948
01949 throw std::logic_error(buffer.str().c_str());
01950 }
01951
01952 #endif
01953
01954 gradient += regularization_term_pointer->calculate_gradient();
01955 }
01956
01957 if(constraints_term_flag)
01958 {
01959 #ifdef _DEBUG
01960
01961 if(!constraints_term_pointer)
01962 {
01963 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01964 << "Vector<double> calculate_gradient(void) const method.\n"
01965 << "Pointer to constraints term is NULL.\n";
01966
01967 throw std::logic_error(buffer.str().c_str());
01968 }
01969
01970 #endif
01971
01972 gradient += constraints_term_pointer->calculate_gradient();
01973 }
01974
01975 return(gradient);
01976 }
01977
01978
01979
01980
01984
01985 Vector<double> PerformanceFunctional::calculate_gradient(const Vector<double>& parameters)
01986 {
01987 #ifdef _DEBUG
01988
01989 if(!neural_network_pointer)
01990 {
01991 std::ostringstream buffer;
01992
01993 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
01994 << "Vector<double> calculate_gradient(const Vector<double>&) method.\n"
01995 << "Pointer to neural network is NULL.\n";
01996
01997 throw std::logic_error(buffer.str().c_str());
01998 }
01999
02000 #endif
02001
02002 #ifdef _DEBUG
02003
02004 const unsigned int parameters_number = neural_network_pointer->count_parameters_number();
02005
02006 const unsigned int size = parameters.size();
02007
02008 if(size != parameters_number)
02009 {
02010 std::ostringstream buffer;
02011
02012 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
02013 << "Vector<double> calculate_gradient(const Vector<double>&) method.\n"
02014 << "Size (" << size << ") must be equal to number of parameters (" << parameters_number << ").\n";
02015
02016 throw std::logic_error(buffer.str().c_str());
02017 }
02018
02019 #endif
02020
02021
02022
02023 const Vector<double> original_parameters = neural_network_pointer->arrange_parameters();
02024
02025
02026
02027 neural_network_pointer->set_parameters(parameters);
02028
02029
02030
02031 const Vector<double> gradient = calculate_gradient();
02032
02033
02034
02035 neural_network_pointer->set_parameters(original_parameters);
02036
02037 return(gradient);
02038 }
02039
02040
02041
02042
02045
02046 Matrix<double> PerformanceFunctional::calculate_Hessian(void) const
02047 {
02048 const unsigned int parameters_number = neural_network_pointer->count_parameters_number();
02049
02050 Matrix<double> Hessian(parameters_number, parameters_number, 0.0);
02051
02052 if(objective_term_flag)
02053 {
02054 Hessian += objective_term_pointer->calculate_Hessian();
02055 }
02056
02057 if(regularization_term_flag)
02058 {
02059 Hessian += regularization_term_pointer->calculate_Hessian();
02060 }
02061
02062 if(constraints_term_flag)
02063 {
02064 Hessian += constraints_term_pointer->calculate_Hessian();
02065 }
02066
02067 return(Hessian);
02068 }
02069
02070
02071
02072
02078
02079 Matrix<double> PerformanceFunctional::calculate_Hessian(const Vector<double>& parameters)
02080 {
02081
02082
02083 #ifdef _DEBUG
02084
02085 const unsigned int size = parameters.size();
02086 const unsigned int parameters_number = neural_network_pointer->count_parameters_number();
02087
02088 if(size != parameters_number)
02089 {
02090 std::ostringstream buffer;
02091
02092 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
02093 << "double calculate_Hessian(const Vector<double>&) method.\n"
02094 << "Size must be equal to number of parameters.\n";
02095
02096 throw std::logic_error(buffer.str().c_str());
02097 }
02098
02099 #endif
02100
02101
02102
02103 const Vector<double> original_parameters = neural_network_pointer->arrange_parameters();
02104
02105
02106
02107 neural_network_pointer->set_parameters(parameters);
02108
02109
02110
02111 const Matrix<double> Hessian = calculate_Hessian();
02112
02113
02114
02115 neural_network_pointer->set_parameters(original_parameters);
02116
02117 return(Hessian);
02118 }
02119
02120
02121
02122
02123
02127
02128 Matrix<double> PerformanceFunctional::calculate_inverse_Hessian(void) const
02129 {
02130 std::ostringstream buffer;
02131
02132 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
02133 << "Matrix<double> calculate_inverse_Hessian(void) const method.\n"
02134 << "This method is not yet implemented.\n";
02135
02136 throw std::logic_error(buffer.str().c_str());
02137
02138
02139
02140
02141 }
02142
02143
02144
02145
02149
02150 Vector<double> PerformanceFunctional::calculate_vector_dot_Hessian(const Vector<double>& vector) const
02151 {
02152
02153
02154 const unsigned int size = vector.size();
02155
02156 const unsigned int parameters_number = neural_network_pointer->count_parameters_number();
02157
02158 if(size != parameters_number)
02159 {
02160 std::ostringstream buffer;
02161
02162 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
02163 << "Vector<double> calculate_vector_dot_Hessian(Vector<double>) method.\n"
02164 << "Size of vector must be equal to number of parameters.\n";
02165
02166 throw std::logic_error(buffer.str().c_str());
02167 }
02168
02169
02170
02171 Vector<double> vector_Hessian_product(parameters_number);
02172
02173 return(vector_Hessian_product);
02174 }
02175
02176
02177
02178
02180
02181 PerformanceFunctional::ZeroOrderEvaluation PerformanceFunctional::calculate_zero_order_evaluation(void) const
02182 {
02183 ZeroOrderEvaluation zero_order_evaluation;
02184
02185 zero_order_evaluation.performance = calculate_evaluation();
02186
02187 return(zero_order_evaluation);
02188 }
02189
02190
02191
02192
02194
02195 PerformanceFunctional::FirstOrderEvaluation PerformanceFunctional::calculate_first_order_evaluation(void) const
02196 {
02197 FirstOrderEvaluation first_order_evaluation;
02198
02199 first_order_evaluation.performance = calculate_evaluation();
02200 first_order_evaluation.gradient = calculate_gradient();
02201
02202 return(first_order_evaluation);
02203 }
02204
02205
02206
02207
02209
02210 PerformanceFunctional::SecondOrderEvaluation PerformanceFunctional::calculate_second_order_evaluation(void) const
02211 {
02212 SecondOrderEvaluation second_order_evaluation;
02213
02214 second_order_evaluation.performance = calculate_evaluation();
02215 second_order_evaluation.gradient = calculate_gradient();
02216 second_order_evaluation.Hessian = calculate_Hessian();
02217
02218 return(second_order_evaluation);
02219 }
02220
02221
02222
02223
02226
02227 double PerformanceFunctional::calculate_zero_order_Taylor_approximation(const Vector<double>&) const
02228 {
02229 return(calculate_evaluation());
02230 }
02231
02232
02233
02234
02238
02239 double PerformanceFunctional::calculate_first_order_Taylor_approximation(const Vector<double>& parameters) const
02240 {
02241
02242
02243 #ifdef _DEBUG
02244
02245 const unsigned int parameters_size = parameters.size();
02246 const unsigned int parameters_number = neural_network_pointer->count_parameters_number();
02247
02248 if(parameters_size != parameters_number)
02249 {
02250 std::ostringstream buffer;
02251
02252 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
02253 << "double calculate_first_order_Taylor_approximation(const Vector<double>&) const method.\n"
02254 << "Size of potential parameters must be equal to number of parameters.\n";
02255
02256 throw std::logic_error(buffer.str().c_str());
02257 }
02258
02259 #endif
02260
02261 const Vector<double> original_parameters = neural_network_pointer->arrange_parameters();
02262
02263 const double performance = calculate_evaluation();
02264 const Vector<double> gradient = calculate_gradient();
02265
02266 const double first_order_Taylor_approximation = performance + gradient.dot(parameters-parameters);
02267
02268 return(first_order_Taylor_approximation);
02269 }
02270
02271
02272
02273
02277
02278 double PerformanceFunctional::calculate_second_order_Taylor_approximation(const Vector<double>& parameters) const
02279 {
02280
02281
02282 #ifdef _DEBUG
02283
02284 const unsigned int parameters_size = parameters.size();
02285 const unsigned int parameters_number = neural_network_pointer->count_parameters_number();
02286
02287 if(parameters_size != parameters_number)
02288 {
02289 std::ostringstream buffer;
02290
02291 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
02292 << "double calculate_second_order_Taylor_approximation(const Vector<double>&) const method.\n"
02293 << "Size of potential parameters must be equal to number of parameters.\n";
02294
02295 throw std::logic_error(buffer.str().c_str());
02296 }
02297
02298 #endif
02299
02300
02301
02302 const Vector<double> original_parameters = neural_network_pointer->arrange_parameters();
02303 const Vector<double> parameters_difference = parameters - parameters;
02304
02305
02306
02307 const double performance = calculate_evaluation();
02308 const Vector<double> gradient = calculate_gradient();
02309 const Matrix<double> Hessian = calculate_Hessian();
02310
02311 const double second_order_Taylor_approximation = performance
02312 + gradient.dot(parameters_difference)
02313 + parameters_difference.dot(Hessian).dot(parameters_difference)/2.0;
02314
02315 return(second_order_Taylor_approximation);
02316 }
02317
02318
02319
02320
02324
02325 double PerformanceFunctional::calculate_directional_performance(const Vector<double>& direction, double rate)
02326 {
02327 return(calculate_evaluation(neural_network_pointer->arrange_parameters() + direction*rate));
02328 }
02329
02330
02331
02332
02336
02337 double PerformanceFunctional::calculate_directional_performance_derivative(const Vector<double>& direction, double rate)
02338 {
02339 const Vector<double> gradient = calculate_gradient(neural_network_pointer->arrange_parameters() + direction*rate);
02340
02341 const Vector<double> normalized_direction = direction/direction.calculate_norm();
02342
02343 return(gradient.dot(normalized_direction));
02344 }
02345
02346
02347
02348
02352
02353 double PerformanceFunctional::calculate_directional_performance_second_derivative(const Vector<double>& direction, double rate)
02354 {
02355 const Matrix<double> Hessian = calculate_Hessian(neural_network_pointer->arrange_parameters() + direction*rate);
02356
02357 const Vector<double> normalized_direction = direction/direction.calculate_norm();
02358
02359 return(normalized_direction.dot(Hessian).dot(normalized_direction));
02360 }
02361
02362
02363
02364
02367
02368 TiXmlElement* PerformanceFunctional::to_XML(void) const
02369 {
02370 std::ostringstream buffer;
02371
02372
02373
02374 TiXmlElement* performance_functional_element = new TiXmlElement("PerformanceFunctional");
02375 performance_functional_element->SetAttribute("Version", 4);
02376
02377
02378
02379 TiXmlElement* objective_term_type_element = new TiXmlElement("ObjectiveTermType");
02380 performance_functional_element->LinkEndChild(objective_term_type_element);
02381
02382 buffer.str("");
02383 buffer << write_objective_term_type();
02384
02385 TiXmlText* objective_term_type_text = new TiXmlText(buffer.str().c_str());
02386 objective_term_type_element->LinkEndChild(objective_term_type_text);
02387
02388
02389
02390 TiXmlElement* regularization_term_type_element = new TiXmlElement("RegularizationTermType");
02391 performance_functional_element->LinkEndChild(regularization_term_type_element);
02392
02393 buffer.str("");
02394 buffer << write_regularization_term_type();
02395
02396 TiXmlText* regularization_term_type_text = new TiXmlText(buffer.str().c_str());
02397 regularization_term_type_element->LinkEndChild(regularization_term_type_text);
02398
02399
02400
02401 TiXmlElement* constraints_term_type_element = new TiXmlElement("ConstraintsTermType");
02402 performance_functional_element->LinkEndChild(constraints_term_type_element);
02403
02404 buffer.str("");
02405 buffer << write_constraints_term_type();
02406
02407 TiXmlText* constraints_term_type_text = new TiXmlText(buffer.str().c_str());
02408 constraints_term_type_element->LinkEndChild(constraints_term_type_text);
02409
02410
02411
02412 TiXmlElement* objective_term_flag_element = new TiXmlElement("ObjectiveFlag");
02413 performance_functional_element->LinkEndChild(objective_term_flag_element);
02414
02415 buffer.str("");
02416 buffer << objective_term_flag;
02417
02418 TiXmlText* objective_term_flag_text = new TiXmlText(buffer.str().c_str());
02419 objective_term_flag_element->LinkEndChild(objective_term_flag_text);
02420
02421
02422
02423 TiXmlElement* regularization_term_flag_element = new TiXmlElement("RegularizationFlag");
02424 performance_functional_element->LinkEndChild(regularization_term_flag_element);
02425
02426 buffer.str("");
02427 buffer << regularization_term_flag;
02428
02429 TiXmlText* regularization_term_flag_text = new TiXmlText(buffer.str().c_str());
02430 regularization_term_flag_element->LinkEndChild(regularization_term_flag_text);
02431
02432
02433
02434 TiXmlElement* constraints_term_flag_element = new TiXmlElement("ConstraintsFlag");
02435 performance_functional_element->LinkEndChild(constraints_term_flag_element);
02436
02437 buffer.str("");
02438 buffer << constraints_term_flag;
02439
02440 TiXmlText* constraints_term_flag_text = new TiXmlText(buffer.str().c_str());
02441 constraints_term_flag_element->LinkEndChild(constraints_term_flag_text);
02442
02443
02444
02445 if(objective_term_pointer)
02446 {
02447 TiXmlElement* objective_term_element = objective_term_pointer->to_XML();
02448
02449 performance_functional_element->LinkEndChild(objective_term_element);
02450 }
02451
02452
02453
02454 if(regularization_term_pointer)
02455 {
02456 TiXmlElement* regularization_term_element = regularization_term_pointer->to_XML();
02457
02458 performance_functional_element->LinkEndChild(regularization_term_element);
02459 }
02460
02461
02462
02463 if(constraints_term_pointer)
02464 {
02465 TiXmlElement* constraints_term_element = constraints_term_pointer->to_XML();
02466
02467 performance_functional_element->LinkEndChild(constraints_term_element);
02468 }
02469
02470
02471
02472 TiXmlElement* display_element = new TiXmlElement("Display");
02473 performance_functional_element->LinkEndChild(display_element);
02474
02475 buffer.str("");
02476 buffer << display;
02477
02478 TiXmlText* display_text = new TiXmlText(buffer.str().c_str());
02479 display_element->LinkEndChild(display_text);
02480
02481 return(performance_functional_element);
02482 }
02483
02484
02485
02486
02489
02490 void PerformanceFunctional::from_XML(TiXmlElement* performance_functional_element)
02491 {
02492 if(!performance_functional_element)
02493 {
02494 return;
02495 }
02496
02497
02498
02499 TiXmlElement* objective_term_type_element = performance_functional_element->FirstChildElement("ObjectiveTermType");
02500
02501 if(objective_term_type_element)
02502 {
02503 const std::string new_objective_term_type = objective_term_type_element->GetText();
02504
02505 try
02506 {
02507 set_objective_term_type(new_objective_term_type);
02508 }
02509 catch(std::exception& e)
02510 {
02511 std::cout << e.what() << std::endl;
02512 }
02513 }
02514
02515
02516
02517 TiXmlElement* regularization_term_type_element = performance_functional_element->FirstChildElement("RegularizationTermType");
02518
02519 if(regularization_term_type_element)
02520 {
02521 std::string new_regularization_term_type = regularization_term_type_element->GetText();
02522
02523 try
02524 {
02525 set_regularization_term_type(new_regularization_term_type);
02526 }
02527 catch(std::exception& e)
02528 {
02529 std::cout << e.what() << std::endl;
02530 }
02531 }
02532
02533
02534
02535 TiXmlElement* constraints_term_type_element = performance_functional_element->FirstChildElement("ConstraintsTermType");
02536
02537 if(constraints_term_type_element)
02538 {
02539 std::string new_constraints_term_type = constraints_term_type_element->GetText();
02540
02541 try
02542 {
02543 set_constraints_term_type(new_constraints_term_type);
02544 }
02545 catch(std::exception& e)
02546 {
02547 std::cout << e.what() << std::endl;
02548 }
02549 }
02550
02551
02552
02553 TiXmlElement* objective_term_flag_element = performance_functional_element->FirstChildElement("ObjectiveFlag");
02554
02555 if(objective_term_flag_element)
02556 {
02557 std::string new_objective_term_flag_string = objective_term_flag_element->GetText();
02558
02559 try
02560 {
02561 set_objective_term_flag(new_objective_term_flag_string != "0");
02562 }
02563 catch(std::exception& e)
02564 {
02565 std::cout << e.what() << std::endl;
02566 }
02567 }
02568
02569
02570
02571 TiXmlElement* regularization_term_flag_element = performance_functional_element->FirstChildElement("RegularizationFlag");
02572
02573 if(regularization_term_flag_element)
02574 {
02575 std::string new_regularization_term_flag_string = regularization_term_flag_element->GetText();
02576
02577 try
02578 {
02579 set_regularization_term_flag(new_regularization_term_flag_string != "0");
02580 }
02581 catch(std::exception& e)
02582 {
02583 std::cout << e.what() << std::endl;
02584 }
02585 }
02586
02587
02588
02589 TiXmlElement* constraints_term_flag_element = performance_functional_element->FirstChildElement("ConstraintsFlag");
02590
02591 if(constraints_term_flag_element)
02592 {
02593 std::string new_constraints_term_flag_string = constraints_term_flag_element->GetText();
02594
02595 try
02596 {
02597 set_constraints_term_flag(new_constraints_term_flag_string != "0");
02598 }
02599 catch(std::exception& e)
02600 {
02601 std::cout << e.what() << std::endl;
02602 }
02603 }
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613 TiXmlElement* display_element = performance_functional_element->FirstChildElement("Display");
02614
02615 if(display_element)
02616 {
02617 std::string new_display_string = display_element->GetText();
02618
02619 try
02620 {
02621 set_display(new_display_string != "0");
02622 }
02623 catch(std::exception& e)
02624 {
02625 std::cout << e.what() << std::endl;
02626 }
02627 }
02628 }
02629
02630
02631
02632
02634
02635 void PerformanceFunctional::print(void) const
02636 {
02637 }
02638
02639
02640
02641
02644
02645 void PerformanceFunctional::save(const std::string& filename) const
02646 {
02647 TiXmlDocument document;
02648
02649
02650
02651 TiXmlDeclaration* declaration = new TiXmlDeclaration("1.0", "", "");
02652 document.LinkEndChild(declaration);
02653
02654
02655
02656 TiXmlElement* performance_functional_element = to_XML();
02657 document.LinkEndChild(performance_functional_element);
02658
02659 document.SaveFile(filename.c_str());
02660 }
02661
02662
02663
02664
02667
02668 void PerformanceFunctional::load(const std::string& filename)
02669 {
02670 std::ostringstream buffer;
02671
02672 TiXmlDocument document(filename.c_str());
02673
02674 if(!document.LoadFile())
02675 {
02676 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
02677 << "void load(const std::string&) method.\n"
02678 << "Cannot load XML file " << filename << ".\n";
02679
02680 throw std::logic_error(buffer.str());
02681 }
02682
02683
02684
02685 TiXmlElement* performance_functional_element = document.FirstChildElement();
02686
02687 if(!performance_functional_element)
02688 {
02689 buffer << "OpenNN Exception: PerformanceFunctional class.\n"
02690 << "void load(const std::string&) method.\n"
02691 << "File " << filename << " is not a valid performance functional file.\n";
02692
02693 throw std::logic_error(buffer.str());
02694 }
02695
02696 from_XML(performance_functional_element);
02697 }
02698
02699
02700
02701
02704
02705 std::string PerformanceFunctional::write_information(void)
02706 {
02707 std::ostringstream buffer;
02708
02709 if(objective_term_pointer)
02710 {
02711 buffer << objective_term_pointer->write_information();
02712 }
02713
02714 if(regularization_term_pointer)
02715 {
02716 buffer << regularization_term_pointer->write_information();
02717 }
02718
02719 if(constraints_term_pointer)
02720 {
02721 buffer << constraints_term_pointer->write_information();
02722 }
02723
02724 return(buffer.str());
02725 }
02726
02727
02728
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02754
02755
02756
02757
02758
02759
02760
02761
02762 }
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772
02773
02774
02775
02776
02777
02778
02779
02780