16 #include "minkowski_error.h"
88 from_XML(mean_squared_error_document);
140 if(new_Minkowski_parameter < 1.0 || new_Minkowski_parameter > 2.0)
142 std::ostringstream buffer;
144 buffer <<
"OpenNN Error. MinkowskiError class.\n"
145 <<
"void set_Minkowski_parameter(const double&) method.\n"
146 <<
"The Minkowski parameter must be comprised between 1 and 2\n";
148 throw std::logic_error(buffer.str());
165 std::ostringstream buffer;
171 buffer <<
"OpenNN Exception: MinkowskiError class.\n"
172 <<
"void check(void) const method.\n"
173 <<
"Pointer to neural network is NULL.\n";
175 throw std::logic_error(buffer.str());
180 if(!multilayer_perceptron_pointer)
182 buffer <<
"OpenNN Exception: MinkowskiError class.\n"
183 <<
"void check(void) const method.\n"
184 <<
"Pointer to multilayer perceptron is NULL.\n";
186 throw std::logic_error(buffer.str());
192 if(inputs_number == 0)
194 buffer <<
"OpenNN Exception: MinkowskiError class.\n"
195 <<
"void check(void) const method.\n"
196 <<
"Number of inputs in multilayer perceptron object is zero.\n";
198 throw std::logic_error(buffer.str());
201 if(outputs_number == 0)
203 buffer <<
"OpenNN Exception: MinkowskiError class.\n"
204 <<
"void check(void) const method.\n"
205 <<
"Number of outputs in multilayer perceptron object is zero.\n";
207 throw std::logic_error(buffer.str());
214 buffer <<
"OpenNN Exception: MinkowskiError class.\n"
215 <<
"void check(void) const method.\n"
216 <<
"Pointer to data set is NULL.\n";
218 throw std::logic_error(buffer.str());
228 if(data_set_inputs_number != inputs_number)
230 buffer <<
"OpenNN Exception: MinkowskiError class.\n"
231 <<
"void check(void) const method.\n"
232 <<
"Number of inputs in neural network must be equal to number of inputs in data set.\n";
234 throw std::logic_error(buffer.str());
237 if(outputs_number != targets_number)
239 buffer <<
"OpenNN Exception: MinkowskiError class.\n"
240 <<
"void check(void) const method.\n"
241 <<
"Number of outputs in neural network must be equal to number of targets in data set.\n";
243 throw std::logic_error(buffer.str());
277 size_t training_index;
290 double Minkowski_error = 0.0;
294 #pragma omp parallel for private(i, training_index, inputs, outputs, targets) reduction(+ : Minkowski_error)
296 for(i = 0; i < (int)training_instances_number; i++)
298 training_index = training_indices[i];
322 return(Minkowski_error);
344 const size_t size = parameters.size();
348 if(size != parameters_number)
350 std::ostringstream buffer;
352 buffer <<
"OpenNN Exception: MeanSquaredError class.\n"
353 <<
"double calculate_performance(const Vector<double>&) const method.\n"
354 <<
"Size (" << size <<
") must be equal to number of parameters (" << parameters_number <<
").\n";
356 throw std::logic_error(buffer.str());
375 size_t training_index;
388 double Minkowski_error = 0.0;
392 #pragma omp parallel for private(i, training_index, inputs, outputs, targets) reduction(+ : Minkowski_error)
394 for(i = 0; i < (int)training_instances_number; i++)
396 training_index = training_indices[i];
420 return(Minkowski_error);
454 size_t generalization_index;
469 double generalization_performance = 0.0;
473 #pragma omp parallel for private(i, generalization_index, inputs, outputs, targets) reduction(+ : generalization_performance)
475 for(i = 0; i < (int)generalization_instances_number; i++)
477 generalization_index = generalization_indices[i];
501 return(generalization_performance);
550 size_t training_index;
577 #pragma omp parallel for private(i, training_index, inputs, targets, first_order_forward_propagation, layers_inputs, layers_combination_parameters_Jacobian, \
578 output_gradient, layers_delta, particular_solution, homogeneous_solution, point_gradient)
580 for(i = 0; i < (int)training_instances_number; i++)
582 training_index = training_indices[i];
608 if(!has_conditions_layer)
610 output_gradient = (layers_activation[layers_number-1]-targets).calculate_p_norm_gradient(
Minkowski_parameter);
621 layers_delta =
calculate_layers_delta(layers_activation_derivative, homogeneous_solution, output_gradient);
628 gradient += point_gradient;
661 return(
"MINKOWSKI_ERROR");
672 std::ostringstream buffer;
674 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
678 tinyxml2::XMLElement* Minkowski_error_element = document->NewElement(
"MinkowskiError");
680 document->InsertFirstChild(Minkowski_error_element);
684 tinyxml2::XMLElement* Minkowski_parameter_element = document->NewElement(
"MinkowskiParameter");
685 Minkowski_error_element->LinkEndChild(Minkowski_parameter_element);
690 tinyxml2::XMLText* Minkowski_parameter_text = document->NewText(buffer.str().c_str());
691 Minkowski_parameter_element->LinkEndChild(Minkowski_parameter_text);
696 tinyxml2::XMLElement* display_element = document->NewElement(
"Display");
697 Minkowski_error_element->LinkEndChild(display_element);
702 tinyxml2::XMLText* display_text = document->NewText(buffer.str().c_str());
703 display_element->LinkEndChild(display_text);
717 const tinyxml2::XMLElement* root_element = document.FirstChildElement(
"MinkowskiError");
721 std::ostringstream buffer;
723 buffer <<
"OpenNN Exception: MinkowskiError class.\n"
724 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
725 <<
"Minkowski error element is NULL.\n";
727 throw std::logic_error(buffer.str());
732 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"MinkowskiParameter");
736 const double new_Minkowski_parameter = atof(element->GetText());
742 catch(
const std::logic_error& e)
744 std::cout << e.what() << std::endl;
751 const tinyxml2::XMLElement* display_element = root_element->FirstChildElement(
"Display");
755 const std::string new_display_string = display_element->GetText();
761 catch(
const std::logic_error& e)
763 std::cout << e.what() << std::endl;
double Minkowski_parameter
Minkowski exponent value.
double calculate_performance(void) const
Returns the Minkowski error performance.
size_t count_parameters_number(void) const
void set_Minkowski_parameter(const double &)
Vector< double > calculate_gradient(void) const
const Variables & get_variables(void) const
Returns a constant reference to the variables object composing this data set object.
virtual ~MinkowskiError(void)
size_t count_training_instances_number(void) const
Returns the number of instances in the data set which will be used for training.
size_t get_inputs_number(void) const
Returns the number of inputs to the multilayer perceptron.
void from_XML(const tinyxml2::XMLDocument &)
size_t get_layers_number(void) const
Returns the number of layers in the multilayer perceptron.
bool has_missing_values(void) const
size_t get_outputs_number(void) const
Returns the number of outputs neurons in the multilayer perceptron.
Vector< double > calculate_outputs(const Vector< double > &) const
const MissingValues & get_missing_values(void) const
Returns a reference to the missing values object in the data set.
Matrix< double > calculate_Hessian(void) const
Vector< size_t > arrange_targets_indices(void) const
Returns the indices of the target variables.
Vector< size_t > arrange_training_indices(void) const
Returns the indices of the instances which will be used for training.
size_t count_generalization_instances_number(void) const
Returns the number of instances in the data set which will be used for generalization.
Vector< double > get_instance(const size_t &) const
bool has_conditions_layer(void) const
MultilayerPerceptron * get_multilayer_perceptron_pointer(void) const
Returns a pointer to the multilayer perceptron composing this neural network.
virtual Vector< double > calculate_homogeneous_solution(const Vector< double > &) const
Returns the homogeneous solution for applying boundary conditions.
Vector< Matrix< double > > calculate_layers_combination_parameters_Jacobian(const Vector< Vector< double > > &) const
double calculate_generalization_performance(void) const
tinyxml2::XMLDocument * to_XML(void) const
double get_Minkowski_parameter(void) const
Returns the Minkowski exponent value used to calculate the error.
virtual Vector< double > calculate_particular_solution(const Vector< double > &) const
Returns the particular solution for applying boundary conditions.
ConditionsLayer * get_conditions_layer_pointer(void) const
Returns a pointer to the conditions layer composing this neural network.
size_t count_inputs_number(void) const
Returns the number of input variables of the data set.
Vector< Vector< Vector< double > > > calculate_first_order_forward_propagation(const Vector< double > &) const
size_t count_targets_number(void) const
Returns the number of target variables of the data set.
Vector< size_t > arrange_generalization_indices(void) const
Returns the indices of the instances which will be used for generalization.
Vector< Vector< double > > arrange_layers_input(const Vector< double > &, const Vector< Vector< double > > &) const
std::string write_performance_term_type(void) const
Returns a string with the name of the Minkowski error performance type, "MINKOWSKI_ERROR".
Vector< size_t > arrange_inputs_indices(void) const
Returns the indices of the input variables.
const Instances & get_instances(void) const
Returns a constant reference to the instances object composing this data set object.
size_t count_parameters_number(void) const
Returns the number of parameters (biases and synaptic weights) in the multilayer perceptron.