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};
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++)
251 vec(j)=
fData[index[i]][j];
264 det =
CStep(fN, fH, index,
fData, sscp, ndist);
272 det =
CStep(fN, fH, index,
fData, sscp, ndist);
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++) {
415 vec(j)=dattemp(index[i],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++) {
469 cstockbig(i,nbest*kgroup*fNvar+maxind*fNvar+j)=
fCovariance(i,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++)
518 det=
CStep(sum, hmerged, index, datmerged, sscp, ndist);
535 det=
CStep(sum, hmerged, index, datmerged, sscp, ndist);
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};
626 Int_t len=nvectors-hh;
628 for(
Int_t i=0; i<len; i++)
630 for(
Int_t jint=0; jint<len; jint++) {
632 for (
Int_t j=0; j<hh; j++) {
633 aw[jint]+=data[index[j+jint]];
635 sq+=data[index[j]]*data[index[j]];
637 aw2[jint]=aw[jint]*aw[jint]/hh;
642 slutn[ndup]=aw[jint];
645 sq=sq - data[index[jint-1]]*data[index[jint-1]]+
646 data[index[jint+hh]]*data[index[jint+hh]]-
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);
799 for (
Int_t j=0; j<fNvar+1; j++) {
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++) {
911 vec[j]=data[index[i]][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++)
939 vec[j]=data[index[nindex-1]][j];
950 for(j=0; j<ntotal; j++) {
952 for(i=0; i<
fNvar; i++)
953 temp[i]=data[j][i] -
fMean(i);
955 for(i=0; i<
fNvar; i++)
956 ndist[j]+=(data[j][i]-
fMean(i))*temp[i];
958 KOrdStat(ntotal, ndist, htotal-1,index);
972 for (i=0; i<nmerged; i++) {
974 for(j=0; j<
fNvar; j++) {
979 KOrdStat(nmerged, ndist, hmerged-1, index);
981 for (i=0; i<hmerged; i++) {
982 for(j=0; j<
fNvar; j++)
983 vec[j]=dat[index[i]][j];
1010 for(j=0; j<ntotal; j++) {
1012 for(i=0; i<
fNvar; i++)
1013 temp[i]=data[j][i]-
fMean[i];
1015 for(i=0; i<
fNvar; i++)
1016 ndist[j]+=(data[j][i]-
fMean[i])*temp[i];
1020 KOrdStat(ntotal, ndist, htotal-1, index);
1023 for (i=0; i<htotal; i++) {
1024 for (j=0; j<
fNvar; j++)
1025 temp[j]=data[index[i]][j];
1045 for (j=0; j<
fNvar; j++) {
1049 for (i=0; i<
fN; i++) {
1051 for(j=0; j<
fNvar; j++) {
1058 for (i=0; i<
fN; i++) {
1059 if(ndist[i] < 1
e-14) nhyp++;
1085 for (i=0; i<
fN; i++) {
1086 if(ndist[i]<1
e-14) {
1087 for (j=0; j<
fNvar; j++)
1102 for(i=0; i<
fNvar; i++) {
1103 mstockbig(nbest*kgroup+maxind,i)=
fMean(i);
1105 for(j=0; j<
fNvar; j++) {
1106 cstockbig(i,nbest*kgroup*fNvar+maxind*fNvar+j)=
fCovariance(i,j);
1122 if ((
fN>=2*nmini) && (
fN<=(3*nmini-1))) {
1127 indsubdat[0]=indsubdat[1]=
Int_t(
fN/2);
1131 if((
fN>=3*nmini) && (
fN<(4*nmini -1))) {
1133 indsubdat[0]=indsubdat[1]=indsubdat[2]=
Int_t(
fN/3);
1138 else indsubdat[2]=
Int_t(
fN/3)+1;
1143 if((
fN>=4*nmini)&&(
fN<=(5*nmini-1))){
1144 if (
fN%4==0) indsubdat[0]=indsubdat[1]=indsubdat[2]=indsubdat[3]=
Int_t(
fN/4);
1148 if(
fN%4==1) indsubdat[2]=indsubdat[3]=
Int_t(
fN/4);
1153 if(
fN%4==3) indsubdat[2]=indsubdat[3]=
Int_t(
fN/4)+1;
1157 for(
Int_t i=0; i<5; i++)
1183 for (i=0; i<
fN; i++) {
1185 for(j=0; j<
fNvar; j++) {
1189 for(j=0; j<
fNvar; j++) {
1203 for (i=0; i<
fN; i++) {
1205 for(j=0; j<
fNvar; j++) {
1210 for(j=0; j<
fNvar; j++) {
1218 for(i=0; i<
fN; i++) {
1219 if (
fRd[i]<=cutoff) {
1220 for(j=0; j<
fNvar; j++)
1221 temp[j]=
fData[i][j];
1241 for (k=1; k<=ngroup; k++) {
1242 for (m=1; m<=indsubdat[k-1]; m++) {
1249 subdat[jndex-1]=nrand+jndex-2;
1250 for (i=1; i<=jndex-1; i++) {
1251 if(subdat[i-1] > nrand+i-2) {
1252 for(j=jndex; j>=i+1; j--) {
1253 subdat[j-1]=subdat[j-2];
1256 subdat[i-1]=nrand+i-2;
1270 const Int_t kWorkMax=100;
1274 Int_t workLocal[kWorkMax];
1282 if (ntotal > kWorkMax) {
1283 isAllocated =
kTRUE;
1284 ind =
new Int_t[ntotal];
1288 for (
Int_t ii=0; ii<ntotal; ii++) {
1296 if (ir == l+1 && a[ind[ir]]<a[ind[l]])
1297 {temp = ind[
l]; ind[
l]=ind[ir]; ind[ir]=temp;}
1304 {temp = ind[
mid]; ind[
mid]=ind[l+1]; ind[l+1]=temp;}
1305 if (a[ind[l]]>a[ind[ir]])
1306 {temp = ind[
l]; ind[
l]=ind[ir]; ind[ir]=temp;}
1308 if (a[ind[l+1]]>a[ind[ir]])
1309 {temp=ind[l+1]; ind[l+1]=ind[ir]; ind[ir]=temp;}
1311 if (a[ind[l]]>a[ind[l+1]])
1312 {temp = ind[
l]; ind[
l]=ind[l+1]; ind[l+1]=temp;}
1318 do i++;
while (a[ind[i]]<a[arr]);
1319 do j--;
while (a[ind[j]]>a[arr]);
1321 {temp=ind[i]; ind[i]=ind[j]; ind[j]=temp;}
1325 if (j>=rk) ir = j-1;
void Classic()
called when h=n.
Int_t GetNOut()
returns the number of outliers
static long int sum(long int i)
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
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...
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t mid
Long64_t LocMax(Long64_t n, const T *a)
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...
const Double_t kChiMedian[50]
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 Evaluate()
Finds the estimate of multivariate mean and variance.
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.
void ClearSscp(TMatrixD &sscp)
clear the sscp matrix, used for covariance and mean calculation
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 ...
Short_t Min(Short_t a, Short_t b)
Double_t KOrdStat(Int_t ntotal, Double_t *arr, Int_t k, Int_t *work)
because I need an Int_t work array
void AddRow(Double_t *row)
adds a vector to the data matrix it is supposed that the vector is of size fNvar
const TMatrixDSym * GetCovariance() const
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
const TVectorD * GetMean() const
TMatrixDSym fInvcovariance
Minimum Covariance Determinant Estimator - a Fast Algorithm invented by Peter J.Rousseeuw and Katrien...
Double_t GetChiQuant(Int_t i) const
returns the chi2 quantiles
const Double_t kChiQuant[50]
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Bool_t Invert(TMatrixDSym &inv)
For a symmetric matrix A(m,m), its inverse A_inv(m,m) is returned .
void Set(Int_t n)
Set size of this array to n ints.
Element * GetMatrixArray()
Cholesky Decomposition class.
virtual Double_t Determinant() const
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...
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void AddToSscp(TMatrixD &sscp, TVectorD &vec)
update the sscp matrix with vector vec
const TVectorD * GetRDistances() const
Int_t GetNoElements() const
Int_t Exact(Double_t *ndist)
for the exact fit situations returns number of observations on the 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...
R__EXTERN TRandom * gRandom
const TMatrixD & GetEigenVectors() const
const TVectorD * GetHyperplane() const
if the points are on a hyperplane, returns this hyperplane
const TVectorD & GetEigenValues() const
const TMatrixDSym * GetCorrelation() const
Double_t Median(Long64_t n, const T *a, const Double_t *w=0, Long64_t *work=0)
Int_t RDist(TMatrixD &sscp)
Calculates robust distances.Then the samples with robust distances greater than a cutoff value (0...
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...
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Int_t GetBDPoint()
returns the breakdown point of the algorithm
void Correl()
transforms covariance matrix into correlation matrix
void Covar(TMatrixD &sscp, TVectorD &m, TMatrixDSym &cov, TVectorD &sd, Int_t nvec)
calculates mean and covariance
TRobustEstimator()
this constructor should be used in a univariate case: first call this constructor, then - the EvaluateUni(..) function
Double_t Sqrt(Double_t x)
Long64_t LocMin(Long64_t n, const T *a)
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.