#include "algorithm.h"
#include "alloc.h"
#include "moments.h"
+#include "percentiles.h"
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <assert.h>
-
+#include <chart.h>
void
-metrics_precalc(struct metrics *fs)
+metrics_precalc(struct metrics *m)
{
- assert (fs) ;
+ assert (m) ;
- fs->n_missing = 0;
+ m->n_missing = 0;
- fs->min = DBL_MAX;
- fs->max = -DBL_MAX;
+ m->min = DBL_MAX;
+ m->max = -DBL_MAX;
- fs->moments = moments1_create(MOMENT_KURTOSIS);
+ m->moments = moments1_create(MOMENT_KURTOSIS);
- fs->ordered_data = hsh_create(20,
+ m->ordered_data = hsh_create(20,
(hsh_compare_func *) compare_values,
(hsh_hash_func *) hash_value,
(hsh_free_func *) weighted_value_free,
(void *) 0);
-
}
/* FIXME: Check this is correct ???
Shouldn't we use the sample variance ??? */
- m->stderr = sqrt (m->var / m->n) ;
+ m->se_mean = sqrt (m->var / m->n) ;
m->wvp = (struct weighted_value **) hsh_sort(m->ordered_data);
m->n_data = hsh_count(m->ordered_data);
- if ( m->n_data == 0 )
+ m->histogram = histogram_create(10, m->min, m->max);
+
+ for ( i = 0 ; i < m->n_data ; ++i )
{
- m->trimmed_mean = m->mean;
- return;
+ struct weighted_value **wv = (m->wvp) ;
+ 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;
-
for ( i = 0 ; i < m->n_data ; ++i )
{
cc += m->wvp[i]->w;
if ( cc < tc )
k1 = i;
-
}
+
+
k2 = m->n_data;
for ( i = m->n_data -1 ; i >= 0; --i )
{
}
+ /* Calculate the percentiles */
+ ptiles(m->ptile_hash, m->wvp, m->n_data, m->n, m->ptile_alg);
+
+ tukey_hinges(m->wvp, m->n_data, m->n, m->hinge);
+
+ /* Special case here */
+ if ( k1 + 1 == k2 )
+ {
+ m->trimmed_mean = m->wvp[k2]->v.f;
+ return;
+ }
+
m->trimmed_mean = 0;
for ( i = k1 + 2 ; i <= k2 - 1 ; ++i )
{
factor_statistics_free(struct factor_statistics *f)
{
hsh_destroy(f->m->ordered_data);
+ gsl_histogram_free(f->m->histogram);
free(f->m) ;
free(f);
}