1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
/*-*-c-*-*/
/*
* ufuncs to compute logit(p) = log(p/(1-p)) and
* expit(x) = 1/(1+exp(-x))
*/
#include <Python.h>
#include <math.h>
#include "numpy/npy_math.h"
#include "_logit.h"
/*
* Inner loops for logit and expit
*/
/**begin repeat
* #type = npy_float, npy_double, npy_longdouble#
* #c = f,,l#
*/
@type@ logit@c@(@type@ x)
{
x /= 1 - x;
return npy_log@c@(x);
}
@type@ expit@c@(@type@ x)
{
return 1 / (1 + npy_exp@c@(-x));
}
/**end repeat**/
|