Logo ROOT  
Reference Guide
TPrincipal Class Reference

Principal Components Analysis (PCA)

The current implementation is based on the LINTRA package from CERNLIB by R. Brun, H. Hansroul, and J. Kubler. The class has been implemented by Christian Holm Christensen in August 2000.

Introduction

In many applications of various fields of research, the treatment of large amounts of data requires powerful techniques capable of rapid data reduction and analysis. Usually, the quantities most conveniently measured by the experimentalist, are not necessarily the most significant for classification and analysis of the data. It is then useful to have a way of selecting an optimal set of variables necessary for the recognition process and reducing the dimensionality of the problem, resulting in an easier classification procedure.

This paper describes the implementation of one such method of feature selection, namely the principal components analysis. This multidimensional technique is well known in the field of pattern recognition and and its use in Particle Physics has been documented elsewhere (cf. H. Wind, Function Parameterization, CERN 72-21).

Overview

Suppose we have prototypes which are trajectories of particles, passing through a spectrometer. If one measures the passage of the particle at say 8 fixed planes, the trajectory is described by an 8-component vector:

\[ \mathbf{x} = \left(x_0, x_1, \ldots, x_7\right) \]

in 8-dimensional pattern space.

One proceeds by generating a a representative tracks sample and building up the covariance matrix \(\mathsf{C}\). Its eigenvectors and eigenvalues are computed by standard methods, and thus a new basis is obtained for the original 8-dimensional space the expansion of the prototypes,

\[ \mathbf{x}_m = \sum^7_{i=0} a_{m_i} \mathbf{e}_i \quad \mbox{where} \quad a_{m_i} = \mathbf{x}^T\bullet\mathbf{e}_i \]

allows the study of the behavior of the coefficients \(a_{m_i}\) for all the tracks of the sample. The eigenvectors which are insignificant for the trajectory description in the expansion will have their corresponding coefficients \(a_{m_i}\) close to zero for all the prototypes.

On one hand, a reduction of the dimensionality is then obtained by omitting these least significant vectors in the subsequent analysis.

On the other hand, in the analysis of real data, these least significant variables(?) can be used for the pattern recognition problem of extracting the valid combinations of coordinates describing a true trajectory from the set of all possible wrong combinations.

The program described here performs this principal components analysis on a sample of data provided by the user. It computes the covariance matrix, its eigenvalues ands corresponding eigenvectors and exhibits the behavior of the principal components \(a_{m_i}\), thus providing to the user all the means of understanding their data.

Principal Components Method

Let's consider a sample of \(M\) prototypes each being characterized by \(P\) variables \(x_0, x_1, \ldots, x_{P-1}\). Each prototype is a point, or a column vector, in a \(P\)-dimensional Pattern space.

\[ \mathbf{x} = \left[\begin{array}{c} x_0\\x_1\\\vdots\\x_{P-1}\end{array}\right]\,, \]

where each \(x_n\) represents the particular value associated with the \(n\)-dimension.

Those \(P\) variables are the quantities accessible to the experimentalist, but are not necessarily the most significant for the classification purpose.

The Principal Components Method consists of applying a linear* transformation to the original variables. This transformation is described by an orthogonal matrix and is equivalent to a rotation of the original pattern space into a new set of coordinate vectors, which hopefully provide easier feature identification and dimensionality reduction.

Let's define the covariance matrix:

\[ \mathsf{C} = \left\langle\mathbf{y}\mathbf{y}^T\right\rangle \quad\mbox{where}\quad \mathbf{y} = \mathbf{x} - \left\langle\mathbf{x}\right\rangle\,, \]

and the brackets indicate mean value over the sample of \(M\) prototypes.

This matrix \(\mathsf{C}\) is real, positive definite, symmetric, and will have all its eigenvalues greater then zero. It will now be show that among the family of all the complete orthonormal bases of the pattern space, the base formed by the eigenvectors of the covariance matrix and belonging to the largest eigenvalues, corresponds to the most significant features of the description of the original prototypes.

let the prototypes be expanded on into a set of \(N\) basis vectors \(\mathbf{e}_n, n=0,\ldots,N,N+1, \ldots, P-1\)

