16 #include "neural_network.h"
29 : multilayer_perceptron_pointer(NULL)
30 , scaling_layer_pointer(NULL)
31 , unscaling_layer_pointer(NULL)
32 , bounding_layer_pointer(NULL)
33 , probabilistic_layer_pointer(NULL)
34 , conditions_layer_pointer(NULL)
35 , inputs_pointer(NULL)
36 , outputs_pointer(NULL)
37 , independent_parameters_pointer(NULL)
51 : multilayer_perceptron_pointer(NULL)
52 , scaling_layer_pointer(NULL)
53 , unscaling_layer_pointer(NULL)
54 , bounding_layer_pointer(NULL)
55 , probabilistic_layer_pointer(NULL)
56 , conditions_layer_pointer(NULL)
57 , inputs_pointer(NULL)
58 , outputs_pointer(NULL)
59 , independent_parameters_pointer(NULL)
84 : multilayer_perceptron_pointer(NULL)
85 , scaling_layer_pointer(NULL)
86 , unscaling_layer_pointer(NULL)
87 , bounding_layer_pointer(NULL)
88 , probabilistic_layer_pointer(NULL)
89 , conditions_layer_pointer(NULL)
90 , inputs_pointer(NULL)
91 , outputs_pointer(NULL)
92 , independent_parameters_pointer(NULL)
102 set(new_multilayer_perceptron_architecture);
116 : multilayer_perceptron_pointer(NULL)
117 , scaling_layer_pointer(NULL)
118 , unscaling_layer_pointer(NULL)
119 , bounding_layer_pointer(NULL)
120 , probabilistic_layer_pointer(NULL)
121 , conditions_layer_pointer(NULL)
122 , inputs_pointer(NULL)
123 , outputs_pointer(NULL)
124 , independent_parameters_pointer(NULL)
148 NeuralNetwork::NeuralNetwork(
const size_t& new_inputs_number,
const size_t& new_hidden_perceptrons_number,
const size_t& new_output_perceptrons_number)
149 : multilayer_perceptron_pointer(NULL)
150 , scaling_layer_pointer(NULL)
151 , unscaling_layer_pointer(NULL)
152 , bounding_layer_pointer(NULL)
153 , probabilistic_layer_pointer(NULL)
154 , conditions_layer_pointer(NULL)
155 , inputs_pointer(NULL)
156 , outputs_pointer(NULL)
157 , independent_parameters_pointer(NULL)
179 : multilayer_perceptron_pointer(NULL)
180 , scaling_layer_pointer(NULL)
181 , unscaling_layer_pointer(NULL)
182 , bounding_layer_pointer(NULL)
183 , probabilistic_layer_pointer(NULL)
184 , conditions_layer_pointer(NULL)
185 , inputs_pointer(NULL)
186 , outputs_pointer(NULL)
187 , independent_parameters_pointer(NULL)
203 : multilayer_perceptron_pointer(NULL)
204 , scaling_layer_pointer(NULL)
205 , unscaling_layer_pointer(NULL)
206 , bounding_layer_pointer(NULL)
207 , probabilistic_layer_pointer(NULL)
208 , conditions_layer_pointer(NULL)
209 , inputs_pointer(NULL)
210 , outputs_pointer(NULL)
211 , independent_parameters_pointer(NULL)
224 : multilayer_perceptron_pointer(NULL)
225 , scaling_layer_pointer(NULL)
226 , unscaling_layer_pointer(NULL)
227 , bounding_layer_pointer(NULL)
228 , probabilistic_layer_pointer(NULL)
229 , conditions_layer_pointer(NULL)
230 , inputs_pointer(NULL)
231 , outputs_pointer(NULL)
232 , independent_parameters_pointer(NULL)
245 : multilayer_perceptron_pointer(NULL)
246 , scaling_layer_pointer(NULL)
247 , unscaling_layer_pointer(NULL)
248 , bounding_layer_pointer(NULL)
249 , probabilistic_layer_pointer(NULL)
250 , conditions_layer_pointer(NULL)
251 , inputs_pointer(NULL)
252 , outputs_pointer(NULL)
253 , independent_parameters_pointer(NULL)
255 set(other_neural_network);
285 if(
this != &other_neural_network)
515 std::ostringstream buffer;
517 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
518 <<
"MultilayerPerceptron* get_multilayer_perceptron_pointer(void) const method.\n"
519 <<
"Multilayer perceptron pointer is NULL.\n";
521 throw std::logic_error(buffer.str());
540 std::ostringstream buffer;
542 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
543 <<
"ScalingLayer* get_scaling_layer_pointer(void) const method.\n"
544 <<
"Scaling layer pointer is NULL.\n";
546 throw std::logic_error(buffer.str());
565 std::ostringstream buffer;
567 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
568 <<
"UnscalingLayer* get_unscaling_layer_pointer(void) const method.\n"
569 <<
"Unscaling layer pointer is NULL.\n";
571 throw std::logic_error(buffer.str());
590 std::ostringstream buffer;
592 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
593 <<
"BoundingLayer* get_bounding_layer_pointer(void) const method.\n"
594 <<
"Bounding layer pointer is NULL.\n";
596 throw std::logic_error(buffer.str());
615 std::ostringstream buffer;
617 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
618 <<
"ProbabilisticLayer* get_probabilistic_layer_pointer(void) const method.\n"
619 <<
"Probabilistic layer pointer is NULL.\n";
621 throw std::logic_error(buffer.str());
640 std::ostringstream buffer;
642 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
643 <<
"ConditionsLayer* get_conditions_layer_pointer(void) const method.\n"
644 <<
"Conditions layer pointer is NULL.\n";
646 throw std::logic_error(buffer.str());
665 std::ostringstream buffer;
667 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
668 <<
"Inputs* get_inputs_pointer(void) const method.\n"
669 <<
"Inputs pointer is NULL.\n";
671 throw std::logic_error(buffer.str());
690 std::ostringstream buffer;
692 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
693 <<
"Outputs* get_outputs_pointer(void) const method.\n"
694 <<
"Outputs pointer is NULL.\n";
696 throw std::logic_error(buffer.str());
715 std::ostringstream buffer;
717 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
718 <<
"IndependentParameters* get_independent_parameters_pointer(void) const method.\n"
719 <<
"Independent parameters pointer is NULL.\n";
721 throw std::logic_error(buffer.str());
831 void NeuralNetwork::set(
const size_t& new_inputs_number,
const size_t& new_hidden_neurons_number,
const size_t& new_outputs_number)
1105 size_t inputs_number;
1136 return(inputs_number);
1146 size_t outputs_number;
1173 return(outputs_number);
1196 if(inputs_number == 0)
1198 return(architecture);
1201 architecture.push_back(inputs_number);
1245 return(architecture);
1256 size_t parameters_number = 0;
1268 return(parameters_number);
1301 return(network_parameters.
assemble(scaled_independent_parameters));
1326 const size_t size = new_parameters.size();
1330 if(size != parameters_number)
1332 std::ostringstream buffer;
1334 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
1335 <<
"void set_parameters(const Vector<double>&) method.\n"
1336 <<
"Size must be equal to number of parameters.\n";
1338 throw std::logic_error(buffer.str());
1367 const Vector<double> scaled_independent_parameters = new_parameters.
take_out(neural_parameters_number, independent_parameters_number);
1440 size_t inputs_number = 0;
1461 size_t outputs_number = 0;
1482 size_t outputs_number = 0;
1503 size_t outputs_number = 0;
1525 size_t inputs_number = 0;
1526 size_t outputs_number = 0;
1548 size_t inputs_number = 0;
1569 size_t outputs_number = 0;
1710 size_t inputs_number;
1711 size_t outputs_number;
1729 inputs_number = rand()%10 + 1;
1730 outputs_number = rand()%10 + 1;
1852 std::ostringstream buffer;
1854 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
1855 <<
"void prune_input(const size_t&) method.\n"
1856 <<
"Pointer to multilayer perceptron is NULL.\n";
1858 throw std::logic_error(buffer.str());
1890 std::ostringstream buffer;
1892 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
1893 <<
"void prune_output(const size_t&) method.\n"
1894 <<
"Pointer to multilayer perceptron is NULL.\n";
1896 throw std::logic_error(buffer.str());
1954 size_t layers_number = 0;
1986 return(layers_number);
2190 return(parameters_norm);
2243 const size_t inputs_size = inputs.size();
2247 if(inputs_size != inputs_number)
2249 std::ostringstream buffer;
2251 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
2252 <<
"Vector<double> calculate_outputs(const Vector<double>&) const method.\n"
2253 <<
"Size of inputs must be equal to number of inputs.\n";
2255 throw std::logic_error(buffer.str());
2320 const double& minimum,
2321 const double& maximum,
2322 const size_t& points_number)
const
2326 Matrix<double> directional_input_data(points_number, inputs_number);
2332 for(
size_t i = 0; i < points_number; i++)
2334 inputs[direction] = minimum + (maximum-minimum)*i/(
double)(points_number-1);
2336 directional_input_data.
set_row(i, inputs);
2339 return(directional_input_data);
2355 const size_t inputs_size = inputs.size();
2359 if(inputs_size != inputs_number)
2361 std::ostringstream buffer;
2363 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
2364 <<
"Vector<double> calculate_outputs(const Vector<double>&, const Vector<double>&) const method.\n"
2365 <<
"Size of inputs (" << inputs_size <<
") must be equal to number of inputs (" << inputs_number <<
").\n";
2367 throw std::logic_error(buffer.str());
2370 const size_t parameters_size = parameters.size();
2374 if(parameters_size != parameters_number)
2376 std::ostringstream buffer;
2378 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
2379 <<
"Vector<double> calculate_outputs(const Vector<double>&, const Vector<double>&) const method.\n"
2380 <<
"Size of potential parameters (" << parameters_size <<
") must be equal to number of parameters (" << parameters_number <<
").\n";
2382 throw std::logic_error(buffer.str());
2452 if(columns_number != inputs_number)
2454 std::ostringstream buffer;
2456 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
2457 <<
"Matrix<double> calculate_output_data(const Matrix<double>&) const method.\n"
2458 <<
"Number of columns must be equal to number of inputs.\n";
2460 throw std::logic_error(buffer.str());
2467 Matrix<double> output_data(input_vectors_number, outputs_number);
2472 for(
size_t i = 0; i < input_vectors_number; i++)
2476 output_data.
set_row(i, outputs);
2479 return(output_data);
2493 const size_t size = inputs.size();
2497 if(size != inputs_number)
2499 std::ostringstream buffer;
2501 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
2502 <<
"void calculate_Jacobian(const Vector<double>&) const method.\n"
2503 <<
"Size must be equal to number of inputs.\n";
2505 throw std::logic_error(buffer.str());
2577 Jacobian = Jacobian.
dot(bounding_layer_Jacobian);
2584 Jacobian = Jacobian.
dot(probabilistic_layer_Jacobian);
2591 Jacobian = Jacobian.
dot(unscaling_layer_Jacobian);
2598 Jacobian = Jacobian.
dot(multilayer_perceptron_Jacobian);
2605 Jacobian = Jacobian.
dot(scaling_layer_Jacobian);
2619 Jacobian = Jacobian.
dot(conditions_layer_Jacobian);
2642 for(
size_t i = 0; i < input_data_size; i++)
2649 return(Jacobian_data);
2692 std::ostringstream buffer;
2694 buffer <<
"NeuralNetwork\n";
2759 buffer <<
"Display: " <<
display <<
"\n";
2761 return(buffer.str());
2772 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
2774 tinyxml2::XMLElement* neural_network_element = document->NewElement(
"NeuralNetwork");
2776 document->InsertFirstChild(neural_network_element);
2778 std::ostringstream buffer;
2784 tinyxml2::XMLElement* element = document->NewElement(
"Inputs");
2785 neural_network_element->LinkEndChild(element);
2789 const tinyxml2::XMLElement* inputsElement = inputs_document->FirstChildElement(
"Inputs");
2791 DeepClone(element, inputsElement, document, NULL);
2793 delete inputs_document;
2800 tinyxml2::XMLElement* element = document->NewElement(
"ScalingLayer");
2801 neural_network_element->LinkEndChild(element);
2805 const tinyxml2::XMLElement* scaling_layer_element = scaling_layer_document->FirstChildElement(
"ScalingLayer");
2807 DeepClone(element, scaling_layer_element, document, NULL);
2809 delete scaling_layer_document;
2816 tinyxml2::XMLElement* element = document->NewElement(
"MultilayerPerceptron");
2817 neural_network_element->LinkEndChild(element);
2821 const tinyxml2::XMLElement* multilayer_perceptron_element = multilayer_perceptron_document->FirstChildElement(
"MultilayerPerceptron");
2823 DeepClone(element, multilayer_perceptron_element, document, NULL);
2825 delete multilayer_perceptron_document;
2832 tinyxml2::XMLElement* element = document->NewElement(
"UnscalingLayer");
2833 neural_network_element->LinkEndChild(element);
2837 const tinyxml2::XMLElement* unscaling_layer_element = unscaling_layer_document->FirstChildElement(
"UnscalingLayer");
2839 DeepClone(element, unscaling_layer_element, document, NULL);
2841 delete unscaling_layer_document;
2848 tinyxml2::XMLElement* element = document->NewElement(
"ProbabilisticLayer");
2849 neural_network_element->LinkEndChild(element);
2853 const tinyxml2::XMLElement* probabilistic_layer_element = probabilistic_layer_document->FirstChildElement(
"ProbabilisticLayer");
2855 DeepClone(element, probabilistic_layer_element, document, NULL);
2857 delete probabilistic_layer_document;
2864 tinyxml2::XMLElement* element = document->NewElement(
"BoundingLayer");
2865 neural_network_element->LinkEndChild(element);
2869 const tinyxml2::XMLElement* bounding_layer_element = bounding_layer_document->FirstChildElement(
"BoundingLayer");
2871 DeepClone(element, bounding_layer_element, document, NULL);
2873 delete bounding_layer_document;
2880 tinyxml2::XMLElement* element = document->NewElement(
"ConditionsLayer");
2881 neural_network_element->LinkEndChild(element);
2885 const tinyxml2::XMLElement* conditions_layer_element = conditions_layer_document->FirstChildElement(
"ConditionsLayer");
2887 DeepClone(element, conditions_layer_element, document, NULL);
2889 delete conditions_layer_document;
2896 tinyxml2::XMLElement* element = document->NewElement(
"Outputs");
2897 neural_network_element->LinkEndChild(element);
2901 const tinyxml2::XMLElement* outputs_element = outputs_document->FirstChildElement(
"Outputs");
2903 DeepClone(element, outputs_element, document, NULL);
2905 delete outputs_document;
2912 tinyxml2::XMLElement* element = document->NewElement(
"IndependentParameters");
2913 neural_network_element->LinkEndChild(element);
2917 const tinyxml2::XMLElement* independent_parameters_element = independent_parameters_document->FirstChildElement(
"IndependentParameters");
2919 DeepClone(element, independent_parameters_element, document, NULL);
2921 delete independent_parameters_document;
2926 tinyxml2::XMLElement* display_element = document->NewElement(
"Display");
2927 neural_network_element->LinkEndChild(display_element);
2932 tinyxml2::XMLText* display_text = document->NewText(buffer.str().c_str());
2933 display_element->LinkEndChild(display_text);
2947 std::ostringstream buffer;
2949 const tinyxml2::XMLElement* root_element = document.FirstChildElement(
"NeuralNetwork");
2953 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
2954 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
2955 <<
"Neural network element is NULL.\n";
2957 throw std::logic_error(buffer.str());
2962 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"Inputs");
2971 tinyxml2::XMLDocument inputs_document;
2973 tinyxml2::XMLElement* element_clone = inputs_document.NewElement(
"Inputs");
2974 inputs_document.InsertFirstChild(element_clone);
2976 DeepClone(element_clone, element, &inputs_document, NULL);
2984 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"Outputs");
2993 tinyxml2::XMLDocument outputs_document;
2995 tinyxml2::XMLElement* element_clone = outputs_document.NewElement(
"Outputs");
2996 outputs_document.InsertFirstChild(element_clone);
2998 DeepClone(element_clone, element, &outputs_document, NULL);
3006 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"MultilayerPerceptron");
3015 tinyxml2::XMLDocument multilayer_perceptron_document;
3017 tinyxml2::XMLElement* element_clone = multilayer_perceptron_document.NewElement(
"MultilayerPerceptron");
3018 multilayer_perceptron_document.InsertFirstChild(element_clone);
3020 DeepClone(element_clone, element, &multilayer_perceptron_document, NULL);
3028 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ScalingLayer");
3037 tinyxml2::XMLDocument scaling_layer_document;
3039 tinyxml2::XMLElement* element_clone = scaling_layer_document.NewElement(
"ScalingLayer");
3040 scaling_layer_document.InsertFirstChild(element_clone);
3042 DeepClone(element_clone, element, &scaling_layer_document, NULL);
3050 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"UnscalingLayer");
3059 tinyxml2::XMLDocument unscaling_layer_document;
3061 tinyxml2::XMLElement* element_clone = unscaling_layer_document.NewElement(
"UnscalingLayer");
3062 unscaling_layer_document.InsertFirstChild(element_clone);
3064 DeepClone(element_clone, element, &unscaling_layer_document, NULL);
3072 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"BoundingLayer");
3081 tinyxml2::XMLDocument bounding_layer_document;
3083 tinyxml2::XMLElement* element_clone = bounding_layer_document.NewElement(
"BoundingLayer");
3084 bounding_layer_document.InsertFirstChild(element_clone);
3086 DeepClone(element_clone, element, &bounding_layer_document, NULL);
3094 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ProbabilisticLayer");
3103 tinyxml2::XMLDocument probabilistic_layer_document;
3105 tinyxml2::XMLElement* element_clone = probabilistic_layer_document.NewElement(
"ProbabilisticLayer");
3106 probabilistic_layer_document.InsertFirstChild(element_clone);
3108 DeepClone(element_clone, element, &probabilistic_layer_document, NULL);
3116 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ConditionsLayer");
3125 tinyxml2::XMLDocument conditions_layer_document;
3127 tinyxml2::XMLElement* element_clone = conditions_layer_document.NewElement(
"ConditionsLayer");
3128 conditions_layer_document.InsertFirstChild(element_clone);
3130 DeepClone(element_clone, element, &conditions_layer_document, NULL);
3138 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"IndependentParameters");
3147 tinyxml2::XMLDocument independent_parameters_document;
3149 tinyxml2::XMLElement* element_clone = independent_parameters_document.NewElement(
"IndependentParameters");
3150 independent_parameters_document.InsertFirstChild(element_clone);
3152 DeepClone(element_clone, element, &independent_parameters_document, NULL);
3160 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"Display");
3164 const std::string new_display_string = element->GetText();
3170 catch(
const std::logic_error& e)
3172 std::cout << e.what() << std::endl;
3199 tinyxml2::XMLDocument* document =
to_XML();
3201 document->SaveFile(file_name.c_str());
3214 std::ofstream file(file_name.c_str());
3218 std::ostringstream buffer;
3220 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3221 <<
"void save_parameters(const std::string&) const method.\n"
3222 <<
"Cannot open parameters data file.\n";
3224 throw std::logic_error(buffer.str());
3229 file << parameters << std::endl;
3247 tinyxml2::XMLDocument document;
3249 if(document.LoadFile(file_name.c_str()))
3251 std::ostringstream buffer;
3253 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3254 <<
"void load(const std::string&) method.\n"
3255 <<
"Cannot load XML file " << file_name <<
".\n";
3257 throw std::logic_error(buffer.str());
3272 std::ifstream file(file_name.c_str());
3276 std::ostringstream buffer;
3278 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3279 <<
"void load_parameters(const std::string&) method.\n"
3280 <<
"Cannot open parameters data file.\n";
3282 throw std::logic_error(buffer.str());
3289 new_parameters.
load(file_name);
3303 std::ostringstream buffer;
3311 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3312 <<
"std::string write_expression(void) const method.\n"
3313 <<
"Pointer to inputs is NULL.\n";
3315 throw std::logic_error(buffer.str());
3322 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3323 <<
"std::string write_expression(void) const method.\n"
3324 <<
"Pointer to multilayer perceptron is NULL.\n";
3326 throw std::logic_error(buffer.str());
3333 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3334 <<
"std::string write_expression(void) const method.\n"
3335 <<
"Pointer to outputs is NULL.\n";
3337 throw std::logic_error(buffer.str());
3352 for(
size_t i = 0; i < inputs_number; i++)
3356 buffer <<
"scaled_" << inputs_name[i];
3358 scaled_inputs_name[i] = buffer.str();
3365 for(
size_t i = 0; i < outputs_number; i++)
3369 buffer <<
"scaled_" << outputs_name[i];
3371 scaled_outputs_name[i] = buffer.str();
3378 for(
size_t i = 0; i < outputs_number; i++)
3382 buffer <<
"non_probabilistic_" << outputs_name[i];
3384 non_probabilistic_outputs_name[i] = buffer.str();
3435 std::string expression = buffer.str();
3440 std::string replace;
3447 while((pos = expression.find(search, pos)) != std::string::npos)
3449 expression.replace(pos, search.length(), replace);
3450 pos += replace.length();
3458 while((pos = expression.find(search, pos)) != std::string::npos)
3460 expression.replace(pos, search.length(), replace);
3461 pos += replace.length();
3475 std::ofstream file(file_name.c_str());
3479 std::ostringstream buffer;
3481 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3482 <<
"void save_expression(const std::string&) method.\n"
3483 <<
"Cannot open expression text file.\n";
3485 throw std::logic_error(buffer.str());
3503 std::ostringstream buffer;
3507 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3508 <<
"void save_data(const std::string&) const method.\n"
3509 <<
"Pointer to multilayer perceptron is NULL.\n";
3511 throw std::logic_error(buffer.str());
3520 if(inputs_number != 1)
3522 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3523 <<
"void save_data(const std::string&) const method.\n"
3524 <<
"Number of inputs is not 1.\n";
3526 throw std::logic_error(buffer.str());
3535 buffer <<
"OpenNN Exception: NeuralNetwork class.\n"
3536 <<
"void save_data(const std::string&) const method.\n"
3537 <<
"Pointer to scaling layer is NULL.\n";
3539 throw std::logic_error(buffer.str());
3546 const size_t variables_number = inputs_number + outputs_number;
3554 const size_t points_number = 101;
3564 for(
size_t i = 0; i < inputs_number; i++)
3566 inputs[i] = scaling_layer_statistics[i].minimum;
3567 increments[i] = (scaling_layer_statistics[i].maximum - scaling_layer_statistics[i].minimum)/(
double)(points_number-1.0);
3570 for(
size_t i = 0; i < points_number; i++)
3578 inputs += increments;
3581 data.
save(file_name);
Vector< std::string > arrange_names(void) const
void load_parameters(const std::string &)
std::string to_string(void) const
Returns a string representation of the current bonding layer object.
bool has_independent_parameters(void) const
const size_t & get_external_inputs_number(void) const
Returns the number of external inputs.
size_t count_parameters_number(void) const
tinyxml2::XMLDocument * to_XML(void) const
Vector< double > calculate_outputs(const Vector< double > &) const
bool has_inputs(void) const
Outputs * get_outputs_pointer(void) const
Returns a pointer to the outputs object composing this neural network.
void construct_scaling_layer(void)
void prune_scaling_neuron(const size_t &)
Matrix< double > calculate_Jacobian(const Vector< double > &, const Vector< double > &, const Matrix< double > &) const
size_t get_layers_number(void)
tinyxml2::XMLDocument * to_XML(void) const
Matrix< double > arrange_Jacobian(const Vector< double > &) const
Arranges a "Jacobian" matrix from the vector of derivatives.
ScalingLayer * get_scaling_layer_pointer(void) const
Returns a pointer to the scaling layer composing this neural network.
bool display
Display messages to screen.
std::string write_expression(const Vector< std::string > &, const Vector< std::string > &) const
void initialize_random(void)
size_t get_scaling_neurons_number(void) const
Returns the number of unscaling neurons in this layer.
Vector< double > calculate_derivative(const Vector< double > &) const
void randomize_parameters_normal(void)
Vector< T > take_out(const size_t &, const size_t &) const
size_t get_inputs_number(void) const
Returns the number of inputs to the neural network.
void from_XML(const tinyxml2::XMLDocument &)
size_t get_parameters_number(void) const
void destruct_independent_parameters(void)
This method deletes the independent parameters object within the neural network.
bool has_outputs(void) const
Matrix< double > arrange_Jacobian(const Vector< double > &) const
Vector< double > arrange_parameters(void) const
std::string write_expression(void) const
Returns a string with the expression of the function represented by the neural network.
Vector< double > calculate_outputs(const Vector< double > &, const Vector< double > &) const
Vector< Matrix< double > > calculate_Hessian_form(const Vector< double > &) const
void save(const std::string &) const
void construct_outputs(void)
void set_outputs_pointer(Outputs *)
void prune_probabilistic_neuron(void)
size_t get_inputs_number(void) const
Returns the number of inputs to the multilayer perceptron.
BoundingLayer * bounding_layer_pointer
Pointer to a bounding layer object.
const size_t & get_conditions_neurons_number(void) const
Returns the number of conditions neurons.
std::string to_string(void) const
Returns a string representation of the current unscaling layer object.
double calculate_parameters_norm(void) const
Returns the norm of the vector of parameters.
std::string to_string(void) const
Returns a string representation of the current outputs object.
Vector< double > calculate_outputs(const Vector< double > &) const
virtual void from_XML(const tinyxml2::XMLDocument &)
void from_XML(const tinyxml2::XMLDocument &)
IndependentParameters * independent_parameters_pointer
Pointer to an independent parameters object.
std::string to_string(void) const
Returns a string representation of the current probabilistic layer object.
size_t get_layers_number(void) const
Returns the number of layers in the multilayer perceptron.
ScalingLayer * scaling_layer_pointer
Pointer to a scaling layer object.
Vector< double > calculate_outputs(const Vector< double > &) const
void construct_bounding_layer(void)
void from_XML(const tinyxml2::XMLDocument &)
NeuralNetwork & operator=(const NeuralNetwork &)
virtual void set_default(void)
Sets those members which are not pointer to their default values.
void set_scaling_layer_pointer(ScalingLayer *)
Matrix< double > calculate_directional_input_data(const size_t &, const Vector< double > &, const double &, const double &, const size_t &=101) const
void prune_unscaling_neuron(const size_t &)
size_t get_bounding_neurons_number(void) const
Returns the number of bounding neurons in the layer.
Vector< size_t > arrange_layers_perceptrons_numbers(void) const
Returns a vector with the size of each layer.
Vector< Statistics< double > > get_statistics(void) const
void prune_output(const size_t &)
void destruct_scaling_layer(void)
This method deletes the scaling layer within the neural network.
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
void initialize_parameters(const double &)
Initializes all the neural and the independent parameters with a given value.
void set_independent_parameters_pointer(IndependentParameters *)
void destruct_inputs(void)
This method deletes the inputs object within the neural network.
void randomize_parameters_uniform(void)
void randomize_parameters_uniform(void)
ProbabilisticLayer * get_probabilistic_layer_pointer(void) const
Returns a pointer to the probabilistic layer composing this neural network.
void destruct_conditions_layer(void)
This method deletes the conditions layer within the neural network.
void set_parameters(const Vector< double > &)
void set_diagonal(const T &)
virtual tinyxml2::XMLDocument * to_XML(void) const
virtual tinyxml2::XMLDocument * to_XML(void) const
Histogram< T > calculate_histogram(const size_t &=10) const
void destruct_multilayer_perceptron(void)
This method deletes the multilayer perceptron within the neural network.
virtual void from_XML(const tinyxml2::XMLDocument &)
void prune_input(const size_t &)
ConditionsLayer * conditions_layer_pointer
Pointer to a conditions object.
ProbabilisticLayer * probabilistic_layer_pointer
Pointer to a probabilistic layer.
void initialize_random(void)
Initializes at random the probabilistic method.
const size_t & get_probabilistic_neurons_number(void) const
Returns the number of probabilistic neurons in the layer.
Statistics< double > calculate_parameters_statistics(void) const
void print(void) const
Prints to the screen the members of a neural network object in a XML-type format. ...
void construct_conditions_layer(void)
Vector< T > assemble(const Vector< T > &) const
void unscale_parameters(const Vector< double > &)
tinyxml2::XMLDocument * to_XML(void) const
const size_t & get_columns_number(void) const
Returns the number of columns in the matrix.
Inputs * get_inputs_pointer(void) const
Returns a pointer to the inputs object composing this neural network.
void set_probabilistic_layer_pointer(ProbabilisticLayer *)
bool has_conditions_layer(void) const
void save_parameters(const std::string &) const
virtual void from_XML(const tinyxml2::XMLDocument &)
Vector< double > calculate_outputs(const Vector< double > &) const
void destruct_probabilistic_layer(void)
This method deletes the probabilistic layer within the neural network.
MultilayerPerceptron * get_multilayer_perceptron_pointer(void) const
Returns a pointer to the multilayer perceptron composing this neural network.
double calculate_norm(void) const
Returns the vector norm.
void prune_input(const size_t &)
void construct_inputs(void)
tinyxml2::XMLDocument * to_XML(void) const
Serializes the conditions layer object into a document of the TinyXML library.
Vector< double > calculate_derivatives(const Vector< double > &) const
std::string to_string(void) const
Returns a string representation of the current multilayer perceptron object.
bool has_unscaling_layer(void) const
void randomize_parameters_normal(void)
void initialize_random(void)
void randomize_parameters_uniform(void)
Initializes the independent parameters with values comprised between -1 and +1.
UnscalingLayer * unscaling_layer_pointer
Pointer to an unscaling layer object.
tinyxml2::XMLDocument * to_XML(void) const
Matrix< double > calculate_Jacobian(const Vector< double > &) const
std::string to_string(void) const
Returns a string representation of the current conditions layer object.
Matrix< double > calculate_output_data(const Matrix< double > &) const
void initialize_random(void)
Outputs * outputs_pointer
Pointer to an outputs object.
void save_data(const std::string &) const
void set_multilayer_perceptron_pointer(MultilayerPerceptron *)
virtual tinyxml2::XMLDocument * to_XML(void) const
size_t get_outputs_number(void) const
Returns the number of outputs to the neural network.
Vector< Matrix< double > > calculate_Jacobian_data(const Matrix< double > &) const
Matrix< double > calculate_Jacobian(const Vector< double > &) const
void delete_pointers(void)
void from_XML(const tinyxml2::XMLDocument &)
virtual void from_XML(const tinyxml2::XMLDocument &)
void resize_inputs_number(const size_t &)
void from_XML(const tinyxml2::XMLDocument &)
const size_t & get_rows_number(void) const
Returns the number of rows in the matrix.
std::string write_expression(const Vector< std::string > &, const Vector< std::string > &) const
void prune_output(const size_t &)
void construct_independent_parameters(void)
UnscalingLayer * get_unscaling_layer_pointer(void) const
Returns a pointer to the unscaling layer composing this neural network.
size_t get_unscaling_neurons_number(void) const
Returns the number of unscaling neurons in this layer.
Vector< double > calculate_outputs(const Vector< double > &) const
std::string to_string(void) const
Returns a string representation of the current scaling layer object.
void set_unscaling_layer_pointer(UnscalingLayer *)
void initialize_random(void)
Matrix< double > arrange_Jacobian(const Vector< double > &) const
Arranges a "Jacobian" matrix from the vector of derivatives.
void construct_multilayer_perceptron(void)
This method constructs an empty multilayer perceptron within the neural network.
BoundingLayer * get_bounding_layer_pointer(void) const
Returns a pointer to the bounding layer composing this neural network.
ConditionsLayer * get_conditions_layer_pointer(void) const
Returns a pointer to the conditions layer composing this neural network.
IndependentParameters * get_independent_parameters_pointer(void) const
Returns a pointer to the independent parameters object composing this neural network.
std::string write_expression(const Vector< std::string > &, const Vector< std::string > &) const
void save(const std::string &) const
void load(const std::string &)
void initialize_parameters(const double &)
std::string to_string(void) const
Returns a string representation of the current independent parameters object.
void randomize_parameters_normal(void)
void destruct_bounding_layer(void)
This method deletes the bounding layer within the neural network.
void initialize_random(void)
Initializes the lower and upper bounds of all the bounding neurons with random values.
std::string to_string(void) const
Returns a string representation of the current neural network object.
Vector< double > dot(const Vector< double > &) const
void set_bounding_layer_pointer(BoundingLayer *)
Vector< double > calculate_derivatives(const Vector< double > &) const
void initialize_random(void)
void set_inputs_pointer(Inputs *)
Statistics< T > calculate_statistics(void) const
Returns the minimum, maximum, mean and the standard deviation of the elements in the vector...
Vector< double > arrange_parameters(void) const
Returns the values of all the biases and synaptic weights in the multilayer perceptron as a single ve...
std::string write_expression(const Vector< std::string > &, const Vector< std::string > &) const
Returns a string with the expression of the inputs scaling process.
void construct_probabilistic_layer(void)
MultilayerPerceptron * multilayer_perceptron_pointer
Pointer to a multilayer perceptron object.
Inputs * inputs_pointer
Pointer to an inputs object.
bool has_probabilistic_layer(void) const
Vector< size_t > arrange_architecture(void) const
virtual ~NeuralNetwork(void)
Destructor.
Vector< Matrix< double > > calculate_Hessian_form(const Vector< double > &) const
void prune_output(const size_t &)
const bool & get_display(void) const
Vector< double > calculate_scaled_parameters(void) const
void set_conditions_layer_pointer(ConditionsLayer *)
void destruct_outputs(void)
This method deletes the outputs object within the neural network.
tinyxml2::XMLDocument * to_XML(void) const
void prune_bounding_neuron(const size_t &)
void save_expression(const std::string &)
bool has_multilayer_perceptron(void) const
void resize_outputs_number(const size_t &)
void set_display(const bool &)
void destruct_unscaling_layer(void)
This method deletes the unscaling layer within the neural network.
void set_row(const size_t &, const Vector< T > &)
void initialize_parameters(const double &)
virtual void load(const std::string &)
Vector< T > arrange_row(const size_t &) const
void initialize_random(void)
bool has_bounding_layer(void) const
void construct_unscaling_layer(void)
bool operator==(const NeuralNetwork &) const
bool has_scaling_layer(void) const
Matrix< double > calculate_Jacobian(const Vector< double > &) const
void set_parameters(const Vector< double > &)
size_t count_parameters_number(void) const
Returns the number of parameters (biases and synaptic weights) in the multilayer perceptron.
Histogram< double > calculate_parameters_histogram(const size_t &=10) const