principal_components_layer.cpp
1 // OpenNN: Open Neural Networks Library
2 // www.opennn.net
3 //
4 // P R I N C I P A L C O M P O N E N T S L A Y E R C L A S S H E A D E R
5 //
6 // Artificial Intelligence Techniques SL
7 // artelnics@artelnics.com
8 
9 #include "principal_components_layer.h"
10 
11 namespace OpenNN
12 {
13 
16 
18 {
19  set();
20 }
21 
22 
28 
29 PrincipalComponentsLayer::PrincipalComponentsLayer(const size_t& new_inputs_number, const size_t& new_principal_components_number) : Layer()
30 {
31  set(new_inputs_number, new_principal_components_number);
32 }
33 
34 
36 
38 {
39  set(new_principal_components_layer);
40 }
41 
42 
44 
46 {
47 }
48 
49 
51 
53 {
55 }
56 
57 
59 
61 {
62  if(principal_components_method == NoPrincipalComponents)
63  {
64  return "NoPrincipalComponents";
65  }
66  else if(principal_components_method == PrincipalComponents)
67  {
68  return "PrincipalComponents";
69  }
70  else
71  {
72  ostringstream buffer;
73 
74  buffer << "OpenNN Exception: PrincipalComponentsLayer class.\n"
75  << "string write_principal_components_method() const method.\n"
76  << "Unknown principal components method.\n";
77 
78  throw logic_error(buffer.str());
79  }
80 }
81 
82 
85 
87 {
88  if(principal_components_method == NoPrincipalComponents)
89  {
90  return "no principal components";
91  }
92  else if(principal_components_method == PrincipalComponents)
93  {
94  return "principal components";
95  }
96  else
97  {
98  ostringstream buffer;
99 
100  buffer << "OpenNN Exception: PrincipalComponentsLayer class.\n"
101  << "string write_principal_components_method_text() const method.\n"
102  << "Unknown principal components method.\n";
103 
104  throw logic_error(buffer.str());
105  }
106 }
107 
108 
109 // Matrix<double> get_principal_components() const method
110 
112 
114 {
115  return principal_components;
116 }
117 
118 
119 // Vector<double> get_means() const method
120 
122 
124 {
125  return means;
126 }
127 
128 
129 // Vector<double> get_explained_variance() const
130 
132 
134 {
135  return explained_variance;
136 }
137 
138 
139 // size_t get_inputs_number() const method
140 
142 
144 {
145  return inputs_number;
146 }
147 
148 
150 
152 {
154 }
155 
156 
157 size_t PrincipalComponentsLayer::get_neurons_number() const
158 {
160 }
161 
162 
165 
167 {
168 /*
169  const size_t inputs_number = inputs.get_columns_number();
170 
171  #ifdef __OPENNN_DEBUG__
172 
173  ostringstream buffer;
174 
175  if(principal_components.get_rows_number() != inputs_number)
176  {
177  buffer << "OpenNN Exception: PrincipalComponentsLayer class.\n"
178  << "Matrix<double> calculate_outputs(Matrix Vector<double>&) const method.\n"
179  << "Size of inputs must be equal to the number of rows of the principal components matrix.\n";
180 
181  throw logic_error(buffer.str());
182  }
183 
184  #endif
185 
186  if(write_principal_components_method() != "PrincipalComponents")
187  {
188  return inputs;
189  }
190 
191  const Vector<size_t> principal_components_indices(0, 1.0, get_principal_components_number()-1);
192 
193  const Vector<size_t> inputs_indices(0, 1.0, inputs_number-1);
194 
195  const Matrix<double> used_principal_components = principal_components.get_submatrix(principal_components_indices, inputs_indices);
196 
197  const Matrix<double> inputs_adjust = inputs.subtract_rows(means);
198 
199  return dot(inputs_adjust, used_principal_components.calculate_transpose());
200 
201  for(size_t i = 0; i < points_number; i++)
202  {
203  const Vector<size_t> principal_components_indices(0, 1.0, get_principal_components_number()-1);
204 
205  const Vector<size_t> inputs_indices(0, 1.0, inputs_number-1);
206 
207  const Matrix<double> used_principal_components = principal_components.get_submatrix(principal_components_indices, inputs_indices);
208 
209  // Data adjust
210 
211  const Matrix<double> inputs_adjust = inputs.subtract_rows(means);
212 
213 // Vector<double> inputs_adjust(inputs_number);
214 
215 // for(size_t j = 0; j < inputs_number; j++)
216 // {
217 // inputs_adjust[j] = inputs[j] - means[j];
218 // }
219 
220  // Outputs
221 
222  const size_t principal_components_number = used_principal_components.get_rows_number();
223 
224  Matrix<double> outputs(points_number, principal_components_number);
225 
226  for(size_t j = 0; j < principal_components_number; j++)
227  {
228  outputs(i,j) = inputs_adjust.dot(used_principal_components.get_row(j));
229  }
230 
231  }
232 
233  return outputs;
234  */
235  return Tensor<double>();
236 }
237 
238 
240 
241 string PrincipalComponentsLayer::write_expression(const Vector<string>& inputs_names, const Vector<string>& outputs_names) const
242 {
244  {
245  case NoPrincipalComponents:
246  {
247  return(write_no_principal_components_expression(inputs_names, outputs_names));
248  }
249 
250  case PrincipalComponents:
251  {
252  return(write_principal_components_expression(inputs_names, outputs_names));
253  }
254  }
255 
256  // Default
257 
258  ostringstream buffer;
259 
260  buffer << "OpenNN Exception: ScalingLayer class.\n"
261  << "string write_expression() const method.\n"
262  << "Unknown principal components method.\n";
263 
264  throw logic_error(buffer.str());
265 }
266 
267 
269 /*/// @param inputs_names Name of inputs to the principal components.
271 
272 
273 string PrincipalComponentsLayer::write_no_principal_components_expression(const Vector<string>&, const Vector<string>& ) const
274 {
275  ostringstream buffer;
276 
277  buffer << "";
278 
279  return buffer.str();
280 }
281 
282 
286 
287 
288 string PrincipalComponentsLayer::write_principal_components_expression(const Vector<string>& inputs_names, const Vector<string>& outputs_names) const
289 {
290  ostringstream buffer;
291 
292  buffer.precision(10);
293 
294  const size_t inputs_number = get_inputs_number();
295  const size_t principal_components_number = get_principal_components_number();
296 
297  for(size_t i = 0; i < principal_components_number;i ++)
298  {
299  buffer << outputs_names[i] << "= (";
300 
301  for(size_t j = 0; j < inputs_number; j++)
302  {
303  buffer << principal_components(i,j) << "*" << inputs_names[j];
304 
305  if(j != inputs_number-1)
306  {
307  buffer << "+";
308  }
309  }
310 
311  buffer << ");\n";
312  }
313 
314  return buffer.str();
315 }
316 
317 
318 // const bool& get_display() const method
319 
322 
323 const bool& PrincipalComponentsLayer::get_display() const
324 {
325  return display;
326 }
327 
328 
329 // void set() method
330 
332 
333 void PrincipalComponentsLayer::set()
334 {
335  set_inputs_number(0);
336  set_principal_components_number(0);
337 
338  means.set();
339  explained_variance.set();
340  principal_components.set();
341 
342  set_default();
343 }
344 
345 
346 // void set(const size_t&, const size_t&)
347 
352 
353 void PrincipalComponentsLayer::set(const size_t& new_inputs_number, const size_t& new_principal_components_number)
354 {
355  set_inputs_number(new_inputs_number);
356  set_principal_components_number(new_principal_components_number);
357 
358  means.set(new_inputs_number, 0.0);
359 
360  explained_variance.set(new_inputs_number, 0.0);
361 
362  principal_components.set(new_principal_components_number, new_inputs_number, 0.0);
363 
364  set_default();
365 }
366 
367 
368 // void set(const PrincipalComponentsLayer&) method
369 
372 
373 void PrincipalComponentsLayer::set(const PrincipalComponentsLayer& new_principal_components_layer)
374 {
375  principal_components_method = new_principal_components_layer.principal_components_method;
376 
377  principal_components = new_principal_components_layer.principal_components;
378 
379  means = new_principal_components_layer.means;
380 
381  display = new_principal_components_layer.display;
382 }
383 
384 
385 // void set_principal_components(const Matrix<double>&) method
386 
389 
390 void PrincipalComponentsLayer::set_principal_components(const Matrix<double>& new_principal_components)
391 {
392  principal_components = new_principal_components;
393 
394  means.set();
395 
396  set_default();
397 }
398 
399 
400 // void set_inputs_number(const size_t&) method
401 
404 
405 void PrincipalComponentsLayer::set_inputs_number(const size_t& new_inputs_number)
406 {
407  inputs_number = new_inputs_number;
408 }
409 
410 
411 // void set_principal_components_number(const size_t&) method
412 
415 
416 void PrincipalComponentsLayer::set_principal_components_number(const size_t& new_principal_components_number)
417 {
418  principal_components_number = new_principal_components_number;
419 }
420 
421 
422 // void set_principal_component(const Matrix<double>&) method
423 
427 
428 void PrincipalComponentsLayer::set_principal_component(const size_t& index, const Vector<double>& principal_component)
429 {
430  principal_components.set_row(index, principal_component);
431 }
432 
433 
434 // void set_means(const Vector<double>&) method
435 
438 
439 void PrincipalComponentsLayer::set_means(const Vector<double>& new_means)
440 {
441  means = new_means;
442 }
443 
444 
445 // void set_means(const size_t&, const double&) method
446 
450 
451 void PrincipalComponentsLayer::set_means(const size_t& new_size, const double& new_value)
452 {
453  means.set(new_size, new_value);
454 }
455 
456 
457 // void set_explained_variance(const Vector<double>&) method
458 
461 
462 void PrincipalComponentsLayer::set_explained_variance(const Vector<double>& new_explained_variance)
463 {
464  explained_variance = new_explained_variance;
465 }
466 
467 
472 
473 // void set_default() method
474 
475 void PrincipalComponentsLayer::set_default()
476 {
477  principal_components_method = NoPrincipalComponents;
478 
479  set_display(true);
480 }
481 
482 
485 
486 void PrincipalComponentsLayer::set_principal_components_method(const PrincipalComponentsMethod & new_method)
487 {
488  principal_components_method = new_method;
489 }
490 
491 
494 
495 void PrincipalComponentsLayer::set_principal_components_method(const string & new_method_string)
496 {
497  if(new_method_string == "NoPrincipalComponents")
498  {
499  principal_components_method = NoPrincipalComponents;
500  }
501  else if(new_method_string == "PrincipalComponents")
502  {
503  principal_components_method = PrincipalComponents;
504  }
505  else
506  {
507  ostringstream buffer;
508 
509  buffer << "OpenNN Exception: PrincipalComponentsLayer class.\n"
510  << "void set_principal_components_method(const string&) method.\n"
511  << "Unknown principal components method: " << new_method_string << ".\n";
512 
513  throw logic_error(buffer.str());
514  }
515 }
516 
517 
518 // void set_display(const bool&) method
519 
524 
525 void PrincipalComponentsLayer::set_display(const bool& new_display)
526 {
527  display = new_display;
528 }
529 
530 
531 // tinyxml2::XMLDocument* to_XML() const method
532 
535 
536 tinyxml2::XMLDocument* PrincipalComponentsLayer::to_XML() const
537 {
538  tinyxml2::XMLDocument* document = new tinyxml2::XMLDocument;
539  /*
540  ostringstream buffer;
541 
542  tinyxml2::XMLElement* principal_components_layer_element = document->NewElement("PrincipalComponentsLayer");
543 
544  document->InsertFirstChild(principal_components_layer_element);
545 
546  // Principal components neurons number
547 
548  tinyxml2::XMLElement* size_element = document->NewElement("PrincipalComponentsNeuronsNumber");
549  principal_components_layer_element->LinkEndChild(size_element);
550 
551  const size_t principal_components_neurons_number = get_principal_components_neurons_number();
552 
553  buffer.str("");
554  buffer << principal_components_neurons_number;
555 
556  tinyxml2::XMLText* size_text = document->NewText(buffer.str().c_str());
557  size_element->LinkEndChild(size_text);
558 
559  // Principal components matrix
560 
561  for(size_t i = 0; i < principal_components_neurons_number; i++)
562  {
563  tinyxml2::XMLElement* principal_components_element = document->NewElement("PrincipalComponents");
564  principal_components_element->SetAttribute("Index",(unsigned)i+1);
565 
566  principal_components_layer_element->LinkEndChild(principal_components_element);
567 
568  // Eigenvector
569 
570  tinyxml2::XMLElement* eigenvector_element = document->NewElement("Eigenvector");
571  principal_components_element->LinkEndChild(eigenvector_element);
572 
573  buffer.str("");
574  buffer << principal_components.get_row(i);
575 
576  tinyxml2::XMLText* eigenvector_text = document->NewText(buffer.str().c_str());
577  eigenvector_element->LinkEndChild(eigenvector_text);
578  }
579 
580  // Means
581 
582  tinyxml2::XMLElement* means_element = document->NewElement("Means");
583  means_element->LinkEndChild(means_element);
584 
585  buffer.str("");
586  buffer << means;
587 
588  tinyxml2::XMLText* means_text = document->NewText(buffer.str().c_str());
589  means_element->LinkEndChild(means_text);
590 
591  // Principal components method
592 
593  tinyxml2::XMLElement* method_element = document->NewElement("PrincipalComponentsMethod");
594  principal_components_layer_element->LinkEndChild(method_element);
595 
596  tinyxml2::XMLText* method_text = document->NewText(write_principal_components_method().c_str());
597  method_element->LinkEndChild(method_text);
598 */
599  return document;
600 }
601 
602 
603 // void write_XML(tinyxml2::XMLPrinter&) const method
604 
607 
608 void PrincipalComponentsLayer::write_XML(tinyxml2::XMLPrinter& file_stream) const
609 {
610  ostringstream buffer;
611 
612  file_stream.OpenElement("PrincipalComponentsLayer");
613 
614  // Inputs number
615 
616  const size_t inputs_number = get_inputs_number();
617 
618  file_stream.OpenElement("InputsNumber");
619 
620  buffer.str("");
621  buffer << inputs_number;
622 
623  file_stream.PushText(buffer.str().c_str());
624 
625  file_stream.CloseElement();
626 
627  // Principal components neurons number
628 
629  const size_t principal_components_number = get_principal_components_number();
630 
631  file_stream.OpenElement("PrincipalComponentsNumber");
632 
633  buffer.str("");
634  buffer << principal_components_number;
635 
636  file_stream.PushText(buffer.str().c_str());
637 
638  file_stream.CloseElement();
639 
640  if(principal_components_number != 0)
641  {
642  // Means
643 
644  file_stream.OpenElement("Means");
645 
646  buffer.str("");
647  buffer << get_means();
648 
649  file_stream.PushText(buffer.str().c_str());
650 
651  file_stream.CloseElement();
652 
653  // Explained variance
654 
655  file_stream.OpenElement("ExplainedVariance");
656 
657  buffer.str("");
658  buffer << get_explained_variance();
659 
660  file_stream.PushText(buffer.str().c_str());
661 
662  file_stream.CloseElement();
663 
664  // Principal components matrix
665 
666  for(size_t i = 0; i < inputs_number/*principal_components_number*/; i++)
667  {
668  file_stream.OpenElement("PrincipalComponent");
669 
670  file_stream.PushAttribute("Index", static_cast<unsigned>(i)+1);
671 
672  // Principal component
673 
674  buffer.str("");
675  buffer << principal_components.get_row(i);
676 
677  file_stream.PushText(buffer.str().c_str());
678 
679  file_stream.CloseElement();
680  }
681 
682  // Principal components method
683 
684  file_stream.OpenElement("PrincipalComponentsMethod");
685  file_stream.PushText(write_principal_components_method().c_str());
686  file_stream.CloseElement();
687  }
688  else
689  {
690  // Principal components method
691 
692  file_stream.OpenElement("PrincipalComponentsMethod");
693  file_stream.PushText(write_principal_components_method().c_str());
694  file_stream.CloseElement();
695  }
696 
697  file_stream.CloseElement();
698 }
699 
700 
701 // void from_XML(const tinyxml2::XMLDocument&) method
702 
705 
706 void PrincipalComponentsLayer::from_XML(const tinyxml2::XMLDocument& document)
707 {
708  ostringstream buffer;
709 
710  const tinyxml2::XMLElement* principal_components_layer_element = document.FirstChildElement("PrincipalComponentsLayer");
711 
712  if(!principal_components_layer_element)
713  {
714  buffer << "OpenNN Exception: PrincipalComponentsLayer class.\n"
715  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
716  << "Principal components layer element is nullptr.\n";
717 
718  throw logic_error(buffer.str());
719  }
720 
721  // Inputs number
722 
723  const tinyxml2::XMLElement* inputs_number_element = principal_components_layer_element->FirstChildElement("InputsNumber");
724 
725  if(!inputs_number_element)
726  {
727  buffer << "OpenNN Exception: ScalingLayer class.\n"
728  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
729  << "Inputs number element is nullptr.\n";
730 
731  throw logic_error(buffer.str());
732  }
733 
734  const size_t inputs_number = static_cast<size_t>(atoi(inputs_number_element->GetText()));
735 
736  set_inputs_number(inputs_number);
737 
738  // Principal components number
739 
740  const tinyxml2::XMLElement* principal_components_number_element = principal_components_layer_element->FirstChildElement("PrincipalComponentsNumber");
741 
742  if(!principal_components_number_element)
743  {
744  buffer << "OpenNN Exception: ScalingLayer class.\n"
745  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
746  << "Principal components number element is nullptr.\n";
747 
748  throw logic_error(buffer.str());
749  }
750 
751  const size_t principal_components_number = static_cast<size_t>(atoi(principal_components_number_element->GetText()));
752 
753  set_principal_components_number(principal_components_number);
754 
755 // if(principal_components_number != 0)
756 // {
757 // set(inputs_number, principal_components_number);
758 // }
759 // else
760 // {
761 // set(inputs_number, inputs_number);
762 // }
763 
764  if(principal_components_number != 0)
765  {
766  // Means
767 
768  const tinyxml2::XMLElement* means_element = principal_components_layer_element->FirstChildElement("Means");
769 
770  if(!means_element)
771  {
772  buffer << "OpenNN Exception: PrincipalComponentsLayer class.\n"
773  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
774  << "Means element is nullptr.\n";
775 
776  throw logic_error(buffer.str());
777  }
778  else
779  {
780  const char* means_text = means_element->GetText();
781 
782  if(means_text)
783  {
784  Vector<double> new_means;
785  new_means.parse(means_text);
786 
787  try
788  {
789  set_means(new_means);
790  }
791  catch(const logic_error& e)
792  {
793  cerr << e.what() <<endl;
794  }
795  }
796  }
797 
798  // Explained variance
799 
800  const tinyxml2::XMLElement* explained_variance_element = principal_components_layer_element->FirstChildElement("ExplainedVariance");
801 
802  if(!explained_variance_element)
803  {
804  buffer << "OpenNN Exception: PrincipalComponentsLayer class.\n"
805  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
806  << "ExplainedVariance element is nullptr.\n";
807 
808  throw logic_error(buffer.str());
809  }
810  else
811  {
812  const char* explained_variance_text = explained_variance_element->GetText();
813 
814  if(explained_variance_text)
815  {
816  Vector<double> new_explained_variance;
817  new_explained_variance.parse(explained_variance_text);
818 
819  try
820  {
821  set_explained_variance(new_explained_variance);
822  }
823  catch(const logic_error& e)
824  {
825  cerr << e.what() <<endl;
826  }
827  }
828  }
829 
830  // Principal components
831 
832  principal_components.set(inputs_number, inputs_number);
833 
834  unsigned index = 0; // size_t does not work
835 
836  const tinyxml2::XMLElement* start_element = means_element;
837 
838  for(size_t i = 0; i < inputs_number/*principal_components_number*/; i++)
839  {
840  const tinyxml2::XMLElement* principal_components_element = start_element->NextSiblingElement("PrincipalComponent");
841  start_element = principal_components_element;
842 
843  if(!principal_components_element)
844  {
845  buffer << "OpenNN Exception: PrincipalComponentsLayer class.\n"
846  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
847  << "Principal component number " << i+1 << " is nullptr.\n";
848 
849  throw logic_error(buffer.str());
850  }
851 
852  principal_components_element->QueryUnsignedAttribute("Index", &index);
853 
854  if(index != i+1)
855  {
856  buffer << "OpenNN Exception: PrincipalComponentsLayer class.\n"
857  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
858  << "Index " << index << " is not correct.\n";
859 
860  throw logic_error(buffer.str());
861  }
862 
863  // Principal component
864 
865  const char* principal_component_text = principal_components_element->GetText();
866 
867  if(principal_component_text)
868  {
869  Vector<double> principal_component;
870  principal_component.parse(principal_component_text);
871 
872  try
873  {
874  set_principal_component(i, principal_component);
875  }
876  catch(const logic_error& e)
877  {
878  cerr << e.what() <<endl;
879  }
880  }
881  }
882  }
883 
884  // Principal components method
885 
886  const tinyxml2::XMLElement* principal_components_method_element = principal_components_layer_element->FirstChildElement("PrincipalComponentsMethod");
887 
888  if(principal_components_method_element)
889  {
890  string new_method = principal_components_method_element->GetText();
891 
892  try
893  {
894  set_principal_components_method(new_method);
895  }
896  catch(const logic_error& e)
897  {
898  cerr << e.what() << endl;
899  }
900  }
901 }
902 
903 }
904 
905 
906 // OpenNN: Open Neural Networks Library.
907 // Copyright(C) 2005-2019 Artificial Intelligence Techniques, SL.
908 //
909 // This library is free software; you can redistribute it and/or
910 // modify it under the terms of the GNU Lesser General Public
911 // License as published by the Free Software Foundation; either
912 // version 2.1 of the License, or any later version.
913 //
914 // This library is distributed in the hope that it will be useful,
915 // but WITHOUT ANY WARRANTY; without even the implied warranty of
916 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
917 // Lesser General Public License for more details.
918 
919 // You should have received a copy of the GNU Lesser General Public
920 // License along with this library; if not, write to the Free Software
921 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
OpenNN::PrincipalComponentsLayer::~PrincipalComponentsLayer
virtual ~PrincipalComponentsLayer()
Destructor.
Definition: principal_components_layer.cpp:45
OpenNN::PrincipalComponentsLayer
This class represents the layer of principal component analysis.
Definition: principal_components_layer.h:43
OpenNN::PrincipalComponentsLayer::write_no_principal_components_expression
string write_no_principal_components_expression(const Vector< string > &, const Vector< string > &) const
Returns a string with the expression of the principal components process when none method is used.
Definition: principal_components_layer.cpp:273
tinyxml2::XMLElement::QueryUnsignedAttribute
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1325
OpenNN::PrincipalComponentsLayer::principal_components
Matrix< double > principal_components
Definition: principal_components_layer.h:161
OpenNN::PrincipalComponentsLayer::set
void set()
Sets the principal components layer to be empty.
Definition: principal_components_layer.cpp:333
OpenNN::PrincipalComponentsLayer::write_expression
string write_expression(const Vector< string > &, const Vector< string > &) const
Returns a string with the expression of the principal components process.
Definition: principal_components_layer.cpp:241
OpenNN::PrincipalComponentsLayer::principal_components_number
size_t principal_components_number
Principal components number.
Definition: principal_components_layer.h:152
OpenNN::PrincipalComponentsLayer::write_principal_components_method
string write_principal_components_method() const
Returns a string with the name of the method used for principal components layer.
Definition: principal_components_layer.cpp:60
tinyxml2::XMLPrinter::PushText
void PushText(const char *text, bool cdata=false)
Add a text node.
Definition: tinyxml2.cpp:2627
tinyxml2::XMLDocument
Definition: tinyxml2.h:1649
OpenNN::PrincipalComponentsLayer::explained_variance
Vector< double > explained_variance
Explained variances for every of the principal components.
Definition: principal_components_layer.h:165
OpenNN::Matrix< double >
OpenNN::PrincipalComponentsLayer::means
Vector< double > means
Means of the input variables.
Definition: principal_components_layer.h:156
OpenNN::PrincipalComponentsLayer::get_principal_components_method
const PrincipalComponentsMethod & get_principal_components_method() const
Returns the method used for principal components layer.
Definition: principal_components_layer.cpp:52
OpenNN::PrincipalComponentsLayer::get_inputs_number
size_t get_inputs_number() const
Returns the number of inputs to the layer.
Definition: principal_components_layer.cpp:143
OpenNN::Tensor< double >
OpenNN::Layer
This abstract class represents the concept of layer of neurons in OpenNN.
Definition: layer.h:38
OpenNN::PrincipalComponentsLayer::principal_components_method
PrincipalComponentsMethod principal_components_method
Principal components layer method.
Definition: principal_components_layer.h:169
OpenNN::PrincipalComponentsLayer::write_principal_components_method_text
string write_principal_components_method_text() const
Definition: principal_components_layer.cpp:86
tinyxml2::XMLPrinter::PushAttribute
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
Definition: tinyxml2.cpp:2538
OpenNN::PrincipalComponentsLayer::PrincipalComponentsLayer
PrincipalComponentsLayer()
Definition: principal_components_layer.cpp:17
tinyxml2::XMLPrinter
Definition: tinyxml2.h:2150
tinyxml2::XMLPrinter::CloseElement
virtual void CloseElement(bool compactMode=false)
If streaming, close the Element.
Definition: tinyxml2.cpp:2589
OpenNN::PrincipalComponentsLayer::get_explained_variance
Vector< double > get_explained_variance() const
Returns a vector containing the explained variance of every of the principal components.
Definition: principal_components_layer.cpp:133
OpenNN::Vector::parse
void parse(const string &)
Definition: vector.h:4575
OpenNN::PrincipalComponentsLayer::calculate_outputs
Tensor< double > calculate_outputs(const Tensor< double > &)
Definition: principal_components_layer.cpp:166
tinyxml2::XMLNode::NextSiblingElement
const XMLElement * NextSiblingElement(const char *name=0) const
Get the next(right) sibling element of this node, with an optionally supplied name.
Definition: tinyxml2.cpp:964
OpenNN::PrincipalComponentsLayer::get_principal_components_number
size_t get_principal_components_number() const
Returns the number of principal components.
Definition: principal_components_layer.cpp:151
OpenNN::PrincipalComponentsLayer::get_means
Vector< double > get_means() const
Returns a vector containing the means of every input variable in the data set.
Definition: principal_components_layer.cpp:123
OpenNN::Vector< double >
OpenNN::PrincipalComponentsLayer::get_principal_components
Matrix< double > get_principal_components() const
Returns a matrix containing the principal components.
Definition: principal_components_layer.cpp:113
OpenNN::PrincipalComponentsLayer::write_principal_components_expression
string write_principal_components_expression(const Vector< string > &, const Vector< string > &) const
Definition: principal_components_layer.cpp:288
tinyxml2::XMLElement
Definition: tinyxml2.h:1239
OpenNN::PrincipalComponentsLayer::PrincipalComponentsMethod
PrincipalComponentsMethod
Enumeration of available methods for apply the principal components layer.
Definition: principal_components_layer.h:68
OpenNN::PrincipalComponentsLayer::inputs_number
size_t inputs_number
Inputs number.
Definition: principal_components_layer.h:148