106 0.454937, 1.38629, 2.36597, 3.35670, 4.35146, 5.34812, 6.34581, 7.34412, 8.34283,
107 9.34182, 10.34, 11.34, 12.34, 13.34, 14.34, 15.34, 16.34, 17.34, 18.34, 19.34,
108 20.34, 21.34, 22.34, 23.34, 24.34, 25.34, 26.34, 27.34, 28.34, 29.34, 30.34,
109 31.34, 32.34, 33.34, 34.34, 35.34, 36.34, 37.34, 38.34, 39.34, 40.34,
110 41.34, 42.34, 43.34, 44.34, 45.34, 46.34, 47.34, 48.34, 49.33};
113 5.02389, 7.3776,9.34840,11.1433,12.8325,
114 14.4494,16.0128,17.5346,19.0228,20.4831,21.920,23.337,
115 24.736,26.119,27.488,28.845,30.191,31.526,32.852,34.170,
116 35.479,36.781,38.076,39.364,40.646,41.923,43.194,44.461,
117 45.722,46.979,48.232,49.481,50.725,51.966,53.203,54.437,
118 55.668,56.896,58.120,59.342,60.561,61.777,62.990,64.201,
119 65.410,66.617,67.821,69.022,70.222,71.420};
133 fCovariance(nvariables),
134 fInvcovariance(nvariables),
135 fCorrelation(nvariables),
139 fHyperplane(nvariables),
140 fData(nvectors, nvariables)
142 if ((nvectors<=1)||(nvariables<=0)){
143 Error(
"TRobustEstimator",
"Not enough vectors or variables");
147 Error(
"TRobustEstimator",
"For the univariate case, use the default constructor and EvaluateUni() function");
155 Warning(
"TRobustEstimator",
"chosen h is too small, default h is taken instead");
214 Warning(
"Evaluate",
"Chosen h = #observations, so classic estimates of location and scatter will be calculated");
231 for (i=0; i<nbest; i++)
245 for (k=0; k<k1; k++) {
249 for (i=0; i<
fH; i++) {
250 for(j=0; j<
fNvar; j++)
281 if(det<deti[maxind]) {
283 for(ii=0; ii<
fNvar; ii++) {
284 mstock(maxind, ii)=
fMean(ii);
285 for(jj=0; jj<
fNvar; jj++)
294 for (i=0; i<nbest; i++) {
295 for(ii=0; ii<
fNvar; ii++) {
296 fMean(ii)=mstock(i, ii);
297 for (jj=0; jj<
fNvar; jj++)
309 for(ii=0; ii<
fNvar; ii++) {
310 mstock(i,ii)=
fMean(ii);
311 for (jj=0; jj<
fNvar; jj++)
317 for(ii=0; ii<
fNvar; ii++) {
318 fMean(ii)=mstock(detind,ii);
320 for(jj=0; jj<
fNvar; jj++)
324 if (deti[detind]!=0) {
332 for (i=0; i<
fN; i++) {
354 for (ii=0; ii<5; ii++)
360 for (ii=0; ii<5; ii++)
365 for (
int iii = 0; iii <
sum; ++iii) subdat[iii] = -999;
366 RDraw(subdat, nsub, indsubdat);
367 for (
int iii = 0; iii <
sum; ++iii) {
368 if (subdat[iii] < 0 || subdat[iii] >=
fN ) {
369 Error(
"Evaluate",
"subdat index is invalid subdat[%d] = %d",iii, subdat[iii] );
375 Int_t nbestsub=nbest*nsub;
379 for (i=0; i<nbestsub; i++) {
380 for(j=0; j<
fNvar; j++)
391 for (
Int_t kgroup=0; kgroup<nsub; kgroup++) {
393 Int_t ntemp=indsubdat[kgroup];
395 for (i=0; i<kgroup; i++)
400 for(i=0; i<ntemp; i++) {
401 for (j=0; j<
fNvar; j++) {
402 dattemp(i,j)=
fData[subdat[temp+i]][j];
407 for (i=0; i<nbest; i++)
410 for(k=0; k<k2; k++) {
413 for (i=0; i<htemp; i++) {
414 for(j=0; j<
fNvar; j++) {
422 par =
Exact2(mstockbig, cstockbig, hyperplane, deti, nbest, kgroup, sscp,ndist);
434 det =
CStep(ntemp, htemp,
index, dattemp, sscp, ndist);
436 par=
Exact2(mstockbig, cstockbig, hyperplane, deti, nbest, kgroup, sscp, ndist);
448 det=
CStep(ntemp,htemp,
index, dattemp, sscp, ndist);
450 par=
Exact2(mstockbig, cstockbig, hyperplane, deti, nbest, kgroup, sscp,ndist);
464 if(det<deti[maxind]) {
466 for(i=0; i<
fNvar; i++) {
467 mstockbig(nbest*kgroup+maxind,i)=
fMean(i);
468 for(j=0; j<
fNvar; j++) {
480 if (deti[maxind]<kEps)
485 for(i=0; i<nbest; i++) {
486 detibig[kgroup*nbest + i]=deti[i];
497 for(i=0; i<
sum; i++) {
498 for (j=0; j<
fNvar; j++)
499 datmerged(i,j)=
fData[subdat[i]][j];
505 for(k=0; k<nbestsub; k++) {
507 for(ii=0; ii<
fNvar; ii++) {
508 fMean(ii)=mstockbig(k,ii);
509 for(jj=0; jj<
fNvar; jj++)
513 for(i=0; i<
fNvar; i++)
549 for(i=0; i<
fNvar; i++) {
550 mstockbig(k,i)=
fMean(i);
551 for(j=0; j<
fNvar; j++) {
560 for(i=0; i<
fNvar; i++) {
561 fMean(i)=mstockbig(minind,i);
563 for(j=0; j<
fNvar; j++)
587 for (i=0; i<
fN; i++) {
613 Double_t faclts[]={2.6477,2.5092,2.3826,2.2662,2.1587,2.0589,1.9660,1.879,1.7973,1.7203,1.6473};
630 for(
Int_t jint=0; jint<
len; jint++) {
632 for (
Int_t j=0; j<hh; j++) {
637 aw2[jint]=aw[jint]*aw[jint]/hh;
642 slutn[ndup]=aw[jint];
647 aw2[jint]+aw2[jint-1];
651 slutn[ndup]=aw[jint];
656 slutn[ndup]=aw[jint];
662 slutn[0]=slutn[
Int_t((ndup)/2)]/hh;
687 if (i < 0 || i >= 50)
return 0;
697 Warning(
"GetCovariance",
"provided matrix is of the wrong size, it will be resized");
709 Warning(
"GetCorrelation",
"provided matrix is of the wrong size, it will be resized");
721 Error(
"GetHyperplane",
"the data doesn't lie on a hyperplane!\n");
734 Error(
"GetHyperplane",
"the data doesn't lie on a hyperplane!\n");
738 Warning(
"GetHyperPlane",
"provided vector is of the wrong size, it will be resized");
750 Warning(
"GetMean",
"provided vector is of the wrong size, it will be resized");
762 Warning(
"GetRDistances",
"provided vector is of the wrong size, it will be resized");
782 for (j=1; j<
fNvar+1; j++) {
783 sscp(0, j) +=
vec(j-1);
784 sscp(j, 0) = sscp(0, j);
786 for (i=1; i<
fNvar+1; i++) {
787 for (j=1; j<
fNvar+1; j++) {
788 sscp(i, j) +=
vec(i-1)*
vec(j-1);
831 for (i=0; i<
fNvar; i++) {
833 sd[i]=sscp(i+1, i+1);
834 f=(sd[i]-
m(i)*
m(i)/nvec)/(nvec-1);
839 for (i=0; i<
fNvar; i++) {
840 for (j=0; j<
fNvar; j++) {
841 cov(i, j)=sscp(i+1, j+1)-nvec*
m(i)*
m(j);
854 for(j=0; j<
fNvar; j++)
856 for(i=0; i<
fNvar; i++) {
857 for (j=0; j<
fNvar; j++) {
885 for(i=0; i<ntotal; i++)
888 for (i=0; i<
p+1; i++) {
891 for(j=0; j<=i-1; j++) {
909 for (i=0; i<
p+1; i++) {
910 for (j=0; j<
fNvar; j++) {
919 while((det<kEps)&&(nindex < htotal)) {
927 for(i=0; i<nindex; i++) {
933 }
while(repeat==
kTRUE);
938 for(j=0; j<
fNvar; j++)
950 for(j=0; j<ntotal; j++) {
952 for(i=0; i<
fNvar; i++)
955 for(i=0; i<
fNvar; i++)
972 for (i=0; i<nmerged; i++) {
974 for(j=0; j<
fNvar; j++) {
981 for (i=0; i<hmerged; i++) {
982 for(j=0; j<
fNvar; j++)
1010 for(j=0; j<ntotal; j++) {
1012 for(i=0; i<
fNvar; i++)
1015 for(i=0; i<
fNvar; i++)
1016 ndist[j]+=(
data[j][i]-
fMean[i])*temp[i];
1023 for (i=0; i<htotal; i++) {
1024 for (j=0; j<
fNvar; j++)
1044 for (j=0; j<
fNvar; j++) {
1048 for (i=0; i<
fN; i++) {
1050 for(j=0; j<
fNvar; j++) {
1057 for (i=0; i<
fN; i++) {
1058 if(ndist[i] < 1
e-14) nhyp++;
1084 for (i=0; i<
fN; i++) {
1085 if(ndist[i]<1
e-14) {
1086 for (j=0; j<
fNvar; j++)
1101 for(i=0; i<
fNvar; i++) {
1102 mstockbig(nbest*kgroup+maxind,i)=
fMean(i);
1104 for(j=0; j<
fNvar; j++) {
1121 if ((
fN>=2*nmini) && (
fN<=(3*nmini-1))) {
1126 indsubdat[0]=indsubdat[1]=
Int_t(
fN/2);
1130 if((
fN>=3*nmini) && (
fN<(4*nmini -1))) {
1132 indsubdat[0]=indsubdat[1]=indsubdat[2]=
Int_t(
fN/3);
1137 else indsubdat[2]=
Int_t(
fN/3)+1;
1142 if((
fN>=4*nmini)&&(
fN<=(5*nmini-1))){
1143 if (
fN%4==0) indsubdat[0]=indsubdat[1]=indsubdat[2]=indsubdat[3]=
Int_t(
fN/4);
1147 if(
fN%4==1) indsubdat[2]=indsubdat[3]=
Int_t(
fN/4);
1152 if(
fN%4==3) indsubdat[2]=indsubdat[3]=
Int_t(
fN/4)+1;
1156 for(
Int_t i=0; i<5; i++)
1182 for (i=0; i<
fN; i++) {
1184 for(j=0; j<
fNvar; j++) {
1188 for(j=0; j<
fNvar; j++) {
1202 for (i=0; i<
fN; i++) {
1204 for(j=0; j<
fNvar; j++) {
1209 for(j=0; j<
fNvar; j++) {
1217 for(i=0; i<
fN; i++) {
1218 if (
fRd[i]<=cutoff) {
1219 for(j=0; j<
fNvar; j++)
1220 temp[j]=
fData[i][j];
1240 for (k=1; k<=ngroup; k++) {
1241 for (
m=1;
m<=indsubdat[k-1];
m++) {
1248 subdat[jndex-1]=nrand+jndex-2;
1249 for (i=1; i<=jndex-1; i++) {
1250 if(subdat[i-1] > nrand+i-2) {
1251 for(j=jndex; j>=i+1; j--) {
1252 subdat[j-1]=subdat[j-2];
1255 subdat[i-1]=nrand+i-2;
1269 const Int_t kWorkMax=100;
1273 Int_t workLocal[kWorkMax];
1281 if (ntotal > kWorkMax) {
1282 isAllocated =
kTRUE;
1283 ind =
new Int_t[ntotal];
1287 for (
Int_t ii=0; ii<ntotal; ii++) {
1295 if (ir ==
l+1 &&
a[ind[ir]]<
a[ind[
l]])
1296 {temp = ind[
l]; ind[
l]=ind[ir]; ind[ir]=temp;}
1303 {temp = ind[mid]; ind[mid]=ind[
l+1]; ind[
l+1]=temp;}
1304 if (
a[ind[
l]]>
a[ind[ir]])
1305 {temp = ind[
l]; ind[
l]=ind[ir]; ind[ir]=temp;}
1307 if (
a[ind[
l+1]]>
a[ind[ir]])
1308 {temp=ind[
l+1]; ind[
l+1]=ind[ir]; ind[ir]=temp;}
1310 if (
a[ind[
l]]>
a[ind[
l+1]])
1311 {temp = ind[
l]; ind[
l]=ind[
l+1]; ind[
l+1]=temp;}
1317 do i++;
while (
a[ind[i]]<
a[arr]);
1318 do j--;
while (
a[ind[j]]>
a[arr]);
1320 {temp=ind[i]; ind[i]=ind[j]; ind[j]=temp;}
1324 if (j>=rk) ir = j-1;
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
R__EXTERN TRandom * gRandom
const Double_t kChiMedian[50]
const Double_t kChiQuant[50]
void Set(Int_t n) override
Set size of this array to n ints.
Cholesky Decomposition class.
Bool_t Invert(TMatrixDSym &inv)
For a symmetric matrix A(m,m), its inverse A_inv(m,m) is returned .
const TMatrixD & GetEigenVectors() const
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
Double_t Determinant() const override
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Int_t RDist(TMatrixD &sscp)
Calculates robust distances.Then the samples with robust distances greater than a cutoff value (0....
Double_t CStep(Int_t ntotal, Int_t htotal, Int_t *index, TMatrixD &data, TMatrixD &sscp, Double_t *ndist)
from the input htotal-subset constructs another htotal subset with lower determinant
const TMatrixDSym * GetCovariance() const
TMatrixDSym fInvcovariance
void CreateSubset(Int_t ntotal, Int_t htotal, Int_t p, Int_t *index, TMatrixD &data, TMatrixD &sscp, Double_t *ndist)
creates a subset of htotal elements from ntotal elements first, p+1 elements are drawn randomly(witho...
void Covar(TMatrixD &sscp, TVectorD &m, TMatrixDSym &cov, TVectorD &sd, Int_t nvec)
calculates mean and covariance
Int_t Exact(Double_t *ndist)
for the exact fit situations returns number of observations on the hyperplane
Double_t KOrdStat(Int_t ntotal, Double_t *arr, Int_t k, Int_t *work)
because I need an Int_t work array
Int_t GetNOut()
returns the number of outliers
TRobustEstimator()
this constructor should be used in a univariate case: first call this constructor,...
void Correl()
transforms covariance matrix into correlation matrix
void AddColumn(Double_t *col)
adds a column to the data matrix it is assumed that the column has size fN variable fVarTemp keeps th...
void RDraw(Int_t *subdat, Int_t ngroup, Int_t *indsubdat)
Draws ngroup nonoverlapping subdatasets out of a dataset of size n such that the selected case number...
void Classic()
called when h=n.
void Evaluate()
Finds the estimate of multivariate mean and variance.
const TVectorD * GetMean() const
Int_t Exact2(TMatrixD &mstockbig, TMatrixD &cstockbig, TMatrixD &hyperplane, Double_t *deti, Int_t nbest, Int_t kgroup, TMatrixD &sscp, Double_t *ndist)
This function is called if determinant of the covariance matrix of a subset=0.
const TVectorD * GetRDistances() const
Int_t GetBDPoint()
returns the breakdown point of the algorithm
void CreateOrtSubset(TMatrixD &dat, Int_t *index, Int_t hmerged, Int_t nmerged, TMatrixD &sscp, Double_t *ndist)
creates a subset of hmerged vectors with smallest orthogonal distances to the hyperplane hyp[1]*(x1-m...
void AddRow(Double_t *row)
adds a vector to the data matrix it is supposed that the vector is of size fNvar
const TVectorD * GetHyperplane() const
if the points are on a hyperplane, returns this hyperplane
Int_t Partition(Int_t nmini, Int_t *indsubdat)
divides the elements into approximately equal subgroups number of elements in each subgroup is stored...
const TMatrixDSym * GetCorrelation() const
Double_t GetChiQuant(Int_t i) const
returns the chi2 quantiles
void EvaluateUni(Int_t nvectors, Double_t *data, Double_t &mean, Double_t &sigma, Int_t hh=0)
for the univariate case estimates of location and scatter are returned in mean and sigma parameters t...
void AddToSscp(TMatrixD &sscp, TVectorD &vec)
update the sscp matrix with vector vec
void ClearSscp(TMatrixD &sscp)
clear the sscp matrix, used for covariance and mean calculation
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
Int_t GetNoElements() const
Element * GetMatrixArray()
Long64_t LocMin(Long64_t n, const T *a)
Returns index of array with the minimum element.
Double_t Median(Long64_t n, const T *a, const Double_t *w=nullptr, Long64_t *work=nullptr)
Same as RMS.
Long64_t LocMax(Long64_t n, const T *a)
Returns index of array with the maximum element.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Sort the n elements of the array a of generic templated type Element.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
static uint64_t sum(uint64_t i)