double Silhouette::calculate(Partition *pAPartition, RelationSDN *pARelation, DataSet *pADataset){ //Declaration variables used by Silhouette double silhouette = 0; // # retirar Similarity *pObjSimilarity = pARelation->getSimilarity(); //cout << pAPartition->getPartitionName() << endl; //Walk vector of all clusters for (Partition::itClustersOfPartition itClusterOnPartition = pAPartition->begin(); itClusterOnPartition != pAPartition->end(); itClusterOnPartition++){ double silPartial = 0; //Walk each object of cluster for(Cluster::itObjectsOfCluster itObjectsOnCluster1 = itClusterOnPartition->begin(); itObjectsOnCluster1 != itClusterOnPartition->end(); itObjectsOnCluster1++){ double dAxi = a(itObjectsOnCluster1, itClusterOnPartition, pARelation); double dBxi, dSxi; if (pARelation->getSimilarity()->isSimilarity()){ dBxi = bSimilarity(itObjectsOnCluster1, itClusterOnPartition, pAPartition, pARelation); if (dAxi > dBxi) dSxi = 1 - (dBxi / dAxi); else if (dAxi == dBxi) dSxi = 0; else dSxi = (dAxi / dBxi) - 1; } else { dBxi = bDissimilarity(itObjectsOnCluster1, itClusterOnPartition, pAPartition, pARelation); if (dAxi < dBxi) dSxi = 1 - (dAxi / dBxi); else if (dAxi == dBxi) dSxi = 0; else dSxi = (dBxi / dAxi) - 1; } silhouette += dSxi; silPartial += dSxi; } #ifdef IID cout << pAPartition->getPartitionName(); cout << "\tSIL \tcluster " << itClusterOnPartition->getLabel() << " \t(" << itClusterOnPartition->getNumberOfObjects() << " objects):\t" << silPartial/itClusterOnPartition->getNumberOfObjects() << endl; #endif } silhouette = silhouette / pAPartition->getNumObjects(); return silhouette; }
double Silhouette::calculate(Partition *pAPartition, RelationSDN *pARelation, DataSet *pADataset){ //Declaration variables used by Silhouette double silhouette = 0; // # retirar Similarity *pObjSimilarity = pARelation->getSimilarity(); //Walk vector of all clusters for (Partition::itClustersOfPartition itClusterOnPartition = pAPartition->begin(); itClusterOnPartition != pAPartition->end(); itClusterOnPartition++){ //Walk each object of cluster for(Cluster::itObjectsOfCluster itObjectsOnCluster1 = itClusterOnPartition->begin(); itObjectsOnCluster1 != itClusterOnPartition->end(); itObjectsOnCluster1++){ double dAxi = a(itObjectsOnCluster1, itClusterOnPartition, pARelation); double dBxi, dSxi; if (pARelation->getSimilarity()->isSimilarity()){ dBxi = bSimilarity(itObjectsOnCluster1, itClusterOnPartition, pAPartition, pARelation); if (dAxi > dBxi) dSxi = 1 - (dBxi / dAxi); else if (dAxi == dBxi) dSxi = 0; else dSxi = (dAxi / dBxi) - 1; } else { dBxi = bDissimilarity(itObjectsOnCluster1, itClusterOnPartition, pAPartition, pARelation); if (dAxi < dBxi) dSxi = 1 - (dAxi / dBxi); else if (dAxi == dBxi) dSxi = 0; else dSxi = (dBxi / dAxi) - 1; } silhouette += dSxi; } } silhouette = silhouette / pAPartition->getNumObjects(); return silhouette; }