ROOT logo

From $ROOTSYS/tutorials/math/pca.C

// -*- mode: c++ -*-
// 
// File pca.C generated by TPrincipal::MakeCode
// on Fri Nov  4 10:22:34 2011
// ROOT version 5.32/00-rc1
//
// This file contains the functions 
//
//    void  X2P(Double_t *x, Double_t *p); 
//    void  P2X(Double_t *p, Double_t *x, Int_t nTest);
//
// The first for transforming original data x in 
// pattern space, to principal components p in 
// feature space. The second function is for the
// inverse transformation, but using only nTest
// of the principal components in the expansion
// 
// See TPrincipal class documentation for more information 
// 
#ifndef __CINT__
#include <Rtypes.h> // needed for Double_t etc
#endif

//
// Static data variables
//
static Int_t    gNVariables = 10;

// Assignment of eigenvector matrix.
// Elements are stored row-wise, that is
//    M[i][j] = e[i * nVariables + j] 
// where i and j are zero-based
static Double_t gEigenVectors[] = {
  0.105952,
  -0.0412338,
  -0.163932,
  0.506955,
  -0.293327,
  -0.45912,
  0.611921,
  0.0417098,
  0.124369,
  -0.121286,
  0.299103,
  0.114816,
  -0.423035,
  0.173049,
  0.129852,
  -0.264772,
  -0.58561,
  0.118711,
  0.35397,
  -0.345193,
  0.196631,
  0.182178,
  0.334538,
  0.0979602,
  -0.695575,
  0.431875,
  -0.124202,
  0.0811669,
  0.242022,
  -0.236021,
  0.0946521,
  0.0513485,
  0.107011,
  0.552681,
  0.561861,
  0.539862,
  0.180077,
  0.041718,
  0.124394,
  -0.121309,
  0.294184,
  0.179444,
  0.157981,
  -0.594249,
  0.257622,
  -0.0673251,
  0.421439,
  0.117814,
  0.351295,
  -0.342585,
  0.135669,
  -0.895902,
  -0.0723783,
  -0.0912176,
  -0.0511243,
  0.155245,
  0.0072091,
  -0.0686794,
  0.36119,
  0.0587528,
  0.0393664,
  -0.129504,
  0.791462,
  0.188712,
  0.167449,
  -0.456201,
  -0.235961,
  -0.142627,
  0.0747034,
  -0.0435387,
  0.501306,
  -0.134663,
  0.0961035,
  0.0147716,
  0.015782,
  -0.0347285,
  -0.0292305,
  0.724996,
  -0.379729,
  0.221314,
  0.503961,
  -0.111486,
  -0.060855,
  -0.0228244,
  -0.0175214,
  0.0561781,
  0.0175518,
  -0.534241,
  -0.552628,
  -0.367135,
  0.4898,
  0.259068,
  -0.0353844,
  0.0139158,
  0.00266293,
  -0.00485772,
  0.0160046,
  -0.354777,
  0.275952,
  0.69945};

// Assignment to eigen value vector. Zero-based.
static Double_t gEigenValues[] = {
  0.385122,
  0.110703,
  0.103572,
  0.101548,
  0.100795,
  0.0996221,
  0.0986388,
  5.97928e-16,
  2.52544e-16,
  5.65803e-16
};

// Assignment to mean value vector. Zero-based.
static Double_t gMeanValues[] = {
  5.0082,
  7.9976,
  1.96735,
  5.0162,
  8.0087,
  2.01253,
  4.99247,
  35.0031,
  30.0106,
  27.9981
};

// Assignment to sigma value vector. Zero-based.
static Double_t gSigmaValues[] = {
  1.00507,
  2.86056,
  1.95587,
  1.00527,
  2.83895,
  1.97263,
  1.01426,
  5.15563,
  5.04925,
  4.64883
};

// 
// The function   void X2P(Double_t *x, Double_t *p)
// 
void X2P(Double_t *x, Double_t *p) {
  for (Int_t i = 0; i < gNVariables; i++) {
    p[i] = 0;
    for (Int_t j = 0; j < gNVariables; j++)
      p[i] += (x[j] - gMeanValues[j]) 
        * gEigenVectors[j *  gNVariables + i] / gSigmaValues[j];

  }
}