\[ \mathbf{y}_i = \sum^N_{i=0} a_{i_n} \mathbf{e}_n, \quad i = 1, \ldots, M, \quad N < P-1 \]

The ‘best’ feature coordinates \(\mathbf{e}_n\), spanning a feature space, will be obtained by minimizing the error due to this truncated expansion, i.e.,

\[ \min\left(E_N\right) = \min\left[\left\langle\left(\mathbf{y}_i - \sum^N_{i=0} a_{i_n} \mathbf{e}_n\right)^2\right\rangle\right] \]

with the conditions:

\[ \mathbf{e}_k\bullet\mathbf{e}_j = \delta_{jk} = \left\{\begin{array}{rcl} 1 & \mbox{for} & k = j\\ 0 & \mbox{for} & k \neq j \end{array}\right. \]

Multiplying (3) by \(\mathbf{e}^T_n\) using (5), we get

\[ a_{i_n} = \mathbf{y}_i^T\bullet\mathbf{e}_n\,, \]

so the error becomes

\begin{eqnarray*} E_N &=& \left\langle\left[\sum_{n=N+1}^{P-1} a_{i_n}\mathbf{e}_n\right]^2\right\rangle\nonumber\\ &=& \left\langle\left[\sum_{n=N+1}^{P-1} \mathbf{y}_i^T\bullet\mathbf{e}_n\mathbf{e}_n\right]^2\right\rangle\nonumber\\ &=& \left\langle\sum_{n=N+1}^{P-1} \mathbf{e}_n^T\mathbf{y}_i\mathbf{y}_i^T\mathbf{e}_n\right\rangle\nonumber\\ &=& \sum_{n=N+1}^{P-1} \mathbf{e}_n^T\mathsf{C}\mathbf{e}_n \end{eqnarray*}

The minimization of the sum in (7) is obtained when each term \(\mathbf{e}_n^\mathsf{C}\mathbf{e}_n\) is minimum, since \(\mathsf{C}\) is positive definite. By the method of Lagrange multipliers, and the condition (5), we get

\[ E_N = \sum^{P-1}_{n=N+1} \left(\mathbf{e}_n^T\mathsf{C}\mathbf{e}_n - l_n\mathbf{e}_n^T\bullet\mathbf{e}_n + l_n\right) \]

The minimum condition \(\frac{dE_N}{d\mathbf{e}^T_n} = 0\) leads to the equation

\[ \mathsf{C}\mathbf{e}_n = l_n\mathbf{e}_n\,, \]

which shows that \(\mathbf{e}_n\) is an eigenvector of the covariance matrix \(\mathsf{C}\) with eigenvalue \(l_n\). The estimated minimum error is then given by

\[ E_N \sim \sum^{P-1}_{n=N+1} \mathbf{e}_n^T\bullet l_n\mathbf{e}_n = \sum^{P-1}_{n=N+1} l_n\,, \]

where \(l_n,\,n=N+1,\ldots,P\) \(l_n,\,n=N+1,\ldots,P-1\) are the eigenvalues associated with the omitted eigenvectors in the expansion (3). Thus, by choosing the \(N\) largest eigenvalues, and their associated eigenvectors, the error \(E_N\) is minimized.

The transformation matrix to go from the pattern space to the feature space consists of the ordered eigenvectors \(\mathbf{e}_1,\ldots,\mathbf{e}_P\) \(\mathbf{e}_0,\ldots,\mathbf{e}_{P-1}\) for its columns

\[ \mathsf{T} = \left[ \begin{array}{cccc} \mathbf{e}_0 & \mathbf{e}_1 & \vdots & \mathbf{e}_{P-1} \end{array}\right] = \left[ \begin{array}{cccc} \mathbf{e}_{0_0} & \mathbf{e}_{1_0} & \cdots & \mathbf{e}_{{P-1}_0}\\ \mathbf{e}_{0_1} & \mathbf{e}_{1_1} & \cdots & \mathbf{e}_{{P-1}_1}\\ \vdots & \vdots & \ddots & \vdots \\ \mathbf{e}_{0_{P-1}} & \mathbf{e}_{1_{P-1}} & \cdots & \mathbf{e}_{{P-1}_{P-1}}\\ \end{array}\right] \]

This is an orthogonal transformation, or rotation, of the pattern space and feature selection results in ignoring certain coordinates in the transformed space.

Christian Holm August 2000, CERN

Definition at line 20 of file TPrincipal.h.

Public Member Functions

 TPrincipal ()
 Empty constructor. Do not use. More...
 
 TPrincipal (Int_t nVariables, Option_t *opt="ND")
 Constructor. More...
 
virtual ~TPrincipal ()
 Destructor. More...
 
virtual void AddRow (const Double_t *x)
 Add a data point and update the covariance matrix. More...
 
virtual void Browse (TBrowser *b)
 Browse the TPrincipal object in the TBrowser. More...
 
virtual void Clear (Option_t *option="")
 Clear the data in Object. More...
 
const TMatrixDGetCovarianceMatrix () const
 
const TVectorDGetEigenValues () const
 
const TMatrixDGetEigenVectors () const
 
TListGetHistograms () const
 
const TVectorDGetMeanValues () const
 
const Double_tGetRow (Int_t row)
 Return a row of the user supplied data. More...
 
const TVectorDGetSigmas () const
 
const TVectorDGetUserData () const
 
Bool_t IsFolder () const
 Returns kTRUE in case object contains browsable objects (like containers or lists of other objects). More...
 
virtual void MakeCode (const char *filename="pca", Option_t *option="")
 Generates the file <filename>, with .C appended if it does argument doesn't end in .cxx or .C. More...
 
virtual void MakeHistograms (const char *name="pca", Option_t *option="epsdx")
 Make histograms of the result of the analysis. More...
 
virtual void MakeMethods (const char *classname="PCA", Option_t *option="")
 Generate the file <classname>PCA.cxx which contains the implementation of two methods: More...
 
virtual void MakePrincipals ()
 Perform the principal components analysis. More...
 
virtual void P2X (const Double_t *p, Double_t *x, Int_t nTest)
 Calculate x as a function of nTest of the most significant principal components p, and return it in x. More...
 
virtual void Print (Option_t *opt="MSE") const
 Print the statistics Options are. More...
 
virtual void SumOfSquareResiduals (const Double_t *x, Double_t *s)
 Calculates the sum of the square residuals, that is. More...
 
void Test (Option_t *option="")
 Test the PCA, bye calculating the sum square of residuals (see method SumOfSquareResiduals), and display the histogram. More...
 
virtual void X2P (const Double_t *x, Double_t *p)
 Calculate the principal components from the original data vector x, and return it in p. More...
 
- Public Member Functions inherited from TNamed
 TNamed ()
 
 TNamed (const char *name, const char *title)
 
 TNamed (const TNamed &named)
 TNamed copy ctor. More...
 
 TNamed (const TString &name, const TString &title)
 
virtual ~TNamed ()
 TNamed destructor. More...
 
virtual void Clear (Option_t *option="")
 Set name and title to empty strings (""). More...
 
virtual TObjectClone (const char *newname="") const
 Make a clone of an object using the Streamer facility. More...
 
virtual Int_t Compare (const TObject *obj) const
 Compare two TNamed objects. More...
 
virtual void Copy (TObject &named) const
 Copy this to obj. More...
 
virtual void FillBuffer (char *&buffer)
 Encode TNamed into output buffer. More...
 
virtual const char * GetName () const
 Returns name of object. More...
 
virtual const char * GetTitle () const
 Returns title of object. More...
 
virtual ULong_t Hash () const
 Return hash value for this object. More...
 
virtual Bool_t IsSortable () const
 
virtual void ls (Option_t *option="") const
 List TNamed name and title. More...
 
TNamedoperator= (const TNamed &rhs)
 TNamed assignment operator. More...
 
virtual void Print (Option_t *option="") const
 Print TNamed name and title. More...
 
virtual void SetName (const char *name)
 Set the name of the TNamed. More...
 
virtual void SetNameTitle (const char *name, const char *title)
 Set all the TNamed parameters (name and title). More...
 
virtual void SetTitle (const char *title="")
 Set the title of the TNamed. More...
 
virtual Int_t Sizeof () const
 Return size of the TNamed part of the TObject. More...
 
- Public Member Functions inherited from TObject
 TObject ()
 TObject constructor. More...
 
 TObject (const TObject &object)
 TObject copy ctor. More...
 
virtual ~TObject ()
 TObject destructor. More...
 
void AbstractMethod (const char *method) const
 Use this method to implement an "abstract" method that you don't want to leave purely abstract. More...
 
virtual void AppendPad (Option_t *option="")
 Append graphics object to current pad. More...
 
virtual void Browse (TBrowser *b)
 Browse object. May be overridden for another default action. More...
 
ULong_t CheckedHash ()
 Check and record whether this class has a consistent Hash/RecursiveRemove setup (*) and then return the regular Hash value for this object. More...
 
virtual const char * ClassName () const
 Returns name of class to which the object belongs. More...
 
virtual void Clear (Option_t *="")
 
virtual TObjectClone (const char *newname="") const
 Make a clone of an object using the Streamer facility. More...
 
virtual Int_t Compare (const TObject *obj) const
 Compare abstract method. More...
 
virtual void Copy (TObject &object) const
 Copy this to obj. More...
 
virtual void Delete (Option_t *option="")
 Delete this object. More...
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 Computes distance from point (px,py) to the object. More...
 
virtual void Draw (Option_t *option="")
 Default Draw method for all objects. More...
 
virtual void DrawClass () const
 Draw class inheritance tree of the class to which this object belongs. More...
 
virtual TObjectDrawClone (Option_t *option="") const
 Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad). More...
 
