18from ROOT
import TPrincipal, gRandom, TBrowser, vector
26print (
"""*************************************************
27* Principal Component Analysis *
29* Number of variables: {0:4d} *
30* Number of data points: {1:8d} *
31* Number of dependent variables: {2:4d} *
33*************************************************""".format(n, m, c))
35# Initilase the TPrincipal object. Use the empty string for the
36# final argument, if you don't wan't the covariance
37# matrix. Normalising the covariance matrix is a good idea if your
38# variables have different orders of magnitude.
39principal = TPrincipal(n, "ND")
41# Use a pseudo-random number generator
44# Make the m data-points
45# Make a variable to hold our data
46# Allocate memory for the data point
47data = vector('double')()
51 for j
in range(n - c):
53 data.push_back(randumNum.Gaus(5, 1))
55 data.push_back(randumNum.Poisson(8))
57 data.push_back(randumNum.Exp(2))
62 for k
in range(n - c - j):
63 data[n - c + j] += data[k]
66 principal.AddRow(data.data())
70principal.MakePrincipals()
79principal.MakeHistograms()
85b =
TBrowser(
"principalBrowser", principal)
Using a TBrowser one can browse all ROOT objects.