Logo ROOT   6.14/05
Reference Guide
pca.C
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 //
3 // File pca.C generated by TPrincipal::MakeCode
4 // on Fri Nov 2 09:34:23 2018
5 // ROOT version 6.14/05
6 //
7 // This file contains the functions
8 //
9 // void X2P(Double_t *x, Double_t *p);
10 // void P2X(Double_t *p, Double_t *x, Int_t nTest);
11 //
12 // The first for transforming original data x in
13 // pattern space, to principal components p in
14 // feature space. The second function is for the
15 // inverse transformation, but using only nTest
16 // of the principal components in the expansion
17 //
18 // See TPrincipal class documentation for more information
19 //
20 #ifndef __CINT__
21 #include <Rtypes.h> // needed for Double_t etc
22 #endif
23 
24 //
25 // Static data variables
26 //
27 static Int_t gNVariables = 10;
28 
29 // Assignment of eigenvector matrix.
30 // Elements are stored row-wise, that is
31 // M[i][j] = e[i * nVariables + j]
32 // where i and j are zero-based
33 static Double_t gEigenVectors[] = {
34  0.092981,
35  0.0183025,
36  -0.469673,
37  0.447794,
38  0.337217,
39  0.576659,
40  0.303622,
41  0.163921,
42  -0.0395451,
43  0.0551067,
44  0.300488,
45  0.173086,
46  -0.0708037,
47  0.244314,
48  -0.400902,
49  0.105924,
50  -0.623148,
51  0.466415,
52  -0.11252,
53  0.156799,
54  0.208504,
55  -0.00193196,
56  -0.189206,
57  -0.393711,
58  0.708482,
59  -0.275614,
60  -0.247156,
61  0.32893,
62  -0.0793528,
63  0.110579,
64  0.101939,
65  0.171081,
66  -0.2769,
67  0.390707,
68  -0.127222,
69  -0.732616,
70  0.382711,
71  0.164348,
72  -0.0396483,
73  0.0552505,
74  0.291416,
75  0.18814,
76  0.474855,
77  -0.276517,
78  -0.10788,
79  0.176643,
80  0.534345,
81  0.461423,
82  -0.111316,
83  0.155121,
84  0.131793,
85  -0.880938,
86  0.15007,
87  0.180274,
88  -0.0199821,
89  -0.0784678,
90  0.0336452,
91  0.196066,
92  -0.288921,
93  -0.148168,
94  0.0399807,
95  -0.169596,
96  -0.637252,
97  -0.56285,
98  -0.435647,
99  0.0751499,
100  0.155583,
101  -0.00545381,
102  -0.153334,
103  0.0597144,
104  0.500682,
105  -0.143895,
106  -0.0635903,
107  -0.0454421,
108  -0.0563623,
109  0.000875005,
110  0.0283942,
111  0.0280789,
112  0.789438,
113  -0.307439,
114  0.503213,
115  -0.113272,
116  0.0614414,
117  0.0652156,
118  0.0288443,
119  -0.0140081,
120  -0.00186302,
121  -0.5194,
122  -0.0484328,
123  0.672877,
124  0.489283,
125  0.258237,
126  0.00176374,
127  -0.00720891,
128  0.0399618,
129  0.0187477,
130  -0.016582,
131  -0.313741,
132  -0.482671,
133  -0.600193};
134 
135 // Assignment to eigen value vector. Zero-based.
136 static Double_t gEigenValues[] = {
137  0.385574,
138  0.111974,
139  0.103131,
140  0.102198,
141  0.0999811,
142  0.0992024,
143  0.0979399,
144  1.39133e-16,
145  2.70742e-16,
146  5.38836e-16
147 };
148 
149 // Assignment to mean value vector. Zero-based.
150 static Double_t gMeanValues[] = {
151  4.99425,
152  8.0105,
153  2.017,
154  4.9975,
155  8.0189,
156  1.97633,
157  4.99577,
158  35.0103,
159  30.0145,
160  28.0382
161 };
162 
163 // Assignment to sigma value vector. Zero-based.
164 static Double_t gSigmaValues[] = {
165  0.992626,
166  2.82439,
167  1.99185,
168  0.995217,
169  2.79416,
170  2.00942,
171  0.999632,
172  5.1466,
173  5.04129,
174  4.64356
175 };
176 
177 //
178 // The function void X2P(Double_t *x, Double_t *p)
179 //
180 void X2P(Double_t *x, Double_t *p) {
181  for (Int_t i = 0; i < gNVariables; i++) {
182  p[i] = 0;
183  for (Int_t j = 0; j < gNVariables; j++)
184  p[i] += (x[j] - gMeanValues[j])
185  * gEigenVectors[j * gNVariables + i] / gSigmaValues[j];
186 
187  }
188 }
189 
190 //
191 // The function void P2X(Double_t *p, Double_t *x, Int_t nTest)
192 //
193 void P2X(Double_t *p, Double_t *x, Int_t nTest) {
194  for (Int_t i = 0; i < gNVariables; i++) {
195  x[i] = gMeanValues[i];
196  for (Int_t j = 0; j < nTest; j++)
197  x[i] += p[j] * gSigmaValues[i]
198  * gEigenVectors[i * gNVariables + j];
199  }
200 }
201 
202 // EOF for pca.C
void X2P(Double_t *x, Double_t *p)
Definition: pca.C:180
static Int_t gNVariables
Definition: pca.C:27
int Int_t
Definition: RtypesCore.h:41
static Double_t gEigenVectors[]
Definition: pca.C:33
Double_t x[n]
Definition: legend1.C:17
static Double_t gSigmaValues[]
Definition: pca.C:164
void P2X(Double_t *p, Double_t *x, Int_t nTest)
Definition: pca.C:193
static Double_t gEigenValues[]
Definition: pca.C:136
double Double_t
Definition: RtypesCore.h:55
static Double_t gMeanValues[]
Definition: pca.C:150