00001 #include "TPrincipal.h"
00002 #include "iomanip.h"
00003
00004 void principal(Int_t n=10, Int_t m=10000)
00005 {
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 Int_t c = n / 5 + 1;
00020
00021 cout << "*************************************************" << endl;
00022 cout << "* Principal Component Analysis *" << endl;
00023 cout << "* *" << endl;
00024 cout << "* Number of variables: " << setw(4) << n
00025 << " *" << endl;
00026 cout << "* Number of data points: " << setw(8) << m
00027 << " *" << endl;
00028 cout << "* Number of dependent variables: " << setw(4) << c
00029 << " *" << endl;
00030 cout << "* *" << endl;
00031 cout << "*************************************************" << endl;
00032
00033
00034
00035
00036
00037
00038 TPrincipal* principal = new TPrincipal(n,"ND");
00039
00040
00041 TRandom* random = new TRandom;
00042
00043
00044
00045
00046 Double_t* data = new Double_t[n];
00047 for (Int_t i = 0; i < m; i++) {
00048
00049
00050
00051 for (Int_t j = 0; j < n - c; j++) {
00052 if (j % 3 == 0)
00053 data[j] = random->Gaus(5,1);
00054 else if (j % 3 == 1)
00055 data[j] = random->Poisson(8);
00056 else
00057 data[j] = random->Exp(2);
00058 }
00059
00060
00061 for (Int_t j = 0 ; j < c; j++) {
00062 data[n - c + j] = 0;
00063 for (Int_t k = 0; k < n - c - j; k++)
00064 data[n - c + j] += data[k];
00065 }
00066
00067
00068 principal->AddRow(data);
00069 }
00070
00071
00072 delete [] data;
00073
00074
00075 principal->MakePrincipals();
00076
00077
00078 principal->Print();
00079
00080
00081 principal->Test();
00082
00083
00084 principal->MakeHistograms();
00085
00086
00087 principal->MakeCode();
00088
00089
00090
00091 TBrowser* b = new TBrowser("principalBrowser", principal);
00092
00093 }