Logo ROOT   6.16/01
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 Sun Dec 19 21:31:45 2021
5// ROOT version 6.16/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//
27static 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
34 0.092981,
35 0.0183025,
36 -0.469673,
37 0.447794,
38 0.337217,
39 0.576659,
40 0.303622,
41 0.163108,
42 -0.0422783,
43 0.0554887,
44 0.300488,
45 0.173086,
46 -0.0708037,
47 0.244314,
48 -0.400902,
49 0.105924,
50 -0.623148,
51 0.464102,
52 -0.120297,
53 0.157886,
54 0.208504,
55 -0.00193196,
56 -0.189206,
57 -0.393711,
58 0.708482,
59 -0.275614,
60 -0.247156,
61 0.327299,
62 -0.0848374,
63 0.111346,
64 0.101939,
65 0.171081,
66 -0.2769,
67 0.390707,
68 -0.127222,
69 -0.732616,
70 0.382711,
71 0.163533,
72 -0.0423886,
73 0.0556335,
74 0.291416,
75 0.18814,
76 0.474855,
77 -0.276517,
78 -0.10788,
79 0.176643,
80 0.534345,
81 0.459134,
82 -0.11901,
83 0.156196,
84 0.131793,
85 -0.880938,
86 0.15007,
87 0.180274,
88 -0.0199821,
89 -0.0784678,
90 0.0336452,
91 0.19375,
92 -0.288729,
93 -0.151551,
94 0.0399807,
95 -0.169596,
96 -0.637252,
97 -0.56285,
98 -0.435647,
99 0.0751499,
100 0.155583,
101 -0.00756312,
102 -0.154195,
103 0.0572148,
104 0.500682,
105 -0.143895,
106 -0.0635903,
107 -0.0454421,
108 -0.0563623,
109 0.000875005,
110 0.0283942,
111 0.0389387,
112 0.793871,
113 -0.29457,
114 0.503213,
115 -0.113272,
116 0.0614414,
117 0.0652156,
118 0.0288443,
119 -0.0140081,
120 -0.00186302,
121 -0.524226,
122 -0.0532569,
123 0.668758,
124 0.489283,
125 0.258237,
126 0.00176374,
127 -0.00720891,
128 0.0399618,
129 0.0187477,
130 -0.016582,
131 -0.315291,
132 -0.469441,
133 -0.609797};
134
135// Assignment to eigen value vector. Zero-based.
137 0.385574,
138 0.111974,
139 0.103131,
140 0.102198,
141 0.0999811,
142 0.0992024,
143 0.0979399,
144 1.38529e-16,
145 2.71896e-16,
146 5.37111e-16
147};
148
149// Assignment to mean value vector. Zero-based.
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.
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//
180void 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//
193void 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
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
Double_t x[n]
Definition: legend1.C:17
static Double_t gSigmaValues[]
Definition: pca.C:164
static Int_t gNVariables
Definition: pca.C:27
void P2X(Double_t *p, Double_t *x, Int_t nTest)
Definition: pca.C:193
static Double_t gEigenVectors[]
Definition: pca.C:33
static Double_t gEigenValues[]
Definition: pca.C:136
static Double_t gMeanValues[]
Definition: pca.C:150
void X2P(Double_t *x, Double_t *p)
Definition: pca.C:180