Logo ROOT  
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 Wed Jan 20 09:38:31 2021
5 // ROOT version 6.23/01
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.161904,
42  -0.0397247,
43  0.0606595,
44  0.300488,
45  0.173086,
46  -0.0708037,
47  0.244314,
48  -0.400902,
49  0.105924,
50  -0.623148,
51  0.460677,
52  -0.113032,
53  0.172599,
54  0.208504,
55  -0.00193196,
56  -0.189206,
57  -0.393711,
58  0.708482,
59  -0.275614,
60  -0.247156,
61  0.324883,
62  -0.0797132,
63  0.121722,
64  0.101939,
65  0.171081,
66  -0.2769,
67  0.390707,
68  -0.127222,
69  -0.732616,
70  0.382711,
71  0.162326,
72  -0.0398284,
73  0.0608178,
74  0.291416,
75  0.18814,
76  0.474855,
77  -0.276517,
78  -0.10788,
79  0.176643,
80  0.534345,
81  0.455747,
82  -0.111822,
83  0.170752,
84  0.131793,
85  -0.880938,
86  0.15007,
87  0.180274,
88  -0.0199821,
89  -0.0784678,
90  0.0336452,
91  0.189092,
92  -0.305629,
93  -0.121269,
94  0.0399807,
95  -0.169596,
96  -0.637252,
97  -0.56285,
98  -0.435647,
99  0.0751499,
100  0.155583,
101  -0.0109055,
102  -0.147748,
103  0.0718216,
104  0.500682,
105  -0.143895,
106  -0.0635903,
107  -0.0454421,
108  -0.0563623,
109  0.000875005,
110  0.0283942,
111  0.0561469,
112  0.76068,
113  -0.369773,
114  0.503213,
115  -0.113272,
116  0.0614414,
117  0.0652156,
118  0.0288443,
119  -0.0140081,
120  -0.00186302,
121  -0.529397,
122  0.0216542,
123  0.666451,
124  0.489283,
125  0.258237,
126  0.00176374,
127  -0.00720891,
128  0.0399618,
129  0.0187477,
130  -0.016582,
131  -0.320424,
132  -0.520441,
133  -0.564008};
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.40885e-16,
145  2.72332e-16,
146  4.57839e-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
gEigenVectors
static Double_t gEigenVectors[]
Definition: pca.C:33
gNVariables
static Int_t gNVariables
Definition: pca.C:27
Int_t
int Int_t
Definition: RtypesCore.h:45
x
Double_t x[n]
Definition: legend1.C:17
P2X
void P2X(Double_t *p, Double_t *x, Int_t nTest)
Definition: pca.C:193
gEigenValues
static Double_t gEigenValues[]
Definition: pca.C:136
gSigmaValues
static Double_t gSigmaValues[]
Definition: pca.C:164
Double_t
double Double_t
Definition: RtypesCore.h:59
gMeanValues
static Double_t gMeanValues[]
Definition: pca.C:150
X2P
void X2P(Double_t *x, Double_t *p)
Definition: pca.C:180
Rtypes.h