FIMS  v0.8.0
Loading...
Searching...
No Matches
fims_math.hpp File Reference

A collection of mathematical functions used in FIMS. More...

#include <cmath>
#include <random>
#include <sstream>
#include "../interface/interface.hpp"
#include "fims_vector.hpp"

Go to the source code of this file.

Functions

template<class Type >
const Type fims_math::logistic (const Type &inflection_point, const Type &slope, const Type &x)
 The general logistic function.
 
template<class Type >
const Type fims_math::logit (const Type &a, const Type &b, const Type &x)
 A logit function for bounding of parameters.
 
template<class Type >
const Type fims_math::inv_logit (const Type &a, const Type &b, const Type &logit_x)
 An inverse logit function for bounding of parameters.
 
template<class Type >
const Type fims_math::double_logistic (const Type &inflection_point_asc, const Type &slope_asc, const Type &inflection_point_desc, const Type &slope_desc, const Type &x)
 The general double logistic function.
 
template<class Type >
const Type fims_math::ad_fabs (const Type &x, Type C=1e-5)
 
template<typename Type >
const Type fims_math::ad_min (const Type &a, const Type &b, Type C=1e-5)
 
template<typename Type >
const Type fims_math::ad_max (const Type &a, const Type &b, Type C=1e-5)
 
template<class T >
T fims_math::sum (const std::vector< T > &v)
 
template<class T >
T fims_math::sum (const fims::Vector< T > &v)
 

Detailed Description

A collection of mathematical functions used in FIMS.

Function Documentation

◆ ad_fabs()

template<class Type >
const Type fims_math::ad_fabs ( const Type x,
Type  C = 1e-5 
)

Used when x could evaluate to zero, which will result in a NaN for derivative values.

Evaluates:

\( (x^2+C)^.5 \)

Parameters
xvalue to keep positive
Cdefault = 1e-5
Returns

◆ ad_max()

template<typename Type >
const Type fims_math::ad_max ( const Type a,
const Type b,
Type  C = 1e-5 
)
inline

Returns the maximum between a and b in a continuous manner using:

(a + b + fims_math::ad_fabs(a - b)) *.5; Reference: fims_math::ad_fabs() This is an approximation with minimal error.

Parameters
a
b
Cdefault = 1e-5
Returns

◆ ad_min()

template<typename Type >
const Type fims_math::ad_min ( const Type a,
const Type b,
Type  C = 1e-5 
)
inline

Returns the minimum between a and b in a continuous manner using:

(a + b - fims_math::ad_fabs(a - b))*.5; Reference: fims_math::ad_fabs()

This is an approximation with minimal error.

Parameters
a
b
Cdefault = 1e-5
Returns

◆ double_logistic()

template<class Type >
const Type fims_math::double_logistic ( const Type inflection_point_asc,
const Type slope_asc,
const Type inflection_point_desc,
const Type slope_desc,
const Type x 
)
inline

The general double logistic function.

\( \frac{1.0}{ 1.0 + exp(-1.0 * slope_{asc} (x - inflection_point_{asc}))} \left(1-\frac{1.0}{ 1.0 + exp(-1.0 * slope_{desc} (x - inflection_point_{desc}))} \right)\)

Parameters
inflection_point_ascthe inflection point of the ascending limb of the double logistic function
slope_ascthe slope of the ascending limb of the double logistic function
inflection_point_descthe inflection point of the descending limb of the double logistic function, where inflection_point_desc > inflection_point_asc
slope_descthe slope of the descending limb of the double logistic function
xthe index the logistic function should be evaluated at
Returns

◆ inv_logit()

template<class Type >
const Type fims_math::inv_logit ( const Type a,
const Type b,
const Type logit_x 
)
inline

An inverse logit function for bounding of parameters.

\( a+\frac{b-a}{1+\mathrm{exp}(-\mathrm{logit}(x))}\)

Parameters
alower bound
bupper bound
logit_xthe parameter in real space
Returns
the parameter in bounded space

◆ logistic()

template<class Type >
const Type fims_math::logistic ( const Type inflection_point,
const Type slope,
const Type x 
)
inline

The general logistic function.

The logistic function can range from zero to one or one to zero, depending on the slope parameter, but it is not normalized to force values to reach those ranges.

\( \frac{1.0}{ 1.0 + exp(-1.0 * slope (x - inflection_point))} \)

Parameters
inflection_pointthe inflection point of the logistic function
slopethe slope of the logistic function. A positive slope results in an ascending logistic curve (0 to 1), while a negative slope results in a descending logistic curve (1 to 0).
xthe index the logistic function should be evaluated at
Returns

◆ logit()

template<class Type >
const Type fims_math::logit ( const Type a,
const Type b,
const Type x 
)
inline

A logit function for bounding of parameters.

\( -\mathrm{log}(b-x) + \mathrm{log}(x-a) \)

Parameters
alower bound
bupper bound
xthe parameter in bounded space
Returns
the parameter in real space

◆ sum() [1/2]

template<class T >
T fims_math::sum ( const fims::Vector< T > &  v)

Sum elements of a vector

Parameters
vA vector of constants.
Returns
A single numeric value.

◆ sum() [2/2]

template<class T >
T fims_math::sum ( const std::vector< T > &  v)

Sum elements of a vector

Parameters
vA vector of constants.
Returns
A single numeric value.