// 
// The function   void P2X(Double_t *p, Double_t *x, Int_t nTest)
// 
void P2X(Double_t *p, Double_t *x, Int_t nTest) {
  for (Int_t i = 0; i < gNVariables; i++) {
    x[i] = gMeanValues[i];
    for (Int_t j = 0; j < nTest; j++)
      x[i] += p[j] * gSigmaValues[i] 
        * gEigenVectors[i *  gNVariables + j];
  }
}

// EOF for pca.C
 pca.C:1
 pca.C:2
 pca.C:3
 pca.C:4
 pca.C:5
 pca.C:6
 pca.C:7
 pca.C:8
 pca.C:9
 pca.C:10
 pca.C:11
 pca.C:12
 pca.C:13
 pca.C:14
 pca.C:15
 pca.C:16
 pca.C:17
 pca.C:18
 pca.C:19
 pca.C:20
 pca.C:21
 pca.C:22
 pca.C:23
 pca.C:24
 pca.C:25
 pca.C:26
 pca.C:27
 pca.C:28
 pca.C:29
 pca.C:30
 pca.C:31
 pca.C:32
 pca.C:33
 pca.C:34
 pca.C:35
 pca.C:36
 pca.C:37
 pca.C:38
 pca.C:39
 pca.C:40
 pca.C:41
 pca.C:42
 pca.C:43
 pca.C:44
 pca.C:45
 pca.C:46
 pca.C:47
 pca.C:48
 pca.C:49
 pca.C:50
 pca.C:51
 pca.C:52
 pca.C:53
 pca.C:54
 pca.C:55
 pca.C:56
 pca.C:57
 pca.C:58
 pca.C:59
 pca.C:60
 pca.C:61
 pca.C:62
 pca.C:63
 pca.C:64
 pca.C:65
 pca.C:66
 pca.C:67
 pca.C:68
 pca.C:69
 pca.C:70
 pca.C:71
 pca.C:72
 pca.C:73
 pca.C:74
 pca.C:75
 pca.C:76
 pca.C:77
 pca.C:78
 pca.C:79
 pca.C:80
 pca.C:81
 pca.C:82
 pca.C:83
 pca.C:84
 pca.C:85
 pca.C:86
 pca.C:87
 pca.C:88
 pca.C:89
 pca.C:90
 pca.C:91
 pca.C:92
 pca.C:93
 pca.C:94
 pca.C:95
 pca.C:96
 pca.C:97
 pca.C:98
 pca.C:99
 pca.C:100
 pca.C:101
 pca.C:102
 pca.C:103
 pca.C:104
 pca.C:105
 pca.C:106
 pca.C:107
 pca.C:108
 pca.C:109
 pca.C:110
 pca.C:111
 pca.C:112
 pca.C:113
 pca.C:114
 pca.C:115
 pca.C:116
 pca.C:117
 pca.C:118
 pca.C:119
 pca.C:120
 pca.C:121
 pca.C:122
 pca.C:123
 pca.C:124
 pca.C:125
 pca.C:126
 pca.C:127
 pca.C:128
 pca.C:129
 pca.C:130
 pca.C:131
 pca.C:132
 pca.C:133
 pca.C:134
 pca.C:135
 pca.C:136
 pca.C:137
 pca.C:138
 pca.C:139
 pca.C:140
 pca.C:141
 pca.C:142
 pca.C:143
 pca.C:144
 pca.C:145
 pca.C:146
 pca.C:147
 pca.C:148
 pca.C:149
 pca.C:150
 pca.C:151
 pca.C:152
 pca.C:153
 pca.C:154
 pca.C:155
 pca.C:156
 pca.C:157
 pca.C:158
 pca.C:159
 pca.C:160
 pca.C:161
 pca.C:162
 pca.C:163
 pca.C:164
 pca.C:165
 pca.C:166
 pca.C:167
 pca.C:168
 pca.C:169
 pca.C:170
 pca.C:171
 pca.C:172
 pca.C:173
 pca.C:174
 pca.C:175
 pca.C:176
 pca.C:177
 pca.C:178
 pca.C:179
 pca.C:180
 pca.C:181
 pca.C:182
 pca.C:183
 pca.C:184
 pca.C:185
 pca.C:186
 pca.C:187
 pca.C:188
 pca.C:189
 pca.C:190
 pca.C:191
 pca.C:192
 pca.C:193
 pca.C:194
 pca.C:195
 pca.C:196
 pca.C:197
 pca.C:198
 pca.C:199
 pca.C:200
 pca.C:201
 pca.C:202
 pca.C:203