virtual void Dump () const
 Dump contents of object on stdout. More...
 
virtual void Error (const char *method, const char *msgfmt,...) const
 Issue error message. More...
 
virtual void Execute (const char *method, const char *params, Int_t *error=0)
 Execute method on this object with the given parameter string, e.g. More...
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=0)
 Execute method on this object with parameters stored in the TObjArray. More...
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 Execute action corresponding to an event at (px,py). More...
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 Issue fatal error message. More...
 
virtual TObjectFindObject (const char *name) const
 Must be redefined in derived classes. More...
 
virtual TObjectFindObject (const TObject *obj) const
 Must be redefined in derived classes. More...
 
virtual Option_tGetDrawOption () const
 Get option used by the graphics system to draw this object. More...
 
virtual const char * GetIconName () const
 Returns mime type name of object. More...
 
virtual const char * GetName () const
 Returns name of object. More...
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 Returns string containing info about the object at position (px,py). More...
 
virtual Option_tGetOption () const
 
virtual const char * GetTitle () const
 Returns title of object. More...
 
virtual UInt_t GetUniqueID () const
 Return the unique object id. More...
 
virtual Bool_t HandleTimer (TTimer *timer)
 Execute action in response of a timer timing out. More...
 
virtual ULong_t Hash () const
 Return hash value for this object. More...
 
