40 while (changed && (iter<max_iter))
44 SG_SWARNING(
"kmeans clustering changed throughout %d iterations stopping...\n", max_iter-1)
47 SG_SINFO(
"Iteration[%d/%d]: Assignment of %i patterns changed.\n", iter, max_iter, changed)
54 for (int32_t i=0; i<XSize; i++)
60 for (int32_t j=0; j<dimensions; j++)
61 mus.
matrix[Cl*dimensions+j] += vec[j];
66 for (int32_t i=0; i<k; i++)
68 if (weights_set[i]!=0.0)
70 for (int32_t j=0; j<dimensions; j++)
71 mus.
matrix[i*dimensions+j] /= weights_set[i];
76 for (int32_t i=0; i<XSize; i++)
80 const int32_t ClList_Pat=ClList[Pat];
85 for(int32_t idx_k=0;idx_k<k;idx_k++)
86 dists[idx_k]=distance->
distance(Pat,idx_k);
89 imini=0 ; mini=dists[0];
97 if (imini!=ClList_Pat)
102 weights_set[imini]+= 1.0;
104 weights_set[ClList_Pat]-= 1.0;
108 for (j=0; j<dimensions; j++)
110 mus.
matrix[imini*dimensions+j]-=
111 (vec[j]-mus.
matrix[imini*dimensions+j]) / weights_set[imini];
118 if (weights_set[ClList_Pat]!=0.0)
122 for (j=0; j<dimensions; j++)
124 mus.
matrix[ClList_Pat*dimensions+j]-=
125 (vec[j]-mus.
matrix[ClList_Pat*dimensions+j]) / weights_set[ClList_Pat];
132 for (j=0; j<dimensions; j++)
133 mus.
matrix[ClList_Pat*dimensions+j]=0;
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
virtual void copy_feature_matrix(SGMatrix< ST > src)
ST * get_feature_vector(int32_t num, int32_t &len, bool &dofree)
Class Distance, a base class for all the distances used in the Shogun toolbox.
int32_t get_num_features() const
virtual int32_t get_num_vectors() const
static void Lloyd_KMeans(int32_t k, CDistance *distance, int32_t max_iter, SGMatrix< float64_t > mus, SGVector< int32_t > ClList, SGVector< float64_t > weights_set, bool fixed_centers)
CFeatures * replace_rhs(CFeatures *rhs)
virtual float64_t distance(int32_t idx_a, int32_t idx_b)
all of classes and functions are contained in the shogun namespace
void free_feature_vector(ST *feat_vec, int32_t num, bool dofree)
The class Features is the base class of all feature objects.
static CDenseFeatures * obtain_from_generic(CFeatures *const base_features)