X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Flanguage%2Fstats%2Fquick-cluster.c;h=161b9768b1fc431d8cd71ad9169062e13431e543;hb=f41e87501f3a3c600f4443033799b1689f84270a;hp=e3bb76e42257362387c0077c2f4fb7f3a047ab64;hpb=2c4b104df57f2e8b5ed2afa50819294aaac4aa6c;p=pspp diff --git a/src/language/stats/quick-cluster.c b/src/language/stats/quick-cluster.c index e3bb76e422..161b9768b1 100644 --- a/src/language/stats/quick-cluster.c +++ b/src/language/stats/quick-cluster.c @@ -247,7 +247,7 @@ dist_from_case (const struct Kmeans *kmeans, const struct ccase *c, for (j = 0; j < qc->n_vars; j++) { const union value *val = case_data (c, qc->vars[j]); - if (var_is_value_missing (qc->vars[j], val, qc->exclude)) + if (var_is_value_missing (qc->vars[j], val) & qc->exclude) NOT_REACHED (); dist += pow2 (gsl_matrix_get (kmeans->centers, which, j) - val->f); @@ -302,7 +302,7 @@ kmeans_initial_centers (struct Kmeans *kmeans, for (j = 0; j < qc->n_vars; ++j) { const union value *val = case_data (c, qc->vars[j]); - if (var_is_value_missing (qc->vars[j], val, qc->exclude)) + if (var_is_value_missing (qc->vars[j], val) & qc->exclude) { missing = true; break; @@ -385,7 +385,7 @@ kmeans_get_nearest_group (const struct Kmeans *kmeans, struct ccase *c, for (j = 0; j < qc->n_vars; j++) { const union value *val = case_data (c, qc->vars[j]); - if (var_is_value_missing (qc->vars[j], val, qc->exclude)) + if (var_is_value_missing (qc->vars[j], val) & qc->exclude) continue; dist += pow2 (gsl_matrix_get (kmeans->centers, i, j) - val->f); @@ -462,7 +462,7 @@ kmeans_cluster (struct Kmeans *kmeans, struct casereader *reader, for (j = 0; j < qc->n_vars; j++) { const union value *val = case_data (c, qc->vars[j]); - if (var_is_value_missing (qc->vars[j], val, qc->exclude)) + if (var_is_value_missing (qc->vars[j], val) & qc->exclude) missing = true; } @@ -488,7 +488,7 @@ kmeans_cluster (struct Kmeans *kmeans, struct casereader *reader, for (j = 0; j < qc->n_vars; ++j) { const union value *val = case_data (c, qc->vars[j]); - if (var_is_value_missing (qc->vars[j], val, qc->exclude)) + if (var_is_value_missing (qc->vars[j], val) & qc->exclude) continue; double *x = gsl_matrix_ptr (kmeans->updated_centers, group, j); *x += val->f * (qc->wv ? case_num (c, qc->wv) : 1.0); @@ -529,7 +529,7 @@ kmeans_cluster (struct Kmeans *kmeans, struct casereader *reader, for (j = 0; j < qc->n_vars; ++j) { const union value *val = case_data (c, qc->vars[j]); - if (var_is_value_missing (qc->vars[j], val, qc->exclude)) + if (var_is_value_missing (qc->vars[j], val) & qc->exclude) continue; double *x = gsl_matrix_ptr (kmeans->updated_centers, group, j); @@ -610,7 +610,7 @@ quick_cluster_show_centers (struct Kmeans *kmeans, bool initial, const struct qc /* A transformation function which juxtaposes the dataset with the (pre-prepared) dataset containing membership and/or distance values. */ -static int +static enum trns_result save_trans_func (void *aux, struct ccase **c, casenumber x UNUSED) { const struct save_trans_data *std = aux; @@ -905,8 +905,7 @@ quick_cluster_parse (struct lexer *lexer, struct qc *qc) } else { - lex_error (lexer, _("Expecting %s or %s."), - "CLUSTER", "DISTANCE"); + lex_error_expecting (lexer, "CLUSTER", "DISTANCE"); return false; } } @@ -931,14 +930,9 @@ quick_cluster_parse (struct lexer *lexer, struct qc *qc) else if (lex_match_id (lexer, "CONVERGE")) { if (lex_force_match (lexer, T_LPAREN) && - lex_force_num (lexer)) + lex_force_num_range_open (lexer, "CONVERGE", 0, DBL_MAX)) { qc->epsilon = lex_number (lexer); - if (qc->epsilon <= 0) - { - lex_error (lexer, _("The convergence criterion must be positive")); - return false; - } lex_get (lexer); if (!lex_force_match (lexer, T_RPAREN)) return false; @@ -1076,7 +1070,12 @@ cmd_quick_cluster (struct lexer *lexer, struct dataset *ds) std->distance = dict_create_var_assert (qc.dict, qc.var_distance, 0); } - add_transformation (qc.dataset, save_trans_func, save_trans_destroy, std); + static const struct trns_class trns_class = { + .name = "QUICK CLUSTER", + .execute = save_trans_func, + .destroy = save_trans_destroy, + }; + add_transformation (qc.dataset, &trns_class, std); } free (qc.var_distance);