コード例 #1
0
    const Cluster &KMeans::operator[](unsigned int u) const {
        if (__k == 0) {
            throw ZeroClustersEx();
        }

        if (u >= __k) {
            throw DimensionalityMismatchEx(__k, u);
        }

        return *__clusters[u];
    }
コード例 #2
0
    KMeans::KMeans(unsigned int dim, unsigned int k, std::string filename, unsigned int maxIter) :
            __dimensionality(dim), __k(k), __iFileName(filename), __maxIter(maxIter) {
        if (k == 0)
            throw ZeroClustersEx();

        std::ifstream iFile(filename.c_str());

        if (iFile.fail())
            throw DataFileOpenEx(filename);

        iFile.close();
    }
コード例 #3
0
double Clustering::KMeans<k, dim>::computeDin() {
    try {
        if(clusterArr.size() == 0){
            throw ZeroClustersEx();
        }
        double result;
        for (int i = 0; i < clusterArr.size(); i++) {
            result += clusterArr[i].intraClusterDistance();
        }
        //Din = result;
        return result;
    }
    catch(double){
        return 0;
    }
}
コード例 #4
0
ファイル: KMeans.cpp プロジェクト: genessa/ucd-csci2312-pa3
//    class KMeans {
//        unsigned int __dimensionality;
//        unsigned int __k;
//        Cluster **__clusters;
//        Point **__initCentroids;
//        std::string __iFileName;
//        unsigned int __maxIter;
//        unsigned int __numIter;
//        unsigned int __numNonempty;
//        unsigned int __numMovesLastIter;
//
KMeans::KMeans(unsigned int dim, unsigned int k, std::string filename, unsigned int maxIter)
    {
        if (k==0)
        { throw ZeroClustersEx(); }

        std::ifstream inFile;
        inFile.open("filename");
        if (!inFile)
        { throw DataFileOpenEx(filename); }

        __dimensionality = dim;
        __k = k;
        __iFileName = filename;
        __maxIter = maxIter;
        __numNonempty = 1;
        __numIter = 0;
    }
コード例 #5
0
double Clustering::KMeans<k, dim>::computeDout() {
    try {
        if(clusterArr.size() == 0){
            throw ZeroClustersEx();
        }
        double result;
        for (int i = 0; i < clusterArr.size(); i++) {
            for (int j = 0; j < clusterArr.size(); j++) {
                result += interClusterDistance(clusterArr[i], clusterArr[j]);
            }
        }
        result /= 2;
        //Dout = result;
        return result;
    }
    catch(double){
        return 0;
    }
}