X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Forder-stats.c;h=157bf2a165d1cd342027728ba5d020a73021413e;hb=62b5101a28fc2c4a9b8b26a998fb6c4ec12d84c7;hp=f5b6851ac1e06822363a178a17004850c94520ba;hpb=bb611ecc6f1c33a0a7c691785927c545d18696f6;p=pspp diff --git a/src/math/order-stats.c b/src/math/order-stats.c index f5b6851ac1..157bf2a165 100644 --- a/src/math/order-stats.c +++ b/src/math/order-stats.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,14 +15,48 @@ along with this program. If not, see . */ #include -#include "order-stats.h" -#include -#include -#include -#include -#include + +#include "math/order-stats.h" + #include +#include "data/casereader.h" +#include "data/val-type.h" +#include "data/variable.h" +#include "libpspp/assertion.h" + +#include "gl/xalloc.h" + +#if 0 + +#include + +static void +order_stats_dump_k1 (const struct order_stats *os) +{ + struct k *k = &os->k[0]; + printf ("K1: tc %g; c %g cc %g ccp %g\n", + k->tc, k->c, k->cc, k->cc_p1); + +} + +static void +order_stats_dump_k2 (const struct order_stats *os) +{ + struct k *k = &os->k[1]; + printf ("K2: tc %g; c %g cc %g ccp %g\n", + k->tc, k->c, k->cc, k->cc_p1); +} + + +void +order_stats_dump (const struct order_stats *os) +{ + order_stats_dump_k1 (os); + order_stats_dump_k2 (os); +} + +#endif static void update_k_lower (struct k *kk, @@ -55,11 +89,12 @@ update_k_values (const struct ccase *cx, double y_i, double c_i, double cc_i, struct order_stats **os, size_t n_os) { int j; + for (j = 0 ; j < n_os ; ++j) { int k; struct order_stats *tos = os[j]; - struct statistic *stat = (struct statistic *) tos; + struct statistic *stat = &tos->parent; for (k = 0 ; k < tos->n_k; ++k) { struct k *myk = &tos->k[k]; @@ -69,51 +104,69 @@ update_k_values (const struct ccase *cx, double y_i, double c_i, double cc_i, if ( stat->accumulate ) stat->accumulate (stat, cx, c_i, cc_i, y_i); + + tos->cc = cc_i; } } void -order_stats_accumulate (struct order_stats **os, size_t nos, - struct casereader *reader, - const struct variable *wv, - const struct variable *var) +order_stats_accumulate_idx (struct order_stats **os, size_t nos, + struct casereader *reader, + int wt_idx, + int val_idx) { - struct ccase cx; - struct ccase prev_cx; + struct ccase *cx; + struct ccase *prev_cx = NULL; double prev_value = -DBL_MAX; double cc_i = 0; double c_i = 0; - case_nullify (&prev_cx); - - for (; casereader_read (reader, &cx); case_destroy (&cx)) + for (; (cx = casereader_read (reader)) != NULL; case_unref (cx)) { - const double weight = wv ? case_data (&cx, wv)->f : 1.0; - const double this_value = case_data (&cx, var)->f; + const double weight = (wt_idx == -1) ? 1.0 : case_data_idx (cx, wt_idx)->f; + const double this_value = case_data_idx (cx, val_idx)->f; /* The casereader MUST be sorted */ assert (this_value >= prev_value); - case_destroy (&prev_cx); - if ( prev_value == -DBL_MAX || prev_value == this_value) c_i += weight; if ( prev_value > -DBL_MAX && this_value > prev_value) { - update_k_values (&prev_cx, prev_value, c_i, cc_i, os, nos); + update_k_values (prev_cx, prev_value, c_i, cc_i, os, nos); c_i = weight; } + case_unref (prev_cx); cc_i += weight; prev_value = this_value; - case_clone (&prev_cx, &cx); + prev_cx = case_ref (cx); } - update_k_values (&prev_cx, prev_value, c_i, cc_i, os, nos); - case_destroy (&prev_cx); + update_k_values (prev_cx, prev_value, c_i, cc_i, os, nos); + case_unref (prev_cx); casereader_destroy (reader); } + + +void +order_stats_accumulate (struct order_stats **os, size_t nos, + struct casereader *reader, + const struct variable *wv, + const struct variable *var, + enum mv_class exclude) +{ + /* Filter out missing cases */ + reader = casereader_create_filter_missing (reader, &var, 1, + exclude, NULL, NULL); + + order_stats_accumulate_idx (os, nos, + reader, + wv ? var_get_case_index (wv) : -1, + var_get_case_index (var)); +} +