Skip to content

Commit

Permalink
added inverse gaussian cdf plus tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jul 30, 2012
1 parent ab98ca5 commit f3492a1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
27 changes: 25 additions & 2 deletions examples/undocumented/libshogun/statistics.cpp
Expand Up @@ -112,7 +112,7 @@ void test_gamma_cdf()
ASSERT(difference<=10E-15);
}

void test_normal()
void test_normal_cdf()
{
/* some tests for high precision MATLAB comparison */
float64_t difference=CStatistics::normal_cdf(1);
Expand All @@ -134,6 +134,28 @@ void test_normal()
ASSERT(difference<=10E-16);
}

void test_inverse_normal_cdf()
{
/* some tests for high precision MATLAB comparison */
float64_t difference=CStatistics::inverse_normal_cdf(0.4, 0, 1);
SG_SPRINT("inverse_normal_cdf(0.4, 0, 1)=%f\n", difference);
difference-=-0.253347103135800;
difference=CMath::abs(difference);
ASSERT(difference<=10E-16);

difference=CStatistics::inverse_normal_cdf(0.8, 0.2, 2.2);
SG_SPRINT("inverse_normal_cdf(0.8, 0.2, 2.2)=%f\n", difference);
difference-=2.051566713860412;
difference=CMath::abs(difference);
ASSERT(difference<=10E-16);

difference=CStatistics::inverse_normal_cdf(0.1, 0.1, 1.2);
SG_SPRINT("inverse_normal_cdf(0.1, 0.1, 1.2)=%f\n", difference);
difference-=-1.437861878653521;
difference=CMath::abs(difference);
ASSERT(difference<=10E-16);
}

void test_error_function()
{
/* some tests for high precision MATLAB comparison */
Expand Down Expand Up @@ -227,7 +249,8 @@ int main(int argc, char **argv)
test_incomplete_gamma();
test_gamma_cdf();
test_inverse_gamma_cdf();
test_normal();
test_normal_cdf();
test_inverse_normal_cdf();
test_error_function();
test_error_function_complement();

Expand Down
6 changes: 6 additions & 0 deletions src/shogun/mathematics/Statistics.cpp
Expand Up @@ -741,6 +741,12 @@ float64_t CStatistics::incomplete_beta(float64_t a, float64_t b, float64_t x)
return result;
}

float64_t CStatistics::inverse_normal_cdf(float64_t y0, float64_t mean,
float64_t std_dev)
{
return inverse_normal_cdf(y0)*std_dev+mean;
}

float64_t CStatistics::inverse_normal_cdf(float64_t y0)
{
float64_t expm2;
Expand Down
4 changes: 4 additions & 0 deletions src/shogun/mathematics/Statistics.h
Expand Up @@ -157,6 +157,10 @@ class CStatistics: public CSGObject
*/
static float64_t inverse_normal_cdf(float64_t y0);

/** same as other version, but with custom mean and variance */
static float64_t inverse_normal_cdf(float64_t y0, float64_t mean,
float64_t std_dev);

/** @return natural logarithm of the gamma function of input */
static inline float64_t lgamma(float64_t x)
{
Expand Down

0 comments on commit f3492a1

Please sign in to comment.