-static double
+static double
matrix_mindist (const gsl_matrix *m, int *mn, int *mm)
{
int i, j;
const union value *val = case_data (c, qc->vars[j]);
if ( var_is_value_missing (qc->vars[j], val, qc->exclude))
NOT_REACHED ();
-
+
dist += pow2 (gsl_matrix_get (kmeans->centers, which, j) - val->f);
}
-
+
return dist;
}
{
dist += pow2 (gsl_matrix_get (kmeans->centers, i, j) - gsl_matrix_get (kmeans->centers, which, j));
}
-
+
if (dist < mindist)
{
mindist = dist;
-/* Calculate the intial cluster centers. */
+/* Calculate the initial cluster centers. */
static void
kmeans_initial_centers (struct Kmeans *kmeans, const struct casereader *reader, const struct qc *qc)
{
}
}
else if (dist_from_case (kmeans, c, qc, mp) > min_dist_from (kmeans, qc, mq))
- /* If the distance between C and the second nearest group (MP) is greater than the
+ /* If the distance between C and the second nearest group (MP) is greater than the
smallest distance between the nearest group (MQ) and any other group, then replace
MQ with C */
{
if ( var_is_value_missing (qc->vars[j], val, qc->exclude))
missing = true;
}
-
+
if (missing)
continue;
double *x = gsl_matrix_ptr (kmeans->updated_centers, group, j);
*x += val->f * (qc->wv ? case_data (c, qc->wv)->f : 1.0);
}
- }
+ }
casereader_destroy (r);
}
*x /= n + 1; // Plus 1 for the initial centers
}
}
-
+
gsl_matrix_memcpy (kmeans->centers, kmeans->updated_centers);
{
kmeans->n = 0;
- int i;
/* Step 3 */
gsl_vector_long_set_all (kmeans->num_elements_groups, 0.0);
gsl_matrix_set_all (kmeans->updated_centers, 0.0);
struct ccase *c;
struct casereader *cs = casereader_clone (reader);
- for (; (c = casereader_read (cs)) != NULL; i++, case_unref (c))
+ for (; (c = casereader_read (cs)) != NULL; case_unref (c))
{
- int group = -1;
+ int group = -1;
kmeans_get_nearest_group (kmeans, c, qc, &group, NULL, NULL, NULL);
for (j = 0; j < qc->n_vars; ++j)
long *n = gsl_vector_long_ptr (kmeans->num_elements_groups, group);
*n += qc->wv ? case_data (c, qc->wv)->f : 1.0;
kmeans->n++;
-
-
}
casereader_destroy (cs);
for (i = 0; (c = casereader_read (cs)) != NULL; i++, case_unref (c))
{
- int clust = -1;
+ int clust = -1;
assert (i < kmeans->n);
kmeans_get_nearest_group (kmeans, c, qc, &clust, NULL, NULL, NULL);
clust = ip->data[clust];
quick_cluster_show_results (struct Kmeans *kmeans, const struct casereader *reader, const struct qc *qc)
{
kmeans_order_groups (kmeans, qc); /* what does this do? */
-
+
if( qc->print_initial_clusters )
quick_cluster_show_centers (kmeans, true, qc);
quick_cluster_show_centers (kmeans, false, qc);
lex_error (lexer, NULL);
goto error;
}
- }
+ }
}
else if (lex_match_id (lexer, "PRINT"))
{
goto error;
}
lex_get (lexer);
- lex_force_match (lexer, T_RPAREN);
+ if (!lex_force_match (lexer, T_RPAREN))
+ goto error;
}
}
else if (lex_match_id (lexer, "CONVERGE"))
goto error;
}
lex_get (lexer);
- lex_force_match (lexer, T_RPAREN);
+ if (!lex_force_match (lexer, T_RPAREN))
+ goto error;
}
}
else if (lex_match_id (lexer, "MXITER"))
goto error;
}
lex_get (lexer);
- lex_force_match (lexer, T_RPAREN);
+ if (!lex_force_match (lexer, T_RPAREN))
+ goto error;
}
}
else if (lex_match_id (lexer, "NOINITIAL"))