41 set(new_outputs_number);
86 if(
this != &other_outputs)
131 if(outputs_number == 0)
153 for(
size_t i = 0; i < outputs_number; i++)
155 names[i] =
items[i].name;
176 if(index >= outputs_number)
178 std::ostringstream buffer;
180 buffer <<
"OpenNN Exception: Outputs class.\n"
181 <<
"const std::string get_name(const size_t&) const method.\n"
182 <<
"Output variable index must be less than number of outputs.\n";
184 throw std::logic_error(buffer.str());
189 return(
items[index].name);
218 if(index >= outputs_number)
220 std::ostringstream buffer;
222 buffer <<
"OpenNN Exception: Outputs class.\n"
223 <<
"const std::string& get_description(const size_t&) const method.\n"
224 <<
"Index of output variable must be less than number of outputs.\n";
226 throw std::logic_error(buffer.str());
260 if(index >= outputs_number)
262 std::ostringstream buffer;
264 buffer <<
"OpenNN Exception: Outputs class.\n"
265 <<
"const std::string get_unit(const size_t&) const method.\n"
266 <<
"Index of output variable must be less than number of outputs.\n";
268 throw std::logic_error(buffer.str());
273 return(
units[index]);
290 for(
size_t i = 0; i < outputs_number; i++)
292 information(i,0) =
items[i].name;
293 information(i,1) =
items[i].units;
294 information(i,2) =
items[i].description;
370 items.set(new_outputs_number);
380 std::ostringstream buffer;
384 for(
size_t i = 0; i < outputs_number; i++)
387 buffer <<
"output_" << i+1;
389 items[i].name = buffer.str();
391 items[i].description =
"";
412 const size_t size = new_names.size();
414 if(size != outputs_number)
416 std::ostringstream buffer;
418 buffer <<
"OpenNN Exception: Outputs class.\n"
419 <<
"void set_names(const Vector<std::string>&) method.\n"
420 <<
"Size of name of outputs vector must be equal to number of output variables.\n";
422 throw std::logic_error(buffer.str());
429 for(
size_t i = 0; i < outputs_number; i++)
431 items[i].name = new_names[i];
451 if(index >= outputs_number)
453 std::ostringstream buffer;
455 buffer <<
"OpenNN Exception: Outputs class.\n"
456 <<
"void set_name(const size_t&, const std::string&) method.\n"
457 <<
"Index of output variable must be less than number of outputs.\n";
459 throw std::logic_error(buffer.str());
466 items[index].name = new_name;
484 const size_t size = new_units.size();
486 if(size != outputs_number)
488 std::ostringstream buffer;
490 buffer <<
"OpenNN Exception: Outputs class.\n"
491 <<
"void set_units(const Vector<std::string>&) method.\n"
492 <<
"Size must be equal to number of output variables.\n";
494 throw std::logic_error(buffer.str());
520 if(index >= outputs_number)
522 std::ostringstream buffer;
524 buffer <<
"OpenNN Exception: Outputs class.\n"
525 <<
"void set_units(const size_t&, const std::string&) method.\n"
526 <<
"Index of output variable must be less than number of outputs.\n";
528 throw std::logic_error(buffer.str());
533 if(
units.size() != outputs_number)
540 units[index] = new_units;
556 const size_t size = new_descriptions.size();
560 if(size != outputs_number)
562 std::ostringstream buffer;
564 buffer <<
"OpenNN Exception: Outputs class.\n"
565 <<
"void set_descriptions(const Vector<std::string>&) method.\n"
566 <<
"Size must be equal to number of outputs.\n";
568 throw std::logic_error(buffer.str());
594 if(index >= outputs_number)
596 std::ostringstream buffer;
598 buffer <<
"OpenNN Exception: Outputs class.\n"
599 <<
"void set_description(const size_t&, const std::string&) method.\n"
600 <<
"Index of output variable must be less than number of outputs.\n";
602 throw std::logic_error(buffer.str());
635 for(
size_t i = 0; i < outputs_number; i++)
637 items[i].name = new_information(i,0);
638 items[i].units = new_information(i,1);
639 items[i].description = new_information(i,2);
665 items.push_back(item);
682 if(index >= outputs_number)
684 std::ostringstream buffer;
686 buffer <<
"OpenNN Exception: Outputs class.\n"
687 <<
"void prune_output(const size_t&) method.\n"
688 <<
"Index of output is equal or greater than number of outputs.\n";
690 throw std::logic_error(buffer.str());
714 std::ostringstream buffer;
716 for(
size_t i = 0; i < outputs_number; i++)
720 buffer <<
"output_" << i+1;
722 default_names[i] = buffer.str();
725 return(default_names);
735 std::ostringstream buffer;
737 buffer <<
"Outputs\n";
741 for(
size_t i = 0; i < outputs_number; i++)
743 buffer <<
"Item " << i+1 <<
":\n"
744 <<
"Name:" <<
items[i].name <<
"\n"
745 <<
"Units:" <<
items[i].units <<
"\n"
746 <<
"Description:" <<
items[i].description <<
"\n";
749 buffer <<
"Display:" <<
display <<
"\n";
751 return(buffer.str());
762 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
766 std::ostringstream buffer;
768 tinyxml2::XMLElement* outputs_element = document->NewElement(
"Outputs");
770 document->InsertFirstChild(outputs_element);
772 tinyxml2::XMLElement* element = NULL;
773 tinyxml2::XMLText* text = NULL;
777 element = document->NewElement(
"OutputsNumber");
778 outputs_element->LinkEndChild(element);
781 buffer << outputs_number;
783 text = document->NewText(buffer.str().c_str());
784 element->LinkEndChild(text);
787 for(
size_t i = 0; i < outputs_number; i++)
789 element = document->NewElement(
"Item");
790 element->SetAttribute(
"Index", (
unsigned)i+1);
791 outputs_element->LinkEndChild(element);
795 tinyxml2::XMLElement* name_element = document->NewElement(
"Name");
796 element->LinkEndChild(name_element);
798 tinyxml2::XMLText* name_text = document->NewText(
items[i].name.c_str());
799 name_element->LinkEndChild(name_text);
803 tinyxml2::XMLElement* units_element = document->NewElement(
"Units");
804 element->LinkEndChild(units_element);
806 tinyxml2::XMLText* units_text = document->NewText(
items[i].
units.c_str());
807 units_element->LinkEndChild(units_text);
811 tinyxml2::XMLElement* description_element = document->NewElement(
"Description");
812 element->LinkEndChild(description_element);
814 tinyxml2::XMLText* descriptionText = document->NewText(
items[i].description.c_str());
815 description_element->LinkEndChild(descriptionText);
820 tinyxml2::XMLElement* display_element = document->NewElement(
"Display");
821 outputs_element->LinkEndChild(display_element);
826 tinyxml2::XMLText* display_text = document->NewText(buffer.str().c_str());
827 display_element->LinkEndChild(display_text);
841 std::ostringstream buffer;
843 const tinyxml2::XMLElement* outputs_element = document.FirstChildElement(
"Outputs");
847 buffer <<
"OpenNN Exception: Outputs class.\n"
848 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
849 <<
"Outputs element is NULL.\n";
851 throw std::logic_error(buffer.str());
856 const tinyxml2::XMLElement* outputs_number_element = outputs_element->FirstChildElement(
"OutputsNumber");
858 if(!outputs_number_element)
860 buffer <<
"OpenNN Exception: Outputs class.\n"
861 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
862 <<
"Outputs number element is NULL.\n";
864 throw std::logic_error(buffer.str());
867 const size_t outputs_number = atoi(outputs_number_element->GetText());
873 const tinyxml2::XMLElement* start_element = outputs_number_element;
875 for(
size_t i = 0; i < outputs_number; i++)
877 const tinyxml2::XMLElement* item_element = start_element->NextSiblingElement(
"Item");
878 start_element = item_element;
882 buffer <<
"OpenNN Exception: Outputs class.\n"
883 <<
"void from_XML(const tinyxml2::XMLElement*) method.\n"
884 <<
"Item " << i+1 <<
" is NULL.\n";
886 throw std::logic_error(buffer.str());
889 item_element->QueryUnsignedAttribute(
"Index", &index);
893 buffer <<
"OpenNN Exception: Outputs class.\n"
894 <<
"void from_XML(const tinyxml2::XMLElement*) method.\n"
895 <<
"Index " << index <<
" is not correct.\n";
897 throw std::logic_error(buffer.str());
902 const tinyxml2::XMLElement* name_element = item_element->FirstChildElement(
"Name");
906 buffer <<
"OpenNN Exception: Outputs class.\n"
907 <<
"void from_XML(const tinyxml2::XMLElement*) method.\n"
908 <<
"Pointer to name element is NULL.\n";
910 throw std::logic_error(buffer.str());
913 if(name_element->GetText())
915 items[index-1].name = name_element->GetText();
920 const tinyxml2::XMLElement* units_element = item_element->FirstChildElement(
"Units");
924 buffer <<
"OpenNN Exception: Outputs class.\n"
925 <<
"void from_XML(const tinyxml2::XMLElement*) method.\n"
926 <<
"Pointer to units element is NULL.\n";
928 throw std::logic_error(buffer.str());
931 if(units_element->GetText())
933 items[index-1].units = units_element->GetText();
938 const tinyxml2::XMLElement* description_element = item_element->FirstChildElement(
"Description");
940 if(!description_element)
942 buffer <<
"OpenNN Exception: Outputs class.\n"
943 <<
"void from_XML(const tinyxml2::XMLElement*) method.\n"
944 <<
"Pointer to description element is NULL.\n";
946 throw std::logic_error(buffer.str());
949 if(description_element->GetText())
951 items[index-1].description = description_element->GetText();
Vector< std::string > arrange_names(void) const
const bool & get_display(void) const
void grow_output(void)
Appends a new item to the outputs.
Vector< std::string > arrange_descriptions(void) const
void set_display(const bool &)
void set_name(const size_t &, const std::string &)
void set_unit(const size_t &, const std::string &)
std::string to_string(void) const
Returns a string representation of the current outputs object.
void set(void)
Sets the size of a vector to zero.
Vector< std::string > arrange_units(void) const
void set_descriptions(const Vector< std::string > &)
Outputs & operator=(const Outputs &)
bool display
Display messages to screen.
void set_information(const Matrix< std::string > &)
virtual tinyxml2::XMLDocument * to_XML(void) const
const std::string & get_description(const size_t &) const
virtual void from_XML(const tinyxml2::XMLDocument &)
bool operator==(const Outputs &) const
bool is_empty(void) const
Returns true if both the number of outputs is zero, and false otherwise.
virtual void set_default(void)
Sets the members of this object to their default values.
Vector< std::string > write_default_names(void) const
Vector< std::string > units
Units of output variables.
Vector< std::string > descriptions
Description of output variables.
const std::string & get_unit(const size_t &) const
void set_description(const size_t &, const std::string &)
void set_outputs_number(const size_t &)
Matrix< std::string > arrange_information(void) const
void prune_output(const size_t &)
Vector< Item > items
Name of output variables.
void set_units(const Vector< std::string > &)
void set_names(const Vector< std::string > &)
virtual ~Outputs(void)
Destructor.
const std::string & get_name(const size_t &) const
size_t get_outputs_number(void) const
Returns the number of outputs neurons in the neural network.