Bool_t HasInconsistentHash () const
 Return true is the type of this object is known to have an inconsistent setup for Hash and RecursiveRemove (i.e. More...
 
virtual void Info (const char *method, const char *msgfmt,...) const
 Issue info message. More...
 
virtual Bool_t InheritsFrom (const char *classname) const
 Returns kTRUE if object inherits from class "classname". More...
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 Returns kTRUE if object inherits from TClass cl. More...
 
virtual void Inspect () const
 Dump contents of this object in a graphics canvas. More...
 
void InvertBit (UInt_t f)
 
virtual Bool_t IsEqual (const TObject *obj) const
 Default equal comparison (objects are equal if they have the same address in memory). More...
 
virtual Bool_t IsFolder () const
 Returns kTRUE in case object contains browsable objects (like containers or lists of other objects). More...
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
virtual Bool_t IsSortable () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
virtual void ls (Option_t *option="") const
 The ls function lists the contents of a class on stdout. More...
 
void MayNotUse (const char *method) const
 Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary). More...
 
virtual Bool_t Notify ()
 This method must be overridden to handle object notification. More...
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 Use this method to declare a method obsolete. More...
 
void operator delete (void *ptr)
 Operator delete. More...
 
void operator delete[] (void *ptr)
 Operator delete []. More...
 
