    

 ## On this page

  

 

 # ComputeRPCA&lt; TYPE &gt; Class Template Reference

 Last update: 16.07.2025 

Perform Robust Principal Component Analysis While traditional PCA is very sensitive to data corruption or outliers, RPCA is, as its name implies, robust to data corruption under surprisingly broad conditions. RPCA attempts to split a given matrix M into two matrices S and L: M = L + S where L is a low-rank matrix and S is a sparse matrix of random errors (of arbitrary magnitude and random sign). In the context of SoS, each column vector of M might be a particular field design. Without any prior knowledge about outliers, RPCA is then able to separate correlations between field designs (L) from outliers (S). Security camera footage is a good example, following the M = L + S data model: L represents the slowly changing background, while S represents walking people. See <https://arxiv.org/abs/0912.3599> for more examples and a precise definition of the conditions, for RPCA to deliver good results. By default, [ComputeRPCA](class_compute_r_p_c_a.xhtml "Perform Robust Principal Component Analysis While traditional PCA is very sensitive to data corruptio...") creates two new quantity idents named RPCA\[\] (L) and RPCAError\[\] (S). Disable the creation of RPCAError by setting the createRPCAError member variable to *false*. The algorithm attempts to recover L and S by running the Principal Component Pursuit bi-objective optimization program:

