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 <config.h>
#include "factor_stats.h"
-#include "config.h"
#include "val.h"
#include "hash.h"
#include "algorithm.h"
m->min = DBL_MAX;
m->max = -DBL_MAX;
+ m->histogram = 0;
m->moments = moments1_create(MOMENT_KURTOSIS);
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;
(*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;
int i;
int j = 1;
-
moments1_calculate (m->moments, &m->n, &m->mean, &m->var,
&m->skewness, &m->kurtosis);
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 )
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;
/* 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->hinges);
+ tukey_hinges(m->wvp, m->n_data, m->n, m->hinge);
/* Special case here */
if ( k1 + 1 == k2 )
m->trimmed_mean += (m->wvp[k1 + 1]->cc - tc) * m->wvp[k1 + 1]->v.f ;
m->trimmed_mean /= 0.9 * m->n ;
+
}
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;
void
weighted_value_free(struct weighted_value *wv)
{
- struct case_node *cn = wv->case_nos;
+ struct case_node *cn ;
+
+ if ( !wv )
+ return ;
+
+ cn = wv->case_nos;
while(cn)
{
{
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;
return f;
}
+void
+metrics_destroy(struct metrics *m)
+{
+ hsh_destroy(m->ordered_data);
+ hsh_destroy(m->ptile_hash);
+ if ( m-> histogram )
+ gsl_histogram_free(m->histogram);
+}
+
void
factor_statistics_free(struct factor_statistics *f)
{
- hsh_destroy(f->m->ordered_data);
- gsl_histogram_free(f->m->histogram);
+
+ int i;
+ for ( i = 0 ; i < f->n_var; ++i )
+ metrics_destroy(&f->m[i]);
free(f->m) ;
free(f);
}