ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
Math.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4
5#include "utils/Types.hpp"
6#include "utils/Macros.hpp"
7
8#define APPROX_THRESHOLD 0.01
9
11namespace ppforest2::math {
20 template<typename A, typename B, typename T> inline bool is_approx(A a, B b, T threshold) {
21 return fabs(a - b) < threshold;
22 }
23
25 template<typename A, typename B> inline bool is_approx(A a, B b) {
26 return is_approx(a, b, APPROX_THRESHOLD);
27 }
28
32 template<typename A, typename B> inline bool is_module_approx(A a, B b) {
33 return is_approx(fabs(a), fabs(b));
34 }
35
43 template<typename T> bool collinear(types::Vector<T> const& a, types::Vector<T> const& b) {
44 return is_module_approx(a.dot(b) / (a.norm() * b.norm()), 1.0);
45 }
46}
#define APPROX_THRESHOLD
Definition Math.hpp:8
Numeric comparison utilities.
Definition Math.hpp:11
bool collinear(types::Vector< T > const &a, types::Vector< T > const &b)
Check whether two vectors are collinear (parallel or anti-parallel).
Definition Math.hpp:43
bool is_module_approx(A a, B b)
Check whether the absolute values of two scalars are approximately equal.
Definition Math.hpp:32
bool is_approx(A a, B b, T threshold)
Check whether two scalars are approximately equal.
Definition Math.hpp:20
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
Generic dynamic-size column vector.
Definition Types.hpp:35