![\[ //! \text{minimize} ||L||_* + \lambda ||S||_1 //! \text{subject to} L + S = M //! \]](/sites/default/files/migrate-content/osp3d_script/form_11.png)

 where ![$ ||L||_* $](/sites/default/files/migrate-content/osp3d_script/form_12.png) denotes the nuclear norm of ![$ L $](/sites/default/files/migrate-content/osp3d_script/form_13.png) (i.e. the sum of the singular values of ![$ L $](/sites/default/files/migrate-content/osp3d_script/form_13.png)) and ![$ ||L||_1 = \sum_{ij}|S_{ij}| $](/sites/default/files/migrate-content/osp3d_script/form_14.png) denotes the ![$ l_1 $](/sites/default/files/migrate-content/osp3d_script/form_15.png)-norm of ![$ S $](/sites/default/files/migrate-content/osp3d_script/form_16.png) seen as a long vector. Recommended value: ![$ \lambda = 1/\sqrt{max(dim(M))}$](/sites/default/files/migrate-content/osp3d_script/form_17.png). [More...](class_compute_r_p_c_a.xhtml#details)

## <a id="pub-types" name="pub-types"></a>Public Types

typedef boost::function&lt; DataObject::ptr\_type(DataObject::ptr\_type input)&gt; [TAlgorithmFunction](class_compute_single_object_per_object.xhtml#afe5cfc4ea6277ec393adca68465c9a5e) defines a function object [More...](#afe5cfc4ea6277ec393adca68465c9a5e)  
 typedef boost::function&lt; DataObject::ptr\_type([Structure](class_structure.xhtml) [database](group__data.xhtml#gaebcac3a2836ec9fdf2e47bd812994b6b), DataObject::ptr\_type input)&gt; [TAlgorithmFunction2](class_compute_single_object_per_object.xhtml#adbff8fbbd061127936232ab5600cbe01) defines a function object [More...](#adbff8fbbd061127936232ab5600cbe01)  
 ## <a id="pub-methods" name="pub-methods"></a>Public Member Functions

 [check](class_compute_single_object_per_object.xhtml#a47c34ec1e578c2ce27cf1c5fcd0d1704) ([Structure](class_structure.xhtml) [database](group__data.xhtml#gaebcac3a2836ec9fdf2e47bd812994b6b)) checks the settings on plausibility It throws an exception if there is a problem with the settings. Important: It tries to find out all problems with these settings and then exits the routine. [More...](#a47c34ec1e578c2ce27cf1c5fcd0d1704)  
 <a id="a0dbc926e6a1423b7d64cc9d41026045e"></a>bool **compute** ([Structure](class_structure.xhtml) [database](group__data.xhtml#gaebcac3a2836ec9fdf2e47bd812994b6b))  [compute](class_compute_single_object_per_object.xhtml#a2ee6c389c27f8cb563b6b1aa31f6bf17) ([Structure](class_structure.xhtml) [database](group__data.xhtml#gaebcac3a2836ec9fdf2e47bd812994b6b), DataObject::ptr\_type [data](class_compute_single_object_per_object.xhtml#aff21fffab499ea652443206d66e1a9bb), string new\_quantity\_ident, string new\_design\_ident) performs the action for a single set of samples [More...](#a2ee6c389c27f8cb563b6b1aa31f6bf17)  
 <a id="afb3c7912b78f2ec44c06e8198df36617"></a> [ComputeRPCA](class_compute_r_p_c_a.xhtml#afb3c7912b78f2ec44c06e8198df36617) () Create an RPCA object with default settings.   
  [ComputeRPCA](class_compute_r_p_c_a.xhtml#a216cd82ee2b0a4340813f2d0713b4806) ([DataObjectContainer](class_data_object_container.xhtml) dataObjectFilter) Create an RPCA object with default settings and set the field data to perform RPCA on. [More...](#a216cd82ee2b0a4340813f2d0713b4806)  
 ## <a id="pub-attribs" name="pub-attribs"></a>Public Attributes

<a id="a1fafb8453285b3214c8c7c8926ca77a1"></a>bool **createRPCAError** <a id="aff21fffab499ea652443206d66e1a9bb"></a>[DataObjectContainer](class_data_object_container.xhtml) [data](class_compute_single_object_per_object.xhtml#aff21fffab499ea652443206d66e1a9bb) the data set to be analyzed   
 <a id="a494c8da7f3865175fcb8044abce244fc"></a>number [lambda](class_compute_r_p_c_a.xhtml#a494c8da7f3865175fcb8044abce244fc) Singular value threshold parameter. Default: 0, lambda is set to 1/sqrt(max(n,m)), with n and m being the input matrix dimensions.   
 <a id="a0bc677a1bf92968ad92aa7d973e24ba4"></a>number [maxIterations](class_compute_r_p_c_a.xhtml#a0bc677a1bf92968ad92aa7d973e24ba4) Maximum number of iterations. Default: 200.   
 <a id="a30b1bcf63b9bdc707fea30bd96d70447"></a>[DataObjectContainer::string\_vector\_type](class_data_object_container.xhtml#ac293ea0e5c280f69a497ea20f20c60b9) [new\_quantity\_idents](class_compute_single_object_per_object.xhtml#a30b1bcf63b9bdc707fea30bd96d70447) the new idents for each quantity. The dimension and index space must fit the one of *quantity\_idents*   
 <a id="ade25e60bd85c8b4abd4f5b416cae0eb9"></a>bool [overwrite\_existing](class_compute_single_object_per_object.xhtml#ade25e60bd85c8b4abd4f5b416cae0eb9) is true if already existing output data objects will be replaced. In this case, also all depending objects of the already existing one will be deleted.   
 <a id="aced57c746ae1d69d2fd56872fa1768bf"></a>[DataObjectContainer::string\_vector\_type](class_data_object_container.xhtml#ac293ea0e5c280f69a497ea20f20c60b9) [quantity\_idents](class_compute_single_object_per_object.xhtml#aced57c746ae1d69d2fd56872fa1768bf) the quantities to be analyzed. If a quantity ident does not exist in *data*, no error appears.   
 <a id="a033dc667b0fe6b15482f2703c104f415"></a>number [relativeError](class_compute_r_p_c_a.xhtml#a033dc667b0fe6b15482f2703c104f415) Iterate until relative error is reached. Default: 1e-9.   
 <a id="details" name="details"></a>## Detailed Description

### template&lt;dataobject\_types TYPE&gt;  
class ComputeRPCA&lt; TYPE &gt;

Perform Robust Principal Component Analysis While traditional PCA is very sensitive to data corruption or outliers, RPCA is, as its name implies, robust to data corruption under surprisingly broad conditions. RPCA attempts to split a given matrix M into two matrices S and L: M = L + S where L is a low-rank matrix and S is a sparse matrix of random errors (of arbitrary magnitude and random sign). In the context of SoS, each column vector of M might be a particular field design. Without any prior knowledge about outliers, RPCA is then able to separate correlations between field designs (L) from outliers (S). Security camera footage is a good example, following the M = L + S data model: L represents the slowly changing background, while S represents walking people. See <https://arxiv.org/abs/0912.3599> for more examples and a precise definition of the conditions, for RPCA to deliver good results. By default, [ComputeRPCA](class_compute_r_p_c_a.xhtml "Perform Robust Principal Component Analysis While traditional PCA is very sensitive to data corruptio...") creates two new quantity idents named RPCA\[\] (L) and RPCAError\[\] (S). Disable the creation of RPCAError by setting the createRPCAError member variable to *false*. The algorithm attempts to recover L and S by running the Principal Component Pursuit bi-objective optimization program:

![\[ //! \text{minimize} ||L||_* + \lambda ||S||_1 //! \text{subject to} L + S = M //! \]](/sites/default/files/migrate-content/osp3d_script/form_11.png)

 where ![$ ||L||_* $](/sites/default/files/migrate-content/osp3d_script/form_12.png) denotes the nuclear norm of ![$ L $](/sites/default/files/migrate-content/osp3d_script/form_13.png) (i.e. the sum of the singular values of ![$ L $](/sites/default/files/migrate-content/osp3d_script/form_13.png)) and ![$ ||L||_1 = \sum_{ij}|S_{ij}| $](/sites/default/files/migrate-content/osp3d_script/form_14.png) denotes the ![$ l_1 $](/sites/default/files/migrate-content/osp3d_script/form_15.png)-norm of ![$ S $](/sites/default/files/migrate-content/osp3d_script/form_16.png) seen as a long vector. Recommended value: ![$ \lambda = 1/\sqrt{max(dim(M))}$](/sites/default/files/migrate-content/osp3d_script/form_17.png).

Template Parameters TYPEthe field data type 

## Member Typedef Documentation

<a id="afe5cfc4ea6277ec393adca68465c9a5e"></a>## [◆ ](#afe5cfc4ea6277ec393adca68465c9a5e)TAlgorithmFunction

 typedef boost::function&lt;DataObject::ptr\_type ( DataObject::ptr\_type input)&gt; [TAlgorithmFunction](class_compute_single_object_per_object.xhtml#afe5cfc4ea6277ec393adca68465c9a5e)  inherited 

defines a function object

Parameters inputa single input object Returnsthe result of the operation 



<a id="adbff8fbbd061127936232ab5600cbe01"></a>## [◆ ](#adbff8fbbd061127936232ab5600cbe01)TAlgorithmFunction2

 typedef boost::function&lt;DataObject::ptr\_type ( [Structure](class_structure.xhtml) [database](group__data.xhtml#gaebcac3a2836ec9fdf2e47bd812994b6b), DataObject::ptr\_type input)&gt; [TAlgorithmFunction2](class_compute_single_object_per_object.xhtml#adbff8fbbd061127936232ab5600cbe01)  inherited 

defines a function object

Parameters databasethe database we refer to inputa single input object Returnsthe result of the operation 



## Constructor &amp; Destructor Documentation

<a id="a216cd82ee2b0a4340813f2d0713b4806"></a>## [◆ ](#a216cd82ee2b0a4340813f2d0713b4806)ComputeRPCA()

 [ComputeRPCA](class_compute_r_p_c_a.xhtml)  ( [DataObjectContainer](class_data_object_container.xhtml)  *dataObjectFilter*) 

Create an RPCA object with default settings and set the field data to perform RPCA on.

Parameters dataObjectFilterthe field data to perform RPCA on 



## Member Function Documentation

<a id="a47c34ec1e578c2ce27cf1c5fcd0d1704"></a>## [◆ ](#a47c34ec1e578c2ce27cf1c5fcd0d1704)check()

 check  ( [Structure](class_structure.xhtml)  *database*)   inherited 

checks the settings on plausibility It throws an exception if there is a problem with the settings. Important: It tries to find out all problems with these settings and then exits the routine.

Parameters databasethe SoS structure 



<a id="a2ee6c389c27f8cb563b6b1aa31f6bf17"></a>## [◆ ](#a2ee6c389c27f8cb563b6b1aa31f6bf17)compute()

 compute  ( [Structure](class_structure.xhtml)  *database*,    DataObject::ptr\_type  *data*,    string  *new\_quantity\_ident*,    string  *new\_design\_ident*   )   inherited 

performs the action for a single set of samples

Parameters databasethe output object is to be inserted in this object datathe input data object new\_quantity\_identthe quantity ident of the new object new\_design\_identthe design ident of the new object If the input object is active, then the output object will be active as well (or inactive, respectively).