00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __PERFORMANCEFUNCTIONAL_H__
00017 #define __PERFORMANCEFUNCTIONAL_H__
00018
00019
00020
00021 #include <string>
00022
00023
00024
00025 #include "../utilities/vector.h"
00026 #include "../utilities/matrix.h"
00027 #include "../utilities/numerical_differentiation.h"
00028
00029 #include "../data_set/data_set.h"
00030 #include "../mathematical_model/mathematical_model.h"
00031
00032 #include "../neural_network/neural_network.h"
00033 #include "performance_term.h"
00034
00035
00036
00037 #include "../../parsers/tinyxml/tinyxml.h"
00038
00039 namespace OpenNN
00040 {
00041
00046
00047 class PerformanceFunctional
00048 {
00049
00050 public:
00051
00052
00053
00054 explicit PerformanceFunctional(void);
00055
00056
00057
00058 explicit PerformanceFunctional(PerformanceTerm*);
00059
00060
00061
00062 explicit PerformanceFunctional(NeuralNetwork*);
00063
00064
00065
00066 explicit PerformanceFunctional(NeuralNetwork*, DataSet*);
00067
00068
00069
00070 explicit PerformanceFunctional(NeuralNetwork*, MathematicalModel*);
00071
00072
00073
00074 explicit PerformanceFunctional(NeuralNetwork*, MathematicalModel*, DataSet*);
00075
00076
00077
00078 explicit PerformanceFunctional(const std::string&);
00079
00080
00081
00082 PerformanceFunctional(const PerformanceFunctional&);
00083
00084
00085
00086 virtual ~PerformanceFunctional(void);
00087
00088
00089
00092
00093 struct ZeroOrderEvaluation
00094 {
00096
00097 double performance;
00098 };
00099
00102
00103 struct FirstOrderEvaluation
00104 {
00106
00107 double performance;
00108
00110
00111 Vector<double> gradient;
00112 };
00113
00116
00117 struct SecondOrderEvaluation
00118 {
00120
00121 double performance;
00122
00124
00125 Vector<double> gradient;
00126
00128
00129 Matrix<double> Hessian;
00130 };
00131
00132
00133
00134
00136
00137 enum PerformanceTermType
00138 {
00139 NONE,
00140 SUM_SQUARED_ERROR,
00141 MEAN_SQUARED_ERROR,
00142 ROOT_MEAN_SQUARED_ERROR,
00143 NORMALIZED_SQUARED_ERROR,
00144 MINKOWSKI_ERROR,
00145 CROSS_ENTROPY_ERROR,
00146 NEURAL_PARAMETERS_NORM,
00147 OUTPUTS_INTEGRALS,
00148 SOLUTION_ERROR,
00149 FINAL_SOLUTIONS_ERROR,
00150 INDEPENDENT_PARAMETERS_ERROR,
00151 INVERSE_SUM_SQUARED_ERROR,
00152 USER_PERFORMANCE_TERM
00153 };
00154
00155
00156
00157
00158
00159
00161
00162 inline NeuralNetwork* get_neural_network_pointer(void) const
00163 {
00164 return(neural_network_pointer);
00165 }
00166
00168
00169
00170
00171
00172
00173
00175
00176
00177
00178
00179
00180
00182
00183 inline PerformanceTerm* get_objective_term_pointer(void) const
00184 {
00185 return(objective_term_pointer);
00186 }
00187
00189
00190 inline PerformanceTerm* get_regularization_term_pointer(void) const
00191 {
00192 return(regularization_term_pointer);
00193 }
00194
00195
00197
00198 inline PerformanceTerm* get_constraints_term_pointer(void)
00199 {
00200 return(constraints_term_pointer);
00201 }
00202
00203
00204
00205
00206 const PerformanceTermType& get_objective_term_type(void) const;
00207 const PerformanceTermType& get_regularization_term_type(void) const;
00208 const PerformanceTermType& get_constraints_term_type(void) const;
00209
00210 std::string write_objective_term_type(void) const;
00211 std::string write_regularization_term_type(void) const;
00212 std::string write_constraints_term_type(void) const;
00213
00214 const bool& get_objective_term_flag(void) const;
00215 const bool& get_regularization_term_flag(void) const;
00216 const bool& get_constraints_term_flag(void) const;
00217
00218
00219
00220 const bool& get_display(void) const;
00221
00222
00223
00224 void set_neural_network_pointer(NeuralNetwork*);
00225
00226 void set_objective_term_pointer(PerformanceTerm*);
00227 void set_regularization_term_pointer(PerformanceTerm*);
00228 void set_constraints_term_pointer(PerformanceTerm*);
00229
00230 void set_default(void);
00231
00232
00233
00234 void set_objective_term_type(const PerformanceTermType&);
00235 void set_objective_term_type(const std::string&);
00236
00237 void set_regularization_term_type(const PerformanceTermType&);
00238 void set_regularization_term_type(const std::string&);
00239
00240 void set_constraints_term_type(const PerformanceTermType&);
00241 void set_constraints_term_type(const std::string&);
00242
00243 void set_objective_term_flag(const bool&);
00244 void set_regularization_term_flag(const bool&);
00245 void set_constraints_term_flag(const bool&);
00246
00247
00248
00249 void set_display(const bool&);
00250
00251
00252
00253 void construct_objective_term(const PerformanceTermType&);
00254 void construct_regularization_term(const PerformanceTermType&);
00255 void construct_constraints_term(const PerformanceTermType&);
00256
00257 void construct_objective_term(const PerformanceTermType&, MathematicalModel*);
00258 void construct_regularization_term(const PerformanceTermType&, MathematicalModel*);
00259 void construct_constraints_term(const PerformanceTermType&, MathematicalModel*);
00260
00261 void construct_objective_term(const PerformanceTermType&, DataSet*);
00262 void construct_regularization_term(const PerformanceTermType&, DataSet*);
00263 void construct_constraints_term(const PerformanceTermType&, DataSet*);
00264
00265 void construct_objective_term(const PerformanceTermType&, MathematicalModel*, DataSet*);
00266 void construct_regularization_term(const PerformanceTermType&, MathematicalModel*, DataSet*);
00267 void construct_constraints_term(const PerformanceTermType&, MathematicalModel*, DataSet*);
00268
00269 void construct_objective_term(const std::string&);
00270 void construct_regularization_term(const std::string&);
00271 void construct_constraints_term(const std::string&);
00272
00273 void destruct_objective_term(void);
00274 void destruct_regularization_term(void);
00275 void destruct_constraints_term(void);
00276
00277 void destruct_all_terms(void);
00278
00279
00280
00281 double calculate_evaluation(void) const;
00282 Vector<double> calculate_gradient(void) const;
00283 Matrix<double> calculate_Hessian(void) const;
00284
00285 double calculate_evaluation(const Vector<double>&);
00286 Vector<double> calculate_gradient(const Vector<double>&);
00287 Matrix<double> calculate_Hessian(const Vector<double>&);
00288
00289 virtual Matrix<double> calculate_inverse_Hessian(void) const;
00290
00291 virtual Vector<double> calculate_vector_dot_Hessian(const Vector<double>&) const;
00292
00293 virtual ZeroOrderEvaluation calculate_zero_order_evaluation(void) const;
00294 virtual FirstOrderEvaluation calculate_first_order_evaluation(void) const;
00295 virtual SecondOrderEvaluation calculate_second_order_evaluation(void) const;
00296
00297 virtual double calculate_generalization_evaluation(void) const;
00298
00299
00300
00301 double calculate_zero_order_Taylor_approximation(const Vector<double>&) const;
00302 double calculate_first_order_Taylor_approximation(const Vector<double>&) const;
00303 double calculate_second_order_Taylor_approximation(const Vector<double>&) const;
00304
00305
00306
00307 double calculate_directional_performance(const Vector<double>&, double);
00308 double calculate_directional_performance_derivative(const Vector<double>&, double);
00309 double calculate_directional_performance_second_derivative(const Vector<double>&, double);
00310
00311
00312
00313 virtual TiXmlElement* to_XML(void) const;
00314 virtual void from_XML(TiXmlElement*);
00315
00316 virtual void print(void) const;
00317 virtual void save(const std::string&) const;
00318 virtual void load(const std::string&);
00319
00320
00321
00322
00323
00324 virtual std::string write_information(void);
00325
00326
00327 private:
00328
00330
00331 NeuralNetwork* neural_network_pointer;
00332
00334
00335 PerformanceTerm* objective_term_pointer;
00336
00338
00339 PerformanceTerm* regularization_term_pointer;
00340
00342
00343 PerformanceTerm* constraints_term_pointer;
00344
00346
00347 PerformanceTermType objective_term_type;
00348
00350
00351 PerformanceTermType regularization_term_type;
00352
00354
00355 PerformanceTermType constraints_term_type;
00356
00358
00359 bool objective_term_flag;
00360
00362
00363 bool regularization_term_flag;
00364
00366
00367 bool constraints_term_flag;
00368
00370
00371 bool display;
00372 };
00373
00374 }
00375
00376 #endif
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393