#include #include namespace icl{ inline float distance(float *a, float *b){ // {{{ open return sqrt( pow(a[0]-b[0],2)+pow(a[1]-b[1],2) ); } // }}} inline int nn(float *data, int dim, float* point, float &dist){ // {{{ open int bestIndex = 0; dist = distance(data,point); float currDist = -1; for(int i=1 ; idim(); float *data = m_poData->data(); m_poCenters->resize(k); float *centers = m_poCenters->data(); // check if all parameters are valid! ICLASSERT_RETURN_VAL( k>=0 ,*m_poCenters); ICLASSERT_RETURN_VAL( n>=0 ,*m_poCenters); /************************************************** ** Random initialisation of the center vectors **** >> TODO other strategy or *************************************************** give them from anywhere else */ for(int p=0 ; p vecx(k),vecy(k); // mean x/y accumulators std::vector vecn(k); // cluster size counters for(int step = 0 ; stepdim(); int n = m_poData->dim(); VQVectorSet ¢ers = *m_poCenters; VQVectorSet &data = *m_poData; VQClusterInfo &info = *m_poClusterInfo; info.resize(k); info.clear(); float err, *p; int inn; for(int i=0;i