X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Ffactor_stats.c;h=29eebed2d5e6015f801724c450ab83f980c4e0a4;hb=4f31116689eeda21658601c6ecf75a915b80103b;hp=8109a2171f0774f25a3087ab156e0f40af475d03;hpb=a19e7749cdb8713316fde220f2fc9a5ad5dc79ed;p=pspp diff --git a/src/factor_stats.c b/src/factor_stats.c index 8109a2171f..29eebed2d5 100644 --- a/src/factor_stats.c +++ b/src/factor_stats.c @@ -15,11 +15,11 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. */ +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301, USA. */ +#include #include "factor_stats.h" -#include "config.h" #include "val.h" #include "hash.h" #include "algorithm.h" @@ -44,6 +44,7 @@ metrics_precalc(struct metrics *m) m->min = DBL_MAX; m->max = -DBL_MAX; + m->histogram = 0; m->moments = moments1_create(MOMENT_KURTOSIS); @@ -92,7 +93,7 @@ metrics_calc(struct metrics *fs, const union value *val, assert( (*wv)->v.f == val->f ); (*wv)->w += weight; - cn = xmalloc( sizeof (struct case_node) ) ; + cn = xmalloc ( sizeof *cn); cn->next = (*wv)->case_nos ; cn->num = case_no; @@ -106,7 +107,7 @@ metrics_calc(struct metrics *fs, const union value *val, (*wv)->v = *val; (*wv)->w = weight; - cn = xmalloc( sizeof (struct case_node) ) ; + cn = xmalloc (sizeof *cn); cn->next=0; cn->num = case_no; (*wv)->case_nos = cn; @@ -141,6 +142,13 @@ metrics_postcalc(struct metrics *m) m->wvp = (struct weighted_value **) hsh_sort(m->ordered_data); m->n_data = hsh_count(m->ordered_data); + /* Trimmed mean calculation */ + if ( m->n_data <= 1 ) + { + m->trimmed_mean = m->mean; + return; + } + m->histogram = histogram_create(10, m->min, m->max); for ( i = 0 ; i < m->n_data ; ++i ) @@ -149,13 +157,6 @@ metrics_postcalc(struct metrics *m) gsl_histogram_accumulate(m->histogram, wv[i]->v.f, wv[i]->w); } - /* Trimmed mean calculation */ - if ( m->n_data <= 1 ) - { - m->trimmed_mean = m->mean; - return; - } - tc = m->n * 0.05 ; k1 = -1; k2 = -1; @@ -214,7 +215,7 @@ struct weighted_value * weighted_value_create(void) { struct weighted_value *wv; - wv = xmalloc (sizeof (struct weighted_value )); + wv = xmalloc (sizeof *wv); wv->cc = 0; wv->case_nos = 0; @@ -255,11 +256,11 @@ create_factor_statistics (int n, union value *id0, union value *id1) { struct factor_statistics *f; - f = xmalloc( sizeof ( struct factor_statistics )); + f = xmalloc (sizeof *f); f->id[0] = *id0; f->id[1] = *id1; - f->m = xmalloc( sizeof ( struct metrics ) * n ) ; + f->m = xnmalloc (n, sizeof *f->m); memset (f->m, 0, sizeof(struct metrics) * n); f->n_var = n; @@ -272,7 +273,8 @@ metrics_destroy(struct metrics *m) { hsh_destroy(m->ordered_data); hsh_destroy(m->ptile_hash); - gsl_histogram_free(m->histogram); + if ( m-> histogram ) + gsl_histogram_free(m->histogram); } void