X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=clusterer.cc;h=d4a70a6c5413ac6dd1a754501fe2b34499de6e4a;hb=379b91965f8d18b05cc40c4a14044eda29a6e82c;hp=02a8c8b990c4cc115c5dc23be7bb2bfd3c5a81e5;hpb=513062971a6c930bd6bb1ad5a8288d326e22bb25;p=clueless-kmeans.git diff --git a/clusterer.cc b/clusterer.cc index 02a8c8b..d4a70a6 100644 --- a/clusterer.cc +++ b/clusterer.cc @@ -35,8 +35,6 @@ Clusterer::~Clusterer() { } scalar_t Clusterer::distance_to_centroid(scalar_t *x, int k) { - // We take the variance into account + the normalization term. This - // is between k-mean and EM with a diagonal covariance scalar_t dist = 0; for(int d = 0; d < _dim; d++) { dist += sq(_cluster_means[k][d] - x[d]) / (2 * _cluster_var[k][d]); @@ -208,22 +206,25 @@ scalar_t Clusterer::uninformative_lp_cluster_association(int nb_points, scalar_t glp_add_cols(lp, nb_points * _nb_clusters); + // The column for gamma[n][k] point 1<=n<=nb_points and cluster + // 1<=k<=_nb_clusters is nb_points * (k - 1) + n; + // The constraints (A) will be expressed by putting directly bounds // on the variables (i.e. one per column). So we need one row per // (B) constraint, and one per (C) constraint. glp_add_rows(lp, nb_points + _nb_clusters * nb_classes); - // First, we set the weights for the objective function, and the - // constraint on the individual gammas + // First, we set the weights for the objective function, and the (A) + // constraints on the individual gammas for(int k = 1; k <= _nb_clusters; k++) { for(int n = 1; n <= nb_points; n++) { int col = n + nb_points * (k - 1); - // The LP weight on this association coefficient for the global - // loss is the normalized distance of that sample to the - // centroid of that cluster + // The LP weight on the gammas for the global loss is the + // normalized distance of that sample to the centroid of that + // cluster glp_set_obj_coef(lp, col, distance_to_centroid(points[n-1], k-1)); @@ -234,8 +235,8 @@ scalar_t Clusterer::uninformative_lp_cluster_association(int nb_points, scalar_t } } - // The (B) constraints: for each point, the sum of its association - // coefficients is equal to 1.0 + // The (B) constraints: for each point, the sum of its gamma is + // equal to 1.0 for(int n = 1; n <= nb_points; n++) { int row = n; @@ -249,9 +250,8 @@ scalar_t Clusterer::uninformative_lp_cluster_association(int nb_points, scalar_t } // The (C) constraints: For each pair cluster/class, the sum of the - // association coefficient to this cluster for this class is equal - // to the number of sample of that class, divided by the number of - // clusters + // gammas for this cluster and this class is equal to the number of + // sample of that class, divided by the number of clusters for(int k = 1; k <= _nb_clusters; k++) { for(int c = 1; c <= nb_classes; c++) {