voidoperator new (size_t sz)
 
voidoperator new (size_t sz, void *vp)
 
voidoperator new[] (size_t sz)
 
voidoperator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 TObject assignment operator. More...
 
virtual void Paint (Option_t *option="")
 This method must be overridden if a class wants to paint itself. More...
 
virtual void Pop ()
 Pop on object drawn in a pad to the top of the display list. More...
 
virtual void Print (Option_t *option="") const
 This method must be overridden when a class wants to print itself. More...
 
virtual Int_t Read (const char *name)
 Read contents of object with specified name from the current directory. More...
 
virtual void RecursiveRemove (TObject *obj)
 Recursively remove this object from a list. More...
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 Save this object in the file specified by filename. More...
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 Save a primitive as a C++ statement(s) on output stream "out". More...
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 Set or unset the user status bits as specified in f. More...
 
virtual void SetDrawOption (Option_t *option="")
 Set drawing option for object. More...
 
virtual void SetUniqueID (UInt_t uid)
 Set the unique object id. More...
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 Issue system error message. More...
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 Set current style settings in this object This function is called when either TCanvas::UseCurrentStyle or TROOT::ForceStyle have been invoked. More...
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 Issue warning message. More...
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0)
 Write this object to the current directory. More...
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0) const
 Write this object to the current directory. More...
 

Protected Member Functions

 TPrincipal (const TPrincipal &)
 Copy constructor. More...
 
void MakeNormalised ()
 Normalize the covariance matrix. More...
 
void MakeRealCode (const char *filename, const char *prefix, Option_t *option="")
 This is the method that actually generates the code for the transformations to and from feature space and pattern space It's called by TPrincipal::MakeCode and TPrincipal::MakeMethods. More...
 
TPrincipaloperator= (const TPrincipal &)
 Assignment operator. More...
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 Interface to ErrorHandler (protected). More...
 
void MakeZombie ()
 

Protected Attributes

TMatrixD fCovarianceMatrix
 
TVectorD fEigenValues
 
TMatrixD fEigenVectors
 
TListfHistograms
 
Bool_t fIsNormalised
 
TVectorD fMeanValues
 
Int_t fNumberOfDataPoints
 
Int_t fNumberOfVariables
 
TVectorD fOffDiagonal
 
TVectorD fSigmas
 
Bool_t fStoreData
 
Double_t fTrace
 
TVectorD fUserData
 
- Protected Attributes inherited from TNamed
TString fName
 
TString fTitle
 

Additional Inherited Members

- Public Types inherited from TObject
enum  {
  kIsOnHeap = 0x01000000 , kNotDeleted = 0x02000000 , kZombie = 0x04000000 , kInconsistent = 0x08000000 ,
  kBitMask = 0x00ffffff
}
 
enum  { kSingleKey = BIT(0) , kOverwrite = BIT(1) , kWriteDelete = BIT(2) }
 
enum  EDeprecatedStatusBits { kObjInCanvas = BIT(3) }
 
enum  EStatusBits {
  kCanDelete = BIT(0) , kMustCleanup = BIT(3) , kIsReferenced = BIT(4) , kHasUUID = BIT(5) ,
  kCannotPick = BIT(6) , kNoContextMenu = BIT(8) , kInvalidObject = BIT(13)
}
 
- Static Public Member Functions inherited from TObject
static Long_t GetDtorOnly ()
 Return destructor only flag. More...
 
static Bool_t GetObjectStat ()
 Get status of object stat flag. More...
 
static void SetDtorOnly (void *obj)
 Set destructor only flag. More...
 
static void SetObjectStat (Bool_t stat)
 Turn on/off tracking of objects in the TObjectTable. More...
 
- Protected Types inherited from TObject
enum  { kOnlyPrepStep = BIT(3) }
 

#include <TPrincipal.h>

Inheritance diagram for TPrincipal:
[legend]

