PrincipalComponentsLayer Class Reference

This class represents the layer of principal component analysis. More...

#include <principal_components_layer.h>

Inheritance diagram for PrincipalComponentsLayer:
Layer

Public Types

enum  PrincipalComponentsMethod { NoPrincipalComponents, PrincipalComponents }
 Enumeration of available methods for apply the principal components layer.
 
- Public Types inherited from Layer
enum  LayerType {
  Scaling, Convolutional, Perceptron, Pooling,
  Probabilistic, LongShortTermMemory, Recurrent, Unscaling,
  Bounding, PrincipalComponents
}
 This enumeration represents the possible types of layers.
 

Public Member Functions

 PrincipalComponentsLayer ()
 
 PrincipalComponentsLayer (const size_t &, const size_t &)
 
 PrincipalComponentsLayer (const PrincipalComponentsLayer &)
 Copy constructor.
 
virtual ~PrincipalComponentsLayer ()
 Destructor.
 
const PrincipalComponentsMethodget_principal_components_method () const
 Returns the method used for principal components layer.
 
string write_principal_components_method () const
 Returns a string with the name of the method used for principal components layer.
 
string write_principal_components_method_text () const
 
Matrix< double > get_principal_components () const
 Returns a matrix containing the principal components.
 
Vector< double > get_means () const
 Returns a vector containing the means of every input variable in the data set.
 
Vector< double > get_explained_variance () const
 Returns a vector containing the explained variance of every of the principal components.
 
size_t get_inputs_number () const
 Returns the number of inputs to the layer.
 
size_t get_principal_components_number () const
 Returns the number of principal components.
 
size_t get_neurons_number () const
 
const bool & get_display () const
 
void set ()
 Sets the principal components layer to be empty.
 
void set (const size_t &, const size_t &)
 
void set (const PrincipalComponentsLayer &)
 
void set_inputs_number (const size_t &)
 
void set_principal_components_number (const size_t &)
 
void set_principal_component (const size_t &, const Vector< double > &)
 
void set_principal_components (const Matrix< double > &)
 
void set_means (const Vector< double > &)
 
void set_means (const size_t &, const double &)
 
void set_explained_variance (const Vector< double > &)
 
virtual void set_default ()
 
void set_principal_components_method (const PrincipalComponentsMethod &)
 
void set_principal_components_method (const string &)
 
void set_display (const bool &)
 
Tensor< double > calculate_outputs (const Tensor< double > &)
 
string write_expression (const Vector< string > &, const Vector< string > &) const
 Returns a string with the expression of the principal components process.
 
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.
 
string write_principal_components_expression (const Vector< string > &, const Vector< string > &) const
 
tinyxml2::XMLDocumentto_XML () const
 
virtual void from_XML (const tinyxml2::XMLDocument &)
 
void write_XML (tinyxml2::XMLPrinter &) const
 
- Public Member Functions inherited from Layer
virtual void initialize_parameters (const double &)
 
virtual void randomize_parameters_uniform (const double &=-1.0, const double &=1.0)
 
virtual void randomize_parameters_normal (const double &=0.0, const double &=1.0)
 
virtual Vector< double > get_parameters () const
 
virtual size_t get_parameters_number () const
 
virtual void set_parameters (const Vector< double > &)
 
virtual Tensor< double > calculate_outputs (const Tensor< double > &, const Vector< double > &)
 
virtual Vector< double > calculate_error_gradient (const Tensor< double > &, const Layer::FirstOrderActivations &, const Tensor< double > &)
 
virtual FirstOrderActivations calculate_first_order_activations (const Tensor< double > &)
 
virtual Tensor< double > calculate_output_delta (const Tensor< double > &, const Tensor< double > &) const
 
virtual Tensor< double > calculate_hidden_delta (Layer *, const Tensor< double > &, const Tensor< double > &, const Tensor< double > &) const
 
virtual Vector< size_t > get_input_variables_dimensions () const
 
virtual void set_neurons_number (const size_t &)
 
virtual string object_to_string () const
 
LayerType get_type () const
 
string get_type_string () const
 Takes the type of layer used by the model.
 

Protected Attributes

size_t inputs_number
 Inputs number.
 
size_t principal_components_number
 Principal components number.
 
Vector< double > means
 Means of the input variables.
 
Matrix< double > principal_components
 
Vector< double > explained_variance
 Explained variances for every of the principal components.
 
PrincipalComponentsMethod principal_components_method
 Principal components layer method.
 
bool display
 Display warning messages to screen.
 
- Protected Attributes inherited from Layer
LayerType layer_type = Perceptron
 Layer type object.
 

Detailed Description

This class represents the layer of principal component analysis.

This layer is used to reduce the dimension of a dataset.

Definition at line 43 of file principal_components_layer.h.

Constructor & Destructor Documentation

◆ PrincipalComponentsLayer() [1/2]

Default constructor. It creates a scaling layer object with no scaling neurons.

Definition at line 17 of file principal_components_layer.cpp.

◆ PrincipalComponentsLayer() [2/2]

PrincipalComponentsLayer ( const size_t &  new_inputs_number,
const size_t &  new_principal_components_number 
)
explicit

Principal components neurons number constructor. This constructor creates a principal components layer layer with a given size. The members of this object are initialized with the default values.

Parameters
new_inputs_numberNumber of original inputs.
new_principal_components_numberNumber of principal components neurons in the layer.

Definition at line 29 of file principal_components_layer.cpp.

Member Function Documentation

