Skip to content

Commit

Permalink
added gamma cdf and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jun 7, 2012
1 parent 4f3c76e commit cdc59d5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/shogun/mathematics/Statistics.cpp
Expand Up @@ -62,7 +62,7 @@ float64_t CStatistics::confidence_intervals_mean(SGVector<float64_t> values,
int32_t deg=values.vlen-1;

/* compute absolute value of t-value */
float64_t t=CMath::abs(inverse_student_t_distribution(deg, alpha));
float64_t t=CMath::abs(inverse_student_t(deg, alpha));

/* values for calculating confidence interval */
float64_t std_dev=std_deviation(values);
Expand All @@ -76,7 +76,7 @@ float64_t CStatistics::confidence_intervals_mean(SGVector<float64_t> values,
return mean;
}

float64_t CStatistics::inverse_student_t_distribution(int32_t k, float64_t p)
float64_t CStatistics::inverse_student_t(int32_t k, float64_t p)
{
float64_t t;
float64_t rk;
Expand All @@ -87,7 +87,7 @@ float64_t CStatistics::inverse_student_t_distribution(int32_t k, float64_t p)
if (!(k>0 && greater(p, 0)) && less(p, 1))
{
SG_SERROR("CStatistics::inverse_student_t_distribution(): "
"Domain error in InvStudentTDistribution\n");
"Domain error\n");
}
rk=k;
if (greater(p, 0.25) && less(p, 0.75))
Expand Down Expand Up @@ -159,7 +159,7 @@ float64_t CStatistics::inverse_incomplete_beta(float64_t a, float64_t b,
if (!(greater_equal(y, 0) && less_equal(y, 1)))
{
SG_SERROR("CStatistics::inverse_incomplete_beta(): "
"Domain error in InvIncompleteBeta\n");
"Domain error\n");
}

/*
Expand Down Expand Up @@ -599,13 +599,13 @@ float64_t CStatistics::incomplete_beta(float64_t a, float64_t b, float64_t x)
if (!(greater(a, 0) && greater(b, 0)))
{
SG_SERROR("CStatistics::incomplete_beta(): "
"Domain error in IncompleteBeta\n");
"Domain error\n");
}

if (!(greater_equal(x, 0) && less_equal(x, 1)))
{
SG_SERROR("CStatistics::incomplete_beta(): "
"Domain error in IncompleteBeta\n");
"Domain error\n");
}

if (equal(x, 0))
Expand Down Expand Up @@ -1215,3 +1215,9 @@ float64_t CStatistics::incomplete_gamma_completed(float64_t a, float64_t x)
result=ans*ax;
return result;
}

float64_t CStatistics::gamma_cdf(float64_t x, float64_t a, float64_t b)
{
/* definition of wikipedia: incomplete gamma devised by true gamma */
return incomplete_gamma(a,x/b);
}
13 changes: 11 additions & 2 deletions src/shogun/mathematics/Statistics.h
Expand Up @@ -77,7 +77,7 @@ class CStatistics: public CSGObject
*
* Taken from ALGOLIB under gpl2+
*/
static float64_t inverse_student_t_distribution(int32_t k, float64_t p);
static float64_t inverse_student_t(int32_t k, float64_t p);

/** Inverse of imcomplete beta integral
*
Expand Down Expand Up @@ -184,7 +184,16 @@ class CStatistics: public CSGObject
*/
static float64_t incomplete_gamma_completed(float64_t a, float64_t x);

protected:
/** Evaluates the CDF of the gamma distribution with given parameters a, b
* at x. Based on Wikipedia definition and ALGOLIB routines.
*
* @param x position to evaluate
* @param a shape parameter
* @param b scale parameter
*/
static float64_t gamma_cdf(float64_t x, float64_t a, float64_t b);

protected:
/** Power series for incomplete beta integral.
* Use when b*x is small and x not too close to 1.
*
Expand Down

0 comments on commit cdc59d5

Please sign in to comment.