ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::math Namespace Reference

Numeric comparison utilities. More...

Functions

template<typename T>
bool collinear (types::Vector< T > const &a, types::Vector< T > const &b)
 Check whether two vectors are collinear (parallel or anti-parallel).
 
template<typename A, typename B>
bool is_approx (A a, B b)
 Overload using the default APPROX_THRESHOLD.
 
template<typename A, typename B, typename T>
bool is_approx (A a, B b, T threshold)
 Check whether two scalars are approximately equal.
 
template<typename A, typename B>
bool is_module_approx (A a, B b)
 Check whether the absolute values of two scalars are approximately equal.
 
int proportion_to_count (float p, unsigned int total)
 Convert a proportion of a total into a count.
 

Detailed Description

Numeric comparison utilities.

Function Documentation

◆ collinear()

template<typename T>
bool ppforest2::math::collinear ( types::Vector< T > const & a,
types::Vector< T > const & b )

Check whether two vectors are collinear (parallel or anti-parallel).

Parameters
aFirst vector.
bSecond vector (same dimension as a).
Returns
True if |cos(angle)| ≈ 1.

◆ is_approx() [1/2]

template<typename A, typename B>
bool ppforest2::math::is_approx ( A a,
B b )
inline

Overload using the default APPROX_THRESHOLD.

◆ is_approx() [2/2]

template<typename A, typename B, typename T>
bool ppforest2::math::is_approx ( A a,
B b,
T threshold )
inline

Check whether two scalars are approximately equal.

Parameters
aFirst value.
bSecond value.
thresholdMaximum allowed absolute difference.
Returns
True if |a − b| < threshold.

◆ is_module_approx()

template<typename A, typename B>
bool ppforest2::math::is_module_approx ( A a,
B b )
inline

Check whether the absolute values of two scalars are approximately equal.

◆ proportion_to_count()

int ppforest2::math::proportion_to_count ( float p,
unsigned int total )
inline

Convert a proportion of a total into a count.

Turns a feature proportion (e.g. p_vars = 0.5) into a variable-selection count, rounding half to even (banker's rounding) to match R's round(), then clamping to at least 1 so a tiny proportion still selects one item (matching R's max(1L, ...)). Shared by the CLI and the R package so both resolve identical counts for the same proportion.

Half-to-even is computed by hand rather than via std::nearbyint so the result never depends on the current floating-point rounding mode. std::floor, the subtraction, and integer parity are all mode-independent and exact for these inputs, keeping results reproducible across compilers and platforms.

Parameters
pProportion in (0, 1].
totalTotal number of items (>= 1).
Returns
Count in [1, total].