|
| 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.
|
| |
Numeric comparison utilities.
| 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
-
| p | Proportion in (0, 1]. |
| total | Total number of items (>= 1). |
- Returns
- Count in [1, total].