Another chi-squared routine

Greg Louis glouis at dynamicro.on.ca
Fri Jan 10 23:45:21 CET 2003


Today I learned that the FSF has a scientific library (i.e. a
collection of numerical routines for scientific computing); version
gsl-1.3 was recently released.  It has routines for the distribution
functions, including chi-squared; but the chi-squared routine returns
probability density rather than cumulative values.  That's ok, though,
because a fast integration routine is provided as well.

Since the gsl compiles easily as a shared library, we could switch and
not have to carry our own truncated dcdflib in the distribution in
order to keep the executable size down.  This may not be deemed
desirable, though, since doing so would add another package dependency
to bogofilter, and not everyone needs numerical analysis stuff in
/usr/lib, handy as it might be for some of us ;)

I decided to try gsl anyhow.  I'm not offering a patch, but it's
trivially easy to add to any version of bogofilter that does Fisher:

In the file containing prbf(), delete the reference to dcdflib.h and
make these changes:

#include <gsl/gsl_randist.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_errno.h>

...

double chisq(double x, void *p) {
    return(gsl_ran_chisq_pdf(x, *(double *)p));
}

double prbf(double x, double df) {
    gsl_function chi; int status;
    double p, abserr; size_t neval;
    chi.function = chisq;
    chi.params = &df;
    gsl_set_error_handler_off();
    status = gsl_integration_qng(&chi, 0.00001, x, 0.0001, 0.01, &p,
        &abserr, &neval);
    /* if we didn't converge we might be outside [0,1] */
    p = max(0.0, 1.0 - p);
    return(min(1.0, p));
}


In configure.in add

AC_CHECK_LIB(gslcblas, main)
AC_CHECK_LIB(gsl, main)

after the check for libm.


In Makefile.am delete the line

		     dcdflib/src/dcdflib.c dcdflib/src/ipmpar.c \

and that's it.  The resulting binary is about 9% smaller than my
dcdflib version (both stripped), and produces the same spamicity
results within 1e-16 or so.

-- 
| G r e g  L o u i s          | gpg public key:      |
|   http://www.bgl.nu/~glouis |   finger greg at bgl.nu |




More information about the bogofilter-dev mailing list