00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <iostream>
00019 #include <fstream>
00020 #include <cmath>
00021 #include <sstream>
00022 #include <string>
00023 #include <limits>
00024
00025
00026
00027 #include "outputs_integrals.h"
00028
00029
00030
00031 #include "../../parsers/tinyxml/tinyxml.h"
00032
00033
00034 namespace OpenNN
00035 {
00036
00037
00038
00042
00043 OutputsIntegrals::OutputsIntegrals(void)
00044 : PerformanceTerm()
00045 {
00046 set_default();
00047 }
00048
00049
00050
00051
00056
00057 OutputsIntegrals::OutputsIntegrals(NeuralNetwork* new_neural_network_pointer)
00058 : PerformanceTerm(new_neural_network_pointer)
00059 {
00060 set_default();
00061 }
00062
00063
00064
00065
00070
00071 OutputsIntegrals::OutputsIntegrals(TiXmlElement* outputs_integrals_element)
00072 : PerformanceTerm(outputs_integrals_element)
00073 {
00074 set_default();
00075
00076 from_XML(outputs_integrals_element);
00077 }
00078
00079
00080
00081
00083
00084 OutputsIntegrals::~OutputsIntegrals(void)
00085 {
00086 }
00087
00088
00089
00090
00092
00093 const NumericalIntegration& OutputsIntegrals::get_numerical_integration(void) const
00094 {
00095 return(numerical_integration);
00096 }
00097
00098
00099
00100
00102
00103 NumericalIntegration* OutputsIntegrals::get_numerical_integration_pointer(void)
00104 {
00105 return(&numerical_integration);
00106 }
00107
00108
00109
00110
00112
00113 const Vector<double>& OutputsIntegrals::get_outputs_integrals_weights(void) const
00114 {
00115 return(outputs_integrals_weights);
00116 }
00117
00118
00119
00120
00123
00124 const double& OutputsIntegrals::get_output_integral_weight(const unsigned int& i) const
00125 {
00126 return(outputs_integrals_weights[i]);
00127 }
00128
00129
00130
00131
00134
00135 void OutputsIntegrals::set_numerical_integration(const NumericalIntegration& new_numerical_integration)
00136 {
00137 numerical_integration = new_numerical_integration;
00138 }
00139
00140
00141
00142
00145
00146 void OutputsIntegrals::set_outputs_integrals_weights(const Vector<double>& new_outputs_integrals_weights)
00147 {
00148 outputs_integrals_weights = new_outputs_integrals_weights;
00149 }
00150
00151
00152
00153
00157
00158 void OutputsIntegrals::set_output_integral_weight(const unsigned int& i, const double& new_output_integral_weight)
00159 {
00160 outputs_integrals_weights[i] = new_output_integral_weight;
00161 }
00162
00163
00164
00165
00171
00172 void OutputsIntegrals::set_default(void)
00173 {
00174 unsigned int outputs_number = 0;
00175
00176 if(neural_network_pointer)
00177 {
00178 const MultilayerPerceptron* multilayer_perceptron_pointer = neural_network_pointer->get_multilayer_perceptron_pointer();
00179
00180 if(multilayer_perceptron_pointer)
00181 {
00182 outputs_number = multilayer_perceptron_pointer->count_inputs_number();
00183 }
00184 }
00185
00186 outputs_integrals_weights.set(outputs_number, 1.0);
00187
00188 display = true;
00189 }
00190
00191
00192
00193
00194
00195
00200
00201 void OutputsIntegrals::check(void) const
00202 {
00203 std::ostringstream buffer;
00204
00205
00206
00207 if(!neural_network_pointer)
00208 {
00209 buffer << "OpenNN Exception: OutputsIntegrals class.\n"
00210 << "void check(void) const method.\n"
00211 << "Pointer to neural network is NULL.\n";
00212
00213 throw std::logic_error(buffer.str().c_str());
00214 }
00215
00216 const MultilayerPerceptron* multilayer_perceptron_pointer = neural_network_pointer->get_multilayer_perceptron_pointer();
00217
00218 if(!multilayer_perceptron_pointer)
00219 {
00220 buffer << "OpenNN Exception: OutputsIntegrals class.\n"
00221 << "void check(void) const method.\n"
00222 << "Pointer to multilayer perceptron is NULL.\n";
00223
00224 throw std::logic_error(buffer.str().c_str());
00225 }
00226
00227 const unsigned int inputs_number = multilayer_perceptron_pointer->count_inputs_number();
00228 const unsigned int outputs_number = multilayer_perceptron_pointer->count_outputs_number();
00229
00230 if(inputs_number != 1)
00231 {
00232 buffer << "OpenNN Exception: OutputsIntegrals class.\n"
00233 << "void check(void) const method.\n"
00234 << "Number of inputs in multilayer perceptron is not one.\n";
00235
00236 throw std::logic_error(buffer.str().c_str());
00237 }
00238
00239 if(outputs_number == 0)
00240 {
00241 buffer << "OpenNN Exception: OutputsIntegrals class.\n"
00242 << "void check(void) const method.\n"
00243 << "Number of outputs in multilayer perceptron object is zero.\n";
00244
00245 throw std::logic_error(buffer.str().c_str());
00246 }
00247 }
00248
00249
00250
00251
00254
00255 double OutputsIntegrals::calculate_evaluation(void) const
00256 {
00257 std::ostringstream buffer;
00258
00259 buffer << "OpenNN Exception: OutputsIntegrals class.\n"
00260 << "double calculate_evaluation(void) const method.\n"
00261 << "This method is under development.\n";
00262
00263 throw std::logic_error(buffer.str().c_str());
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 }
00292
00293
00294
00295
00298
00299
00300 double OutputsIntegrals::calculate_evaluation(const Vector<double>&) const
00301 {
00302 std::ostringstream buffer;
00303
00304 buffer << "OpenNN Exception: OutputsIntegrals class.\n"
00305 << "double calculate_evaluation(const Vector<double>&) const method.\n"
00306 << "This method is under development.\n";
00307
00308 throw std::logic_error(buffer.str().c_str());
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 }
00348
00349
00350
00351
00355
00356 Vector<double> OutputsIntegrals::calculate_gradient(void) const
00357 {
00358
00359
00360 #ifdef _DEBUG
00361
00362 check();
00363
00364 #endif
00365
00366 Vector<double> gradient;
00367
00368 return(gradient);
00369 }
00370
00371
00372
00373
00377
00378 Matrix<double> OutputsIntegrals::calculate_Hessian(void) const
00379 {
00380
00381
00382 #ifdef _DEBUG
00383
00384 check();
00385
00386 #endif
00387
00388 Matrix<double> Hessian;
00389
00390 return(Hessian);
00391 }
00392
00393
00394
00395
00397
00398 std::string OutputsIntegrals::write_performance_term_type(void) const
00399 {
00400 return("OUTPUTS_INTEGRALS");
00401 }
00402
00403
00404
00405
00407
00408 TiXmlElement* OutputsIntegrals::to_XML(void) const
00409 {
00410 std::ostringstream buffer;
00411
00412
00413
00414 TiXmlElement* outputs_integrals_element = new TiXmlElement("OutputsIntegrals");
00415 outputs_integrals_element->SetAttribute("Version", 4);
00416
00417
00418
00419 if(numerical_differentiation_pointer)
00420 {
00421 TiXmlElement* element = numerical_differentiation_pointer->to_XML();
00422 outputs_integrals_element->LinkEndChild(element);
00423 }
00424
00425
00426 {
00427 TiXmlElement* element = new TiXmlElement("OutputsIntegralsWeights");
00428 outputs_integrals_element->LinkEndChild(element);
00429
00430 buffer.str("");
00431 buffer << outputs_integrals_weights;
00432
00433 TiXmlText* text = new TiXmlText(buffer.str().c_str());
00434 element->LinkEndChild(text);
00435 }
00436
00437
00438 {
00439 TiXmlElement* element = new TiXmlElement("Display");
00440 outputs_integrals_element->LinkEndChild(element);
00441
00442 buffer.str("");
00443 buffer << display;
00444
00445 TiXmlText* text = new TiXmlText(buffer.str().c_str());
00446 element->LinkEndChild(text);
00447 }
00448
00449 return(outputs_integrals_element);
00450 }
00451
00452
00453
00454
00456
00457
00458 void OutputsIntegrals::from_XML(TiXmlElement* outputs_integrals_element)
00459 {
00460 if(outputs_integrals_element)
00461 {
00462
00463 {
00464 TiXmlElement* display_element = outputs_integrals_element->FirstChildElement("Display");
00465
00466 if(display_element)
00467 {
00468 std::string new_display_string = display_element->GetText();
00469
00470 try
00471 {
00472 set_display(new_display_string != "0");
00473 }
00474 catch(std::exception& e)
00475 {
00476 std::cout << e.what() << std::endl;
00477 }
00478 }
00479 }
00480 }
00481 }
00482
00483
00484 }
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501