Constructor & Destructor Documentation

◆ TPrincipal() [1/3]

TPrincipal::TPrincipal ( const TPrincipal pr)
protected

Copy constructor.

Definition at line 312 of file TPrincipal.cxx.

◆ TPrincipal() [2/3]

TPrincipal::TPrincipal ( )

Empty constructor. Do not use.

Definition at line 229 of file TPrincipal.cxx.

◆ ~TPrincipal()

TPrincipal::~TPrincipal ( )
virtual

Destructor.

Definition at line 357 of file TPrincipal.cxx.

◆ TPrincipal() [3/3]

TPrincipal::TPrincipal ( Int_t  nVariables,
Option_t opt = "ND" 
)

Constructor.

Argument is number of variables in the sample of data Options are:

  • N Normalize the covariance matrix (default)
  • D Store input data (default)

The created object is named "principal" by default.

Definition at line 253 of file TPrincipal.cxx.

Member Function Documentation

◆ AddRow()

void TPrincipal::AddRow ( const Double_t p)
virtual

Add a data point and update the covariance matrix.

The input array must be fNumberOfVariables long.

The Covariance matrix and mean values of the input data is calculated on the fly by the following equations:

\[ \left<x_i\right>^{(0)} = x_{i0} \]

\[ \left<x_i\right>^{(n)} = \left<x_i\right>^{(n-1)} + \frac1n \left(x_{in} - \left<x_i\right>^{(n-1)}\right) \]

\[ C_{ij}^{(0)} = 0 \]

\[ C_{ij}^{(n)} = C_{ij}^{(n-1)} + \frac1{n-1}\left[\left(x_{in} - \left<x_i\right>^{(n)}\right) \left(x_{jn} - \left<x_j\right>^{(n)}\right)\right] - \frac1n C_{ij}^{(n-1)} \]

since this is a really fast method, with no rounding errors (please refer to CERN 72-21 pp. 54-106).

The data is stored internally in a TVectorD, in the following way:

\[ \mathbf{x} = \left[\left(x_{0_0},\ldots,x_{{P-1}_0}\right),\ldots, \left(x_{0_i},\ldots,x_{{P-1}_i}\right), \ldots\right] \]

With \(P\) as defined in the class description.

Definition at line 410 of file TPrincipal.cxx.

◆ Browse()

void TPrincipal::Browse ( TBrowser b)
virtual

Browse the TPrincipal object in the TBrowser.

Reimplemented from TObject.

Definition at line 457 of file TPrincipal.cxx.

◆ Clear()

void TPrincipal::Clear ( Option_t opt = "")
virtual

Clear the data in Object.

Notice, that's not possible to change the dimension of the original data.

Reimplemented from TNamed.

Definition at line 480 of file TPrincipal.cxx.

◆ GetCovarianceMatrix()

const TMatrixD * TPrincipal::GetCovarianceMatrix ( ) const
inline

Definition at line 58 of file TPrincipal.h.

◆ GetEigenValues()

const TVectorD * TPrincipal::GetEigenValues ( ) const
inline

Definition at line 59 of file TPrincipal.h.

◆ GetEigenVectors()

const TMatrixD * TPrincipal::GetEigenVectors ( ) const
inline

Definition at line 60 of file TPrincipal.h.

◆ GetHistograms()

TList * TPrincipal::GetHistograms ( ) const
inline

Definition at line 61 of file TPrincipal.h.

◆ GetMeanValues()

const TVectorD * TPrincipal::GetMeanValues ( ) const
inline

Definition at line 62 of file TPrincipal.h.

◆ GetRow()

const Double_t * TPrincipal::GetRow ( Int_t  row)

Return a row of the user supplied data.

If row is out of bounds, 0 is returned. It's up to the user to delete the returned array. Row 0 is the first row;

Definition at line 507 of file TPrincipal.cxx.

◆ GetSigmas()

const TVectorD * TPrincipal::GetSigmas ( ) const
inline

Definition at line 64 of file TPrincipal.h.

◆ GetUserData()

const TVectorD * TPrincipal::GetUserData ( ) const
inline

