111 0.454937, 1.38629, 2.36597, 3.35670, 4.35146, 5.34812, 6.34581, 7.34412, 8.34283,
112 9.34182, 10.34, 11.34, 12.34, 13.34, 14.34, 15.34, 16.34, 17.34, 18.34, 19.34,
113 20.34, 21.34, 22.34, 23.34, 24.34, 25.34, 26.34, 27.34, 28.34, 29.34, 30.34,
114 31.34, 32.34, 33.34, 34.34, 35.34, 36.34, 37.34, 38.34, 39.34, 40.34,
115 41.34, 42.34, 43.34, 44.34, 45.34, 46.34, 47.34, 48.34, 49.33};
118 5.02389, 7.3776,9.34840,11.1433,12.8325,
119 14.4494,16.0128,17.5346,19.0228,20.4831,21.920,23.337,
120 24.736,26.119,27.488,28.845,30.191,31.526,32.852,34.170,
121 35.479,36.781,38.076,39.364,40.646,41.923,43.194,44.461,
122 45.722,46.979,48.232,49.481,50.725,51.966,53.203,54.437,
123 55.668,56.896,58.120,59.342,60.561,61.777,62.990,64.201,
124 65.410,66.617,67.821,69.022,70.222,71.420};
138 fCovariance(nvariables),
139 fInvcovariance(nvariables),
140 fCorrelation(nvariables),
144 fHyperplane(nvariables),
145 fData(nvectors, nvariables)
147 if ((nvectors<=1)||(nvariables<=0)){
148 Error(
"TRobustEstimator",
"Not enough vectors or variables");
152 Error(
"TRobustEstimator",
"For the univariate case, use the default constructor and EvaluateUni() function");
160 Warning(
"TRobustEstimator",
"chosen h is too small, default h is taken instead");
219 Warning(
"Evaluate",
"Chosen h = #observations, so classic estimates of location and scatter will be calculated");
236 for (i=0; i<nbest; i++)
250 for (k=0; k<k1; k++) {
254 for (i=0; i<
fH; i++) {
255 for(j=0; j<
fNvar; j++)
256 vec(j)=
fData[index[i]][j];
269 det =
CStep(fN, fH, index,
fData, sscp, ndist);
277 det =
CStep(fN, fH, index,
fData, sscp, ndist);
286 if(det<deti[maxind]) {
288 for(ii=0; ii<
fNvar; ii++) {
289 mstock(maxind, ii)=
fMean(ii);
290 for(jj=0; jj<
fNvar; jj++)
299 for (i=0; i<nbest; i++) {
300 for(ii=0; ii<
fNvar; ii++) {
301 fMean(ii)=mstock(i, ii);
302 for (jj=0; jj<
fNvar; jj++)
314 for(ii=0; ii<
fNvar; ii++) {
315 mstock(i,ii)=
fMean(ii);
316 for (jj=0; jj<
fNvar; jj++)
322 for(ii=0; ii<
fNvar; ii++) {
323 fMean(ii)=mstock(detind,ii);
325 for(jj=0; jj<
fNvar; jj++)
329 if (deti[detind]!=0) {
337 for (i=0; i<
fN; i++) {
359 for (ii=0; ii<5; ii++)
365 for (ii=0; ii<5; ii++)
370 for (
int iii = 0; iii < sum; ++iii) subdat[iii] = -999;
371 RDraw(subdat, nsub, indsubdat);
372 for (
int iii = 0; iii < sum; ++iii) {
373 if (subdat[iii] < 0 || subdat[iii] >= fN ) {
374 Error(
"Evaluate",
"subdat index is invalid subdat[%d] = %d",iii, subdat[iii] );
380 Int_t nbestsub=nbest*nsub;
384 for (i=0; i<nbestsub; i++) {
385 for(j=0; j<
fNvar; j++)
396 for (
Int_t kgroup=0; kgroup<nsub; kgroup++) {
398 Int_t ntemp=indsubdat[kgroup];
400 for (i=0; i<kgroup; i++)
405 for(i=0; i<ntemp; i++) {
406 for (j=0; j<
fNvar; j++) {
407 dattemp(i,j)=
fData[subdat[temp+i]][j];
412 for (i=0; i<nbest; i++)
415 for(k=0; k<k2; k++) {
418 for (i=0; i<htemp; i++) {
419 for(j=0; j<
fNvar; j++) {
420 vec(j)=dattemp(index[i],j);
427 par =
Exact2(mstockbig, cstockbig, hyperplane, deti, nbest, kgroup, sscp,ndist);
439 det =
CStep(ntemp, htemp, index, dattemp, sscp, ndist);
441 par=
Exact2(mstockbig, cstockbig, hyperplane, deti, nbest, kgroup, sscp, ndist);
453 det=
CStep(ntemp,htemp, index, dattemp, sscp, ndist);
455 par=
Exact2(mstockbig, cstockbig, hyperplane, deti, nbest, kgroup, sscp,ndist);
469 if(det<deti[maxind]) {
471 for(i=0; i<
fNvar; i++) {
472 mstockbig(nbest*kgroup+maxind,i)=
fMean(i);
473 for(j=0; j<
fNvar; j++) {
474 cstockbig(i,nbest*kgroup*fNvar+maxind*fNvar+j)=
fCovariance(i,j);
485 if (deti[maxind]<kEps)
490 for(i=0; i<nbest; i++) {
491 detibig[kgroup*nbest + i]=deti[i];
502 for(i=0; i<sum; i++) {
503 for (j=0; j<
fNvar; j++)
504 datmerged(i,j)=
fData[subdat[i]][j];
510 for(k=0; k<nbestsub; k++) {
512 for(ii=0; ii<
fNvar; ii++) {
513 fMean(ii)=mstockbig(k,ii);
514 for(jj=0; jj<
fNvar; jj++)
518 for(i=0; i<
fNvar; i++)
523 det=
CStep(sum, hmerged, index, datmerged, sscp, ndist);
540 det=
CStep(sum, hmerged, index, datmerged, sscp, ndist);
554 for(i=0; i<
fNvar; i++) {
555 mstockbig(k,i)=
fMean(i);
556 for(j=0; j<
fNvar; j++) {
565 for(i=0; i<
fNvar; i++) {
566 fMean(i)=mstockbig(minind,i);
568 for(j=0; j<
fNvar; j++)
592 for (i=0; i<
fN; i++) {
618 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};
631 Int_t len=nvectors-hh;
633 for(
Int_t i=0; i<len; i++)
635 for(
Int_t jint=0; jint<len; jint++) {
637 for (
Int_t j=0; j<hh; j++) {
638 aw[jint]+=data[index[j+jint]];
640 sq+=data[index[j]]*data[index[j]];
642 aw2[jint]=aw[jint]*aw[jint]/hh;
647 slutn[ndup]=aw[jint];
650 sq=sq - data[index[jint-1]]*data[index[jint-1]]+
651 data[index[jint+hh]]*data[index[jint+hh]]-
652 aw2[jint]+aw2[jint-1];
656 slutn[ndup]=aw[jint];
661 slutn[ndup]=aw[jint];
667 slutn[0]=slutn[
Int_t((ndup)/2)]/hh;
692 if (i < 0 || i >= 50)
return 0;
702 Warning(
"GetCovariance",
"provided matrix is of the wrong size, it will be resized");
714 Warning(
"GetCorrelation",
"provided matrix is of the wrong size, it will be resized");
726 Error(
"GetHyperplane",
"the data doesn't lie on a hyperplane!\n");
739 Error(
"GetHyperplane",
"the data doesn't lie on a hyperplane!\n");
743 Warning(
"GetHyperPlane",
"provided vector is of the wrong size, it will be resized");
755 Warning(
"GetMean",
"provided vector is of the wrong size, it will be resized");
767 Warning(
"GetRDistances",
"provided vector is of the wrong size, it will be resized");
787 for (j=1; j<
fNvar+1; j++) {
788 sscp(0, j) +=vec(j-1);
789 sscp(j, 0) = sscp(0, j);
791 for (i=1; i<fNvar+1; i++) {
792 for (j=1; j<fNvar+1; j++) {
793 sscp(i, j) += vec(i-1)*vec(j-1);
804 for (
Int_t j=0; j<fNvar+1; j++) {
836 for (i=0; i<
fNvar; i++) {
838 sd[i]=sscp(i+1, i+1);
839 f=(sd[i]-
m(i)*
m(i)/nvec)/(nvec-1);
844 for (i=0; i<
fNvar; i++) {
845 for (j=0; j<
fNvar; j++) {
846 cov(i, j)=sscp(i+1, j+1)-nvec*
m(i)*
m(j);
859 for(j=0; j<
fNvar; j++)
861 for(i=0; i<
fNvar; i++) {
862 for (j=0; j<
fNvar; j++) {
890 for(i=0; i<ntotal; i++)
893 for (i=0; i<p+1; i++) {
896 for(j=0; j<=i-1; j++) {
914 for (i=0; i<p+1; i++) {
915 for (j=0; j<
fNvar; j++) {
916 vec[j]=data[index[i]][j];
924 while((det<kEps)&&(nindex < htotal)) {
932 for(i=0; i<nindex; i++) {
938 }
while(repeat==
kTRUE);
943 for(j=0; j<
fNvar; j++)
944 vec[j]=data[index[nindex-1]][j];
955 for(j=0; j<ntotal; j++) {
957 for(i=0; i<
fNvar; i++)
958 temp[i]=data[j][i] -
fMean(i);
960 for(i=0; i<
fNvar; i++)
961 ndist[j]+=(data[j][i]-
fMean(i))*temp[i];
963 KOrdStat(ntotal, ndist, htotal-1,index);
977 for (i=0; i<nmerged; i++) {
979 for(j=0; j<
fNvar; j++) {
984 KOrdStat(nmerged, ndist, hmerged-1, index);
986 for (i=0; i<hmerged; i++) {
987 for(j=0; j<
fNvar; j++)
988 vec[j]=dat[index[i]][j];
1015 for(j=0; j<ntotal; j++) {
1017 for(i=0; i<
fNvar; i++)
1018 temp[i]=data[j][i]-
fMean[i];
1020 for(i=0; i<
fNvar; i++)
1021 ndist[j]+=(data[j][i]-
fMean[i])*temp[i];
1025 KOrdStat(ntotal, ndist, htotal-1, index);
1028 for (i=0; i<htotal; i++) {
1029 for (j=0; j<
fNvar; j++)
1030 temp[j]=data[index[i]][j];
1050 for (j=0; j<
fNvar; j++) {
1054 for (i=0; i<
fN; i++) {
1056 for(j=0; j<
fNvar; j++) {
1063 for (i=0; i<
fN; i++) {
1064 if(ndist[i] < 1e-14) nhyp++;
1090 for (i=0; i<
fN; i++) {
1091 if(ndist[i]<1e-14) {
1092 for (j=0; j<
fNvar; j++)
1107 for(i=0; i<
fNvar; i++) {
1108 mstockbig(nbest*kgroup+maxind,i)=
fMean(i);
1110 for(j=0; j<
fNvar; j++) {
1111 cstockbig(i,nbest*kgroup*fNvar+maxind*fNvar+j)=
fCovariance(i,j);
1127 if ((
fN>=2*nmini) && (
fN<=(3*nmini-1))) {
1132 indsubdat[0]=indsubdat[1]=
Int_t(
fN/2);
1136 if((
fN>=3*nmini) && (
fN<(4*nmini -1))) {
1138 indsubdat[0]=indsubdat[1]=indsubdat[2]=
Int_t(
fN/3);
1143 else indsubdat[2]=
Int_t(
fN/3)+1;
1148 if((
fN>=4*nmini)&&(
fN<=(5*nmini-1))){
1149 if (
fN%4==0) indsubdat[0]=indsubdat[1]=indsubdat[2]=indsubdat[3]=
Int_t(
fN/4);
1153 if(
fN%4==1) indsubdat[2]=indsubdat[3]=
Int_t(
fN/4);
1158 if(
fN%4==3) indsubdat[2]=indsubdat[3]=
Int_t(
fN/4)+1;
1162 for(
Int_t i=0; i<5; i++)
1188 for (i=0; i<
fN; i++) {
1190 for(j=0; j<
fNvar; j++) {
1194 for(j=0; j<
fNvar; j++) {
1208 for (i=0; i<
fN; i++) {
1210 for(j=0; j<
fNvar; j++) {
1215 for(j=0; j<
fNvar; j++) {
1223 for(i=0; i<
fN; i++) {
1224 if (
fRd[i]<=cutoff) {
1225 for(j=0; j<
fNvar; j++)
1226 temp[j]=
fData[i][j];
1246 for (k=1; k<=ngroup; k++) {
1247 for (m=1; m<=indsubdat[k-1]; m++) {
1254 subdat[jndex-1]=nrand+jndex-2;
1255 for (i=1; i<=jndex-1; i++) {
1256 if(subdat[i-1] > nrand+i-2) {
1257 for(j=jndex; j>=i+1; j--) {
1258 subdat[j-1]=subdat[j-2];
1261 subdat[i-1]=nrand+i-2;
1275 const Int_t kWorkMax=100;
1279 Int_t workLocal[kWorkMax];
1287 if (ntotal > kWorkMax) {
1288 isAllocated =
kTRUE;
1289 ind =
new Int_t[ntotal];
1301 if (ir == l+1 && a[ind[ir]]<a[ind[l]])
1302 {temp = ind[
l]; ind[
l]=ind[ir]; ind[ir]=temp;}
1309 {temp = ind[mid]; ind[mid]=ind[l+1]; ind[l+1]=temp;}
1310 if (a[ind[l]]>a[ind[ir]])
1311 {temp = ind[
l]; ind[
l]=ind[ir]; ind[ir]=temp;}
1313 if (a[ind[l+1]]>a[ind[ir]])
1314 {temp=ind[l+1]; ind[l+1]=ind[ir]; ind[ir]=temp;}
1316 if (a[ind[l]]>a[ind[l+1]])
1317 {temp = ind[
l]; ind[
l]=ind[l+1]; ind[l+1]=temp;}
1323 do i++;
while (a[ind[i]]<a[arr]);
1324 do j--;
while (a[ind[j]]>a[arr]);
1326 {temp=ind[i]; ind[i]=ind[j]; ind[j]=temp;}
1330 if (j>=rk) ir = j-1;
const TVectorD & GetEigenValues() const
void Classic()
called when h=n.
Int_t GetNOut()
returns the number of outliers
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...
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...
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
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 * GetHyperplane() const
if the points are on a hyperplane, returns this hyperplane
Double_t GetChiQuant(Int_t i) const
returns the chi2 quantiles
TMatrixDSym fInvcovariance
virtual Double_t Determinant() const
const Double_t kChiQuant[50]
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
const TVectorD * GetRDistances() const
Bool_t Invert(TMatrixDSym &inv)
For a symmetric matrix A(m,m), its inverse A_inv(m,m) is returned .
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void Set(Int_t n)
Set size of this array to n ints.
Element * GetMatrixArray()
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 AddToSscp(TMatrixD &sscp, TVectorD &vec)
update the sscp matrix with vector vec
Int_t Exact(Double_t *ndist)
for the exact fit situaions 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 TMatrixDSym * GetCorrelation() const
const TMatrixD & GetEigenVectors() 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...
ClassImp(TRobustEstimator) const Double_t kChiMedian[50]
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
Int_t GetNoElements() const
const TVectorD * GetMean() const
const TMatrixDSym * GetCovariance() const
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.