} // data point j
// (3) Iterations
Int_t nit = 0;
- Bool_t rmovalStep = kFALSE;
while(1) {
nit++;
// Sigma
for (i = 0; i < k; i++) {
sigma2[i] = 0.;
- for (j = 1; j < n; j++) {
+ for (j = 0; j < n; j++) {
sigma2[i] += r[j][i] * d(mx[i], my[i], x[j], y[j]);
} // Data
sigma2[i] /= rk[i];
} // data point j
// (3) Iterations
Int_t nit = 0;
- Bool_t rmovalStep = kFALSE;
while(1) {
nit++;
sigmax2[i] = 0.;
sigmay2[i] = 0.;
- for (j = 1; j < n; j++) {
+ for (j = 0; j < n; j++) {
Double_t dx = TMath::Abs(mx[i]-x[j]);
if (dx > TMath::Pi()) dx = 2. * TMath::Pi() - dx;
Double_t dy = TMath::Abs(my[i]-y[j]);
}
+ClassImp(AliKMeansResult)
+
+
+
+AliKMeansResult::AliKMeansResult(Int_t k):
+ TObject(),
+ fK(k),
+ fMx (new Double_t[k]),
+ fMy (new Double_t[k]),
+ fSigma2(new Double_t[k]),
+ fRk (new Double_t[k]),
+ fTarget(new Double_t[k]),
+ fInd (new Int_t[k])
+{
+// Constructor
+}
+
+AliKMeansResult::AliKMeansResult(const AliKMeansResult &res):
+ TObject(res),
+ fK(res.GetK()),
+ fMx(0),
+ fMy(0),
+ fSigma2(0),
+ fRk(0),
+ fTarget(0),
+ fInd(0)
+{
+ // Copy constructor
+ for (Int_t i = 0; i <fK; i++) {
+ fMx[i] = (res.GetMx()) [i];
+ fMy[i] = (res.GetMy()) [i];
+ fSigma2[i] = (res.GetSigma2())[i];
+ fRk[i] = (res.GetRk()) [i];
+ fTarget[i] = (res.GetTarget())[i];
+ fInd[i] = (res.GetInd()) [i];
+ }
+}
+
+AliKMeansResult& AliKMeansResult::operator=(const AliKMeansResult& res)
+{
+ //
+ // Assignment operator
+ if (this != &res) {
+ fK = res.GetK();
+ for (Int_t i = 0; i <fK; i++) {
+ fMx[i] = (res.GetMx()) [i];
+ fMy[i] = (res.GetMy()) [i];
+ fSigma2[i] = (res.GetSigma2())[i];
+ fRk[i] = (res.GetRk()) [i];
+ fTarget[i] = (res.GetTarget())[i];
+ fInd[i] = (res.GetInd()) [i];
+ }
+ }
+ return *this;
+}
+
+
+AliKMeansResult::~AliKMeansResult()
+{
+// Destructor
+ delete[] fMx;
+ delete[] fMy;
+ delete[] fSigma2;
+ delete[] fRk;
+ delete[] fInd;
+ delete[] fTarget;
+}
+
+void AliKMeansResult::Sort()
+{
+ // Build target array and sort
+ // Sort clusters
+ for (Int_t i = 0; i < fK; i++) {
+ if (fRk[i] > 2.9) {
+ fTarget[i] = fRk[i] / fSigma2[i];
+ }
+ else fTarget[i] = 0.;
+ }
+
+ TMath::Sort(fK, fTarget, fInd);
+}
+
+void AliKMeansResult::Sort(Int_t n, Double_t* x, Double_t* y)
+{
+ // Build target array and sort
+ for (Int_t i = 0; i < fK; i++)
+ {
+ Int_t nc = 0;
+ for (Int_t j = 0; j < n; j++)
+ {
+ if (2. * AliKMeansClustering::d(fMx[i], fMy[i], x[j], y[j]) < 2.28 * fSigma2[i]) nc++;
+ }
+
+ if (nc > 2) {
+ fTarget[i] = Double_t(nc) / (2.28 * fSigma2[i]);
+ } else {
+ fTarget[i] = 0.;
+ }
+ }
+
+ TMath::Sort(fK, fTarget, fInd);
+}
+
+void AliKMeansResult::CopyResults(AliKMeansResult* res)
+{
+ fK = res->GetK();
+ for (Int_t i = 0; i <fK; i++) {
+ fMx[i] = (res->GetMx()) [i];
+ fMy[i] = (res->GetMy()) [i];
+ fSigma2[i] = (res->GetSigma2())[i];
+ fRk[i] = (res->GetRk()) [i];
+ fTarget[i] = (res->GetTarget())[i];
+ fInd[i] = (res->GetInd()) [i];
+ }
+}