00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __OBJECTIVEFUNCTIONAL_H__
00017 #define __OBJECTIVEFUNCTIONAL_H__
00018
00019
00020
00021 #include "../Utilities/Vector.h"
00022 #include "../Utilities/Matrix.h"
00023 #include "../MultilayerPerceptron/MultilayerPerceptron.h"
00024
00025
00026
00027 #include <string>
00028
00029 namespace Flood
00030 {
00031
00034
00035 class ObjectiveFunctional
00036 {
00037
00038 public:
00039
00040
00041
00042 explicit ObjectiveFunctional(void);
00043
00044
00045
00046 explicit ObjectiveFunctional(MultilayerPerceptron*);
00047
00048
00049
00050 virtual ~ObjectiveFunctional(void);
00051
00052
00053
00054
00056
00057 enum RegularizationMethod{None, NeuralParametersNorm};
00058
00060
00061 enum NumericalDifferentiationMethod{ForwardDifferences, CentralDifferences};
00062
00064
00065 enum NumericalEpsilonMethod{Absolute, Relative};
00066
00067
00068
00069
00070
00072
00073 inline MultilayerPerceptron* get_multilayer_perceptron_pointer(void)
00074 {
00075 return(multilayer_perceptron_pointer);
00076 }
00077
00078
00079
00080 double get_objective_weight(void);
00081
00082
00083
00084 RegularizationMethod& get_regularization_method(void);
00085 std::string get_regularization_method_name(void);
00086
00087 double get_regularization_weight(void);
00088
00089
00090
00091 NumericalDifferentiationMethod get_numerical_differentiation_method(void);
00092 std::string get_numerical_differentiation_method_name(void);
00093
00094 NumericalEpsilonMethod get_numerical_epsilon_method(void);
00095 std::string get_numerical_epsilon_method_name(void);
00096
00097 double get_numerical_epsilon(void);
00098
00099
00100
00101 int get_calculate_evaluation_count(void);
00102 int get_calculate_gradient_count(void);
00103 int get_calculate_Hessian_count(void);
00104
00105 bool get_display(void);
00106
00107
00108
00109 void set_multilayer_perceptron_pointer(MultilayerPerceptron*);
00110
00111 void set_default(void);
00112
00113
00114
00115 void set_objective_weight(double);
00116
00117
00118
00119 void set_regularization_method(const RegularizationMethod&);
00120 void set_regularization_method(const std::string&);
00121
00122 void set_regularization_weight(double);
00123
00124
00125
00126 void set_numerical_differentiation_method(const NumericalDifferentiationMethod&);
00127 void set_numerical_differentiation_method(const std::string&);
00128
00129 void set_numerical_epsilon_method(const NumericalEpsilonMethod&);
00130 void set_numerical_epsilon_method(const std::string&);
00131
00132 void set_numerical_epsilon(double);
00133
00134
00135
00136 void set_calculate_evaluation_count(int);
00137 void set_calculate_gradient_count(int);
00138 void set_calculate_Hessian_count(int);
00139
00140 void set_display(bool);
00141
00142
00143
00144 double calculate_evaluation(void);
00145 double calculate_potential_evaluation(const Vector<double>&);
00146
00148
00149 virtual double calculate_objective(void) = 0;
00150 virtual double calculate_regularization(void);
00151
00152
00153
00154 Vector<double> calculate_gradient(void);
00155 Vector<double> calculate_potential_gradient(const Vector<double>&);
00156
00157 double calculate_gradient_norm(void);
00158
00160
00161 virtual Vector<double> calculate_objective_gradient(void);
00162 virtual Vector<double> calculate_regularization_gradient(void);
00163
00164 virtual Vector<double> calculate_neural_parameters_gradient(void);
00165 virtual Vector<double> calculate_independent_parameters_gradient(void);
00166
00167
00168
00169 Vector<double> calculate_objective_gradient_numerical_differentiation(void);
00170
00171 Vector<double> calculate_neural_parameters_gradient_numerical_differentiation(void);
00172 Vector<double> calculate_neural_parameters_gradient_forward_differences(void);
00173 Vector<double> calculate_neural_parameters_gradient_central_differences(void);
00174
00175 Vector<double> calculate_independent_parameters_gradient_numerical_differentiation(void);
00176 Vector<double> calculate_independent_parameters_gradient_forward_differences(void);
00177 Vector<double> calculate_independent_parameters_gradient_central_differences(void);
00178
00179
00180
00182
00183 virtual Matrix<double> calculate_Hessian(void);
00184 Matrix<double> calculate_potential_Hessian(const Vector<double>&);
00185
00186
00187
00188 Matrix<double> calculate_Hessian_numerical_differentiation(void);
00189 Matrix<double> calculate_Hessian_forward_differences(void);
00190 Matrix<double> calculate_Hessian_central_differences(void);
00191
00192
00193
00194 virtual Matrix<double> calculate_inverse_Hessian(void);
00195
00196 Matrix<double> calculate_DFP_inverse_Hessian
00197 (const Vector<double>&, const Vector<double>&, const Vector<double>&, const Vector<double>&, const Matrix<double>&);
00198
00199 Matrix<double> calculate_BFGS_inverse_Hessian
00200 (const Vector<double>&, const Vector<double>&, const Vector<double>&, const Vector<double>&, const Matrix<double>&);
00201
00202
00203
00204 virtual Vector<double> calculate_vector_dot_Hessian(const Vector<double>&);
00205
00206
00207
00208 Vector<double> calculate_vector_dot_Hessian_numerical_differentiation(const Vector<double>&);
00209
00210 Vector<double> calculate_vector_dot_Hessian_forward_differences(const Vector<double>&);
00211 Vector<double> calculate_vector_dot_Hessian_central_differences(const Vector<double>&);
00212
00213
00214
00215 virtual double calculate_validation_error(void);
00216
00217
00218
00219 double calculate_actual_epsilon(double);
00220
00221
00222
00223 virtual std::string to_XML(bool);
00224
00225 virtual void print(void);
00226 virtual void save(const char*);
00227 virtual void load(const char*);
00228
00229 virtual void print_information(void);
00230
00231 protected:
00232
00234
00235 MultilayerPerceptron* multilayer_perceptron_pointer;
00236
00238
00239 double objective_weight;
00240
00242
00243 RegularizationMethod regularization_method;
00244
00246
00247 double regularization_weight;
00248
00250
00251 int calculate_evaluation_count;
00252
00254
00255 int calculate_gradient_count;
00256
00258
00259 int calculate_Hessian_count;
00260
00262
00263 NumericalDifferentiationMethod numerical_differentiation_method;
00264
00266
00267 NumericalEpsilonMethod numerical_epsilon_method;
00268
00270
00271 double numerical_epsilon;
00272
00274
00275 bool display;
00276 };
00277
00278 }
00279
00280 #endif
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297