Definition at line 65 of file TPrincipal.h.

◆ IsFolder()

Bool_t TPrincipal::IsFolder ( ) const
inlinevirtual

Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).

Reimplemented from TObject.

Definition at line 66 of file TPrincipal.h.

◆ MakeCode()

void TPrincipal::MakeCode ( const char *  filename = "pca",
Option_t opt = "" 
)
virtual

Generates the file <filename>, with .C appended if it does argument doesn't end in .cxx or .C.

The file contains the implementation of two functions

void X2P(Double_t *x, Double *p)
void P2X(Double_t *p, Double *x, Int_t nTest)
int Int_t
Definition: RtypesCore.h:43
double Double_t
Definition: RtypesCore.h:57
virtual void X2P(const Double_t *x, Double_t *p)
Calculate the principal components from the original data vector x, and return it in p.
virtual void P2X(const Double_t *p, Double_t *x, Int_t nTest)
Calculate x as a function of nTest of the most significant principal components p,...
Double_t x[n]
Definition: legend1.C:17
const char * Double

which does the same as TPrincipal::X2P and TPrincipal::P2X respectively. Please refer to these methods.

Further, the static variables:

Int_t gNVariables
Double_t gEigenValues[]
Double_t gEigenVectors[]
Double_t gMeanValues[]
Double_t gSigmaValues[]

are initialized. The only ROOT header file needed is Rtypes.h

See TPrincipal::MakeRealCode for a list of options

Definition at line 544 of file TPrincipal.cxx.

◆ MakeHistograms()

void TPrincipal::MakeHistograms ( const char *  name = "pca",
Option_t opt = "epsdx" 
)
virtual

Make histograms of the result of the analysis.

The option string say which histograms to create

  • X Histogram original data
  • P Histogram principal components corresponding to original data
  • D Histogram the difference between the original data and the projection of principal unto a lower dimensional subspace (2D histograms)
  • E Histogram the eigenvalues
  • S Histogram the square of the residues (see TPrincipal::SumOfSquareResiduals) The histograms will be named <name>_<type><number>, where <name> is the first argument, <type> is one of X,P,D,E,S, and <number> is the variable.

Definition at line 569 of file TPrincipal.cxx.

◆ MakeMethods()

void TPrincipal::MakeMethods ( const char *  classname = "PCA",
Option_t opt = "" 
)
virtual

Generate the file <classname>PCA.cxx which contains the implementation of two methods:

void <classname>::X2P(Double_t *x, Double *p)
void <classname>::P2X(Double_t *p, Double *x, Int_t nTest)

which does the same as TPrincipal::X2P and TPrincipal::P2X respectively. Please refer to these methods.

Further, the public static members:

are initialized, and assumed to exist. The class declaration is assumed to be in <classname>.h and assumed to be provided by the user.

See TPrincipal::MakeRealCode for a list of options

The minimal class definition is:

class <classname> {
public:
static Int_t fgNVariables;
static Double_t fgEigenVectors[];
static Double_t fgEigenValues[];
static Double_t fgMeanValues[];
static Double_t fgSigmaValues[];
void X2P(Double_t *x, Double_t *p);
void P2X(Double_t *p, Double_t *x, Int_t nTest);
};

Whether the methods <classname>::X2P and <classname>::P2X should be static or not, is up to the user.

Definition at line 856 of file TPrincipal.cxx.

◆ MakeNormalised()

void TPrincipal::MakeNormalised ( )
protected

Normalize the covariance matrix.

Definition at line 794 of file TPrincipal.cxx.

◆ MakePrincipals()

void TPrincipal::MakePrincipals ( )
virtual

Perform the principal components analysis.

This is done in several stages in the TMatrix::EigenVectors method:

  • Transform the covariance matrix into a tridiagonal matrix.
  • Find the eigenvalues and vectors of the tridiagonal matrix.

Definition at line 869 of file TPrincipal.cxx.

◆ MakeRealCode()

void TPrincipal::MakeRealCode ( const char *  filename,
const char *  classname,
Option_t option = "" 
)
protected