◆ calculate_outputs()

Tensor< double > calculate_outputs ( const Tensor< double > &  inputs)
virtual

Performs the principal component analysis to produce a reduced data set.

Parameters
inputsSet of inputs to the principal components layer.

Reimplemented from Layer.

Definition at line 166 of file principal_components_layer.cpp.

◆ from_XML()

void from_XML ( const tinyxml2::XMLDocument document)
virtual

Deserializes a TinyXML document into this principal components layer object.

Parameters
documentXML document containing the member data.

Definition at line 706 of file principal_components_layer.cpp.

◆ get_display()

const bool & get_display ( ) const

Returns true if messages from this class are to be displayed on the screen, or false if messages from this class are not to be displayed on the screen.

Definition at line 323 of file principal_components_layer.cpp.

◆ set() [1/2]

void set ( const PrincipalComponentsLayer new_principal_components_layer)

Sets the members of this object to be the members of another object of the same class.

Parameters
new_principal_components_layerObject to be copied.

Definition at line 373 of file principal_components_layer.cpp.

◆ set() [2/2]

void set ( const size_t &  new_inputs_number,
const size_t &  new_principal_components_number 
)

Sets a new size to the principal components layer. It also sets means and eigenvector matrix to zero.

Parameters
new_inputs_numberNew inputs number.
new_principal_components_numberNew principal components number.

Definition at line 353 of file principal_components_layer.cpp.

◆ set_default()

void set_default ( )
virtual

Sets the members to their default value.

  • Display: true.

Definition at line 475 of file principal_components_layer.cpp.

◆ set_display()

void set_display ( const bool &  new_display)

Sets a new display value. If it is set to true messages from this class are to be displayed on the screen; if it is set to false messages from this class are not to be displayed on the screen.

Parameters
new_displayDisplay value.

Definition at line 525 of file principal_components_layer.cpp.

◆ set_explained_variance()

void set_explained_variance ( const Vector< double > &  new_explained_variance)

Sets a new value to the explained variance member.

Parameters
new_explained_varianceObject to be set.

Definition at line 462 of file principal_components_layer.cpp.

◆ set_inputs_number()

void set_inputs_number ( const size_t &  new_inputs_number)
virtual

Sets a new value for the inputs number member.

Parameters
new_inputs_numberNew inputs number.

Reimplemented from Layer.

Definition at line 405 of file principal_components_layer.cpp.

◆ set_means() [1/2]

void set_means ( const size_t &  new_size,
const double &  new_value 
)

Sets a new size and a new value to the means.

Parameters
new_sizeNew size of the vector means.
new_valueNew value of the vector means.

Definition at line 451 of file principal_components_layer.cpp.

◆ set_means() [2/2]

void set_means ( const Vector< double > &  new_means)

Sets a new value of the means member.

Parameters
new_meansObject to be set.

Definition at line 439 of file principal_components_layer.cpp.

◆ set_principal_component()

void set_principal_component ( const size_t &  index,
const Vector< double > &  principal_component 
)

Sets a new value of the principal components member.

Parameters
indexIndex of the principal component.
principal_componentObject to be set.

Definition at line 428 of file principal_components_layer.cpp.

◆ set_principal_components()

void set_principal_components ( const Matrix< double > &  new_principal_components)

Sets a new value of the principal components member.

Parameters
new_principal_componentsObject to be set.

Definition at line 390 of file principal_components_layer.cpp.

◆ set_principal_components_method() [1/2]

void set_principal_components_method ( const PrincipalComponentsMethod new_method)

Sets a new principal components method.

Parameters
new_methodNew principal components method.

Definition at line 486 of file principal_components_layer.cpp.

◆ set_principal_components_method() [2/2]

void set_principal_components_method ( const string &  new_method_string)

Sets a new principal components method.

Parameters
new_method_stringNew principal components method string.

Definition at line 495 of file principal_components_layer.cpp.

◆ set_principal_components_number()

void set_principal_components_number ( const size_t &  new_principal_components_number)

Sets a new value for the principal components number member.

Parameters
new_principal_components_numberNew principal components number.

Definition at line 416 of file principal_components_layer.cpp.

◆ to_XML()

tinyxml2::XMLDocument * to_XML ( ) const

Serializes the principal components layer object into a XML document of the TinyXML library. See the OpenNN manual for more information about the format of this element.

Definition at line 536 of file principal_components_layer.cpp.

◆ write_principal_components_expression()

string write_principal_components_expression ( const Vector< string > &  inputs_names,
const Vector< string > &  outputs_names 
) const

Returns a string with the expression of the principal components process when principal components anlysis is used.

Parameters
inputs_namesName of inputs to the principal components.
outputs_namesName of outputs from the principal components.

Definition at line 288 of file principal_components_layer.cpp.

◆ write_principal_components_method_text()

string write_principal_components_method_text ( ) const

Returns a string with the name of the method used for principal components layer, as paragaph text.

Definition at line 86 of file principal_components_layer.cpp.

◆ write_XML()

void write_XML ( tinyxml2::XMLPrinter file_stream) const

Serializes the principal components layer object into a XML document of the TinyXML library without keep the DOM tree in memory. See the OpenNN manual for more information about the format of this document.

Definition at line 608 of file principal_components_layer.cpp.

Member Data Documentation

◆ principal_components

Matrix<double> principal_components
protected

Contains all the principal components getd in rows and sorted according to their relative explained variance.

Definition at line 161 of file principal_components_layer.h.


The documentation for this class was generated from the following files: