Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #705 from karlnapf/master
documentation updates for CStatistics class
  • Loading branch information
karlnapf committed Aug 11, 2012
2 parents a0e2bb9 + 913e17b commit ae5d490
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 115 deletions.
2 changes: 1 addition & 1 deletion src/shogun/evaluation/GradientCriterion.h
Expand Up @@ -18,7 +18,7 @@ namespace shogun
class CGradientCriterion: public CEvaluation
{

/* @brief CGradientCriterion
/** @brief CGradientCriterion
*
* Simple class which specifies the direction
* of gradient search. Does not provide any
Expand Down
10 changes: 5 additions & 5 deletions src/shogun/evaluation/GradientResult.h
Expand Up @@ -53,19 +53,19 @@ class CGradientResult: public CEvaluationResult
return GRADIENTEVALUATION_RESULT;
}

/*Function value*/
/** Function value */
SGVector<float64_t> quantity;

/*Function Gradient*/
/** Function Gradient */
CMap<TParameter*, SGVector<float64_t> > gradient;

/*Which objects do the gradient parameters belong to?*/
/** Which objects do the gradient parameters belong to? */
CMap<TParameter*, CSGObject*> parameter_dictionary;

/*Total number of variables represented by the gradient*/
/** Total number of variables represented by the gradient */
index_t total_variables;

/** Returns the function value
/** Prints the function value
* and gradient contained in the object.
*/
void print_result()
Expand Down
8 changes: 4 additions & 4 deletions src/shogun/evaluation/MachineEvaluation.h
Expand Up @@ -28,13 +28,13 @@ class CLabels;
class CSplittingStrategy;
class CEvaluation;

class CMachineEvaluation: public CSGObject
{

/* @brief Machine Evaluation is an abstract class
/** @brief Machine Evaluation is an abstract class
* that evaluates a machine according to some criterion.
*
*/
class CMachineEvaluation: public CSGObject
{


public:

Expand Down
116 changes: 45 additions & 71 deletions src/shogun/mathematics/Statistics.h
Expand Up @@ -213,68 +213,52 @@ class CStatistics: public CSGObject
*
* The function is defined by
*
*
* igamc(a,x) = 1 - igam(a,x)
*
* inf.
* -
* 1 | | -t a-1
* = ----- | e t dt.
* - | |
* | (a) -
* x
*
* \f[
* \text{incomplete\_gamma\_completed}(a,x)=1-\text{incomplete\_gamma}(a,x) =
* \frac{1}{\Gamma (a)}\int_x^\infty e^{-t} t^{a-1} dt
* \f]
*
* In this implementation both arguments must be positive.
* The integral is evaluated by either a power series or
* continued fraction expansion, depending on the relative
* values of a and x.
* values of \f$a\f$ and \f$x\f$.
*
* Taken from ALGLIB under gpl2+
*/
static float64_t incomplete_gamma_completed(float64_t a, float64_t x);

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

/** Evaluates the inverse CDF of the gamma distribution with given
* parameters a, b at x such that gamma_cdf(x,a,b)=result.
* parameters \f$a\f$, \f$b\f$ at \f$x\f$, such that result equals
* \f$\text{gamma\_cdf}(x,a,b)\f$.
*
* @param p position to evaluate
* @param a shape parameter
* @param b scale parameter
* @return x such that gamma_cdf(x,a,b)=result
* @return \f$x\f$ such that result equals \f$\text{gamma\_cdf}(x,a,b)\f$.
*/
static float64_t inverse_gamma_cdf(float64_t p, float64_t a, float64_t b);

/** Inverse of complemented imcomplete gamma integral
*
* Given p, the function finds x such that
*
* igamc( a, x ) = p.
*
* Starting with the approximate value
*
* 3
* x = a t
*
* where
*
* t = 1 - d - ndtri(p) sqrt(d)
* Given \f$p\f$, the function finds \f$x\f$ such that
*
* and
* \f$\text{inverse\_incomplete\_gamma\_completed}( a, x ) = p.\f$
*
* d = 1/9a,
* Starting with the approximate value \f$ x=a t^3\f$, where
* \f$ t = 1 - d - \text{ndtri}(p) \sqrt{d} \f$ and \f$ d = \frac{1}{9}a \f$
*
* the routine performs up to 10 Newton iterations to find the
* root of igamc(a,x) - p = 0.
* The routine performs up to 10 Newton iterations to find the
* root of \f$ \text{inverse\_incomplete\_gamma\_completed}( a, x )-p=0\f$
*
* Taken from ALGLIB under gpl2+
*/
Expand All @@ -284,20 +268,16 @@ class CStatistics: public CSGObject
/** Normal distribution function
*
* Returns the area under the Gaussian probability density
* function, integrated from minus infinity to x:
*
* x
* -
* 1 | | 2
* ndtr(x) = --------- | exp( - t /2 ) dt
* sqrt(2pi) | |
* -
* -inf.
* function, integrated from minus infinity to \f$x\f$:
*
* = ( 1 + erf(z) ) / 2
* \f[
* \text{normal\_cdf}(x)=\frac{1}{\sqrt{2\pi}} \int_{-\infty}^x
* \exp \left( -\frac{t^2}{2} \right) dt = \frac{1+\text{error\_function}(z) }{2}
* \f]
*
* where z = x/sqrt(2)/std_dev. Computation is via the functions
* erf and erfc.
* where \f$ z = \frac{x}{\sqrt{2} \sigma}\f$ and \f$ \sigma \f$ is the standard
* deviation. Computation is via the functions \f$\text{error\_function}\f$
* and \f$\text{error\_function\_completement}\f$.
*
* Taken from ALGLIB under gpl2+
* Custom variance added by Heiko Strathmann
Expand All @@ -308,51 +288,45 @@ class CStatistics: public CSGObject
*
* The integral is
*
* x
* -
* 2 | | 2
* erf(x) = -------- | exp( - t ) dt.
* sqrt(pi) | |
* -
* 0
* \f[
* \text{error\_function}(x)=
* \frac{2}{\sqrt{pi}}\int_0^x \exp (-t^2) dt
* \f]
*
* For 0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwise
* erf(x) = 1 - erfc(x).
* For \f$0 \leq |x| < 1, \text{error\_function}(x) = x \frac{P4(x^2)}{Q5(x^2)}\f$
* otherwise
* \f$\text{error\_function}(x) = 1 - \text{error\_function\_complement}(x)\f$.
*
* Taken from ALGLIB under gpl2+
*/
static float64_t error_function(float64_t x);

/** Complementary error function
*
* 1 - erf(x) =
*
* inf.
* -
* 2 | | 2
* erfc(x) = -------- | exp( - t ) dt
* sqrt(pi) | |
* -
* x
*
* \f[
* 1 - \text{error\_function}(x) =
* \text{error\_function\_complement}(x)=
* \frac{2}{\sqrt{\pi}}\int_x^\infty \exp\left(-t^2 \right)dt
* \f]
*
* For small x, erfc(x) = 1 - erf(x); otherwise rational
* For small \f$x\f$, \f$\text{error\_function\_complement}(x) =
* 1 - \text{error\_function}(x)\f$; otherwise rational
* approximations are computed.
*
* Taken from ALGLIB under gpl2+
*/
static float64_t error_function_complement(float64_t x);

/// returns the mutual information of p which is given in logspace
/// where p,q are given in logspace
/** @return mutual information of \f$p\f$ which is given in logspace
* where \f$p,q\f$ are given in logspace */
static float64_t mutual_info(float64_t* p1, float64_t* p2, int32_t len);

/// returns the relative entropy H(P||Q),
/// where p,q are given in logspace
/** @return relative entropy \f$H(P||Q)\f$
* where \f$p,q\f$ are given in logspace */
static float64_t relative_entropy(
float64_t* p, float64_t* q, int32_t len);

/// returns entropy of p which is given in logspace
/** @return entropy of \f$p\f$ which is given in logspace */
static float64_t entropy(float64_t* p, int32_t len);

/** fisher's test for multiple 2x3 tables
Expand All @@ -379,7 +353,7 @@ class CStatistics: public CSGObject

protected:
/** Power series for incomplete beta integral.
* Use when b*x is small and x not too close to 1.
* Use when \f$bx\f$ is small and \f$x\f$ not too close to \f$1\f$.
*
* Taken from ALGLIB under gpl2+
*/
Expand Down
18 changes: 9 additions & 9 deletions src/shogun/modelselection/GradientModelSelection.h
Expand Up @@ -56,26 +56,26 @@ class CGradientModelSelection: public CModelSelection
*/
inline virtual const char* get_name() const {return "GradientModelSelection";}

/* Set the maximum evaluations used in the optimization algorithm
/** Set the maximum evaluations used in the optimization algorithm
*
* @param m max evaluations
*/
void set_max_evaluations(int m) {m_max_evaluations = m;}

/* Get the maximum evaluations used in the optimization algorithm
/** Get the maximum evaluations used in the optimization algorithm
*
* @return number of maximum evaluations
*/
int get_max_evaluations() {return m_max_evaluations;}

/* Set the minimum level of gradient tolerance used in the
/** Set the minimum level of gradient tolerance used in the
* optimization algorithm
*
* @param t tolerance level
*/
void set_grad_tolerance(float64_t t) {m_grad_tolerance = t;}

/* Get the minimum level of gradient tolerance used in the
/** Get the minimum level of gradient tolerance used in the
* optimization algorithm
*
* @return tolerance level
Expand All @@ -84,7 +84,7 @@ class CGradientModelSelection: public CModelSelection

private:

/* nlopt callback function wrapper
/** nlopt callback function wrapper
*
* @param n number of parameters
*
Expand All @@ -108,21 +108,21 @@ class CGradientModelSelection: public CModelSelection

protected:

/* struct used for nlopt callback function*/
/** struct used for nlopt callback function*/
struct nlopt_package
{
shogun::CMachineEvaluation* m_machine_eval;
shogun::CParameterCombination* m_current_combination;
bool print_state;
};

/*Maximum number of evaluations used in optimization algorithm */
/** Maximum number of evaluations used in optimization algorithm */
int m_max_evaluations;

/*Gradient tolerance used in optimization algorithm */
/** Gradient tolerance used in optimization algorithm */
float64_t m_grad_tolerance;

/*Parameter combination tree*/
/** Parameter combination tree*/
CParameterCombination* m_current_combination;

};
Expand Down
8 changes: 4 additions & 4 deletions src/shogun/modelselection/ParameterCombination.h
Expand Up @@ -225,14 +225,14 @@ friend class CModelSelectionParameters;
static CDynamicObjectArray* extract_trees_with_name(
const CDynamicObjectArray* sets, const char* desired_name);

/* Gets parameter by name in current node.
/** Gets parameter by name in current node.
*
* @param name name of parameter
* @return parameter. Null if not found.
*/
TParameter* get_parameter_helper(const char* name);

/* Sets parameter by name in current node.
/** Sets parameter by name in current node.
*
* @param name name of parameter
* @param value of parameter
Expand All @@ -242,7 +242,7 @@ friend class CModelSelectionParameters;
*/
bool set_parameter_helper(const char* name, bool value, index_t index);

/* Sets parameter by name in current node.
/** Sets parameter by name in current node.
*
* @param name name of parameter
* @param value of parameter
Expand All @@ -252,7 +252,7 @@ friend class CModelSelectionParameters;
*/
bool set_parameter_helper(const char* name, int32_t value, index_t index);

/* Sets parameter by name in current node.
/** Sets parameter by name in current node.
*
* @param name name of parameter
* @param value of parameter
Expand Down

0 comments on commit ae5d490

Please sign in to comment.