This is the method that actually generates the code for the transformations to and from feature space and pattern space It's called by TPrincipal::MakeCode and TPrincipal::MakeMethods.

The options are: NONE so far

Definition at line 891 of file TPrincipal.cxx.

◆ operator=()

TPrincipal & TPrincipal::operator= ( const TPrincipal pr)
protected

Assignment operator.

Definition at line 333 of file TPrincipal.cxx.

◆ P2X()

void TPrincipal::P2X ( const Double_t p,
Double_t x,
Int_t  nTest 
)
virtual

Calculate x as a function of nTest of the most significant principal components p, and return it in x.

It's the users responsibility to make sure that both x and p are of the right size (i.e., memory must be allocated for x).

Definition at line 1060 of file TPrincipal.cxx.

◆ Print()

void TPrincipal::Print ( Option_t opt = "MSE") const
virtual

Print the statistics Options are.

  • M Print mean values of original data
  • S Print sigma values of original data
  • E Print eigenvalues of covariance matrix
  • V Print eigenvectors of covariance matrix Default is MSE

Reimplemented from TNamed.

Definition at line 1080 of file TPrincipal.cxx.

◆ SumOfSquareResiduals()

void TPrincipal::SumOfSquareResiduals ( const Double_t x,
Double_t s 
)
virtual

Calculates the sum of the square residuals, that is.

\[ E_N = \sum_{i=0}^{P-1} \left(x_i - x^\prime_i\right)^2 \]

where \(x^\prime_i = \sum_{j=i}^N p_i e_{n_j}\) is the \(i^{\mbox{th}}\) component of the principal vector, corresponding to \(x_i\), the original data; I.e., the square distance to the space spanned by \(N\) eigenvectors.

Definition at line 1169 of file TPrincipal.cxx.

◆ Test()

void TPrincipal::Test ( Option_t option = "")

Test the PCA, bye calculating the sum square of residuals (see method SumOfSquareResiduals), and display the histogram.

Definition at line 1191 of file TPrincipal.cxx.

◆ X2P()

void TPrincipal::X2P ( const Double_t x,
Double_t p 
)
virtual

Calculate the principal components from the original data vector x, and return it in p.

It's the users responsibility to make sure that both x and p are of the right size (i.e., memory must be allocated for p).

Definition at line 1215 of file TPrincipal.cxx.

Member Data Documentation

◆ fCovarianceMatrix

TMatrixD TPrincipal::fCovarianceMatrix
protected

Definition at line 28 of file TPrincipal.h.

◆ fEigenValues

TVectorD TPrincipal::fEigenValues
protected

Definition at line 31 of file TPrincipal.h.

◆ fEigenVectors

TMatrixD TPrincipal::fEigenVectors
protected

Definition at line 30 of file TPrincipal.h.

◆ fHistograms

TList* TPrincipal::fHistograms
protected

Definition at line 39 of file TPrincipal.h.

◆ fIsNormalised

Bool_t TPrincipal::fIsNormalised
protected

Definition at line 41 of file TPrincipal.h.

◆ fMeanValues

TVectorD TPrincipal::fMeanValues
protected

Definition at line 26 of file TPrincipal.h.

◆ fNumberOfDataPoints

Int_t TPrincipal::fNumberOfDataPoints
protected

Definition at line 23 of file TPrincipal.h.

◆ fNumberOfVariables

Int_t TPrincipal::fNumberOfVariables
protected

Definition at line 24 of file TPrincipal.h.

◆ fOffDiagonal

TVectorD TPrincipal::fOffDiagonal
protected

Definition at line 33 of file TPrincipal.h.

◆ fSigmas

TVectorD TPrincipal::fSigmas
protected

Definition at line 27 of file TPrincipal.h.

◆ fStoreData

Bool_t TPrincipal::fStoreData
protected

Definition at line 42 of file TPrincipal.h.

◆ fTrace

Double_t TPrincipal::fTrace
protected

Definition at line 37 of file TPrincipal.h.

◆ fUserData

TVectorD TPrincipal::fUserData
protected

Definition at line 35 of file TPrincipal.h.

Libraries for TPrincipal:
[legend]

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