more ai generated doc with human review
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
/*! \file pimathbase.h
|
||||
* \ingroup Math
|
||||
* \~\brief
|
||||
* \~english Basic mathematical functions and defines
|
||||
* \~russian Базовые математические функции и дефайны
|
||||
*/
|
||||
//! \addtogroup Math
|
||||
//! \{
|
||||
//! \file pimathbase.h
|
||||
//! \brief
|
||||
//! \~english Basic mathematical functions and defines
|
||||
//! \~russian Базовые математические функции и дефайны
|
||||
//! \details
|
||||
//! \~english Common mathematical constants, conversion functions and utility functions
|
||||
//! \~russian Общие математические константы, функции преобразования и утилиты
|
||||
//! \}
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Basic mathematical functions and defines
|
||||
@@ -114,11 +118,29 @@ inline double sinc(const double & v) {
|
||||
return sin(t) / t;
|
||||
}
|
||||
|
||||
//! Bessel function of the first kind of order 0
|
||||
//! \~english Bessel function J0(x)
|
||||
//! \~russian Функция Бесселя первого рода порядка 0
|
||||
PIP_EXPORT double piJ0(const double & v);
|
||||
//! Bessel function of the first kind of order 1
|
||||
//! \~english Bessel function J1(x)
|
||||
//! \~russian Функция Бесселя первого рода порядка 1
|
||||
PIP_EXPORT double piJ1(const double & v);
|
||||
//! Bessel function of the first kind of order n
|
||||
//! \~english Bessel function Jn(n, x)
|
||||
//! \~russian Функция Бесселя первого рода порядка n
|
||||
PIP_EXPORT double piJn(int n, const double & v);
|
||||
//! Bessel function of the second kind of order 0
|
||||
//! \~english Bessel function Y0(x)
|
||||
//! \~russian Функция Бесселя второго рода порядка 0
|
||||
PIP_EXPORT double piY0(const double & v);
|
||||
//! Bessel function of the second kind of order 1
|
||||
//! \~english Bessel function Y1(x)
|
||||
//! \~russian Функция Бесселя второго рода порядка 1
|
||||
PIP_EXPORT double piY1(const double & v);
|
||||
//! Bessel function of the second kind of order n
|
||||
//! \~english Bessel function Yn(n, x)
|
||||
//! \~russian Функция Бесселя второго рода порядка n
|
||||
PIP_EXPORT double piYn(int n, const double & v);
|
||||
|
||||
// clang-format off
|
||||
@@ -129,24 +151,45 @@ inline constexpr float toDeg(float rad) {return rad * M_180_PI;}
|
||||
inline constexpr double toDeg(double rad) {return rad * M_180_PI;}
|
||||
inline constexpr ldouble toDeg(ldouble rad) {return rad * M_180_PI;}
|
||||
// clang-format on
|
||||
|
||||
//! Square of a value
|
||||
//! \~english Returns the square of value v (v * v)
|
||||
//! \~russian Возвращает квадрат значения v (v * v)
|
||||
template<typename T>
|
||||
inline constexpr T sqr(const T & v) {
|
||||
return v * v;
|
||||
}
|
||||
|
||||
//! Convert linear value to decibels
|
||||
//! \~english Convert linear value to decibels: 10 * log10(val)
|
||||
//! \~russian Преобразовать линейное значение в децибелы: 10 * log10(val)
|
||||
template<typename T>
|
||||
inline constexpr T toDb(T val) {
|
||||
return T(10.) * std::log10(val);
|
||||
}
|
||||
|
||||
//! Convert decibels to linear value
|
||||
//! \~english Convert decibels to linear value: 10^(val/10)
|
||||
//! \~russian Преобразовать децибелы в линейное значение: 10^(val/10)
|
||||
template<typename T>
|
||||
inline constexpr T fromDb(T val) {
|
||||
return std::pow(T(10.), val / T(10.));
|
||||
}
|
||||
|
||||
// [-1 ; 1]
|
||||
//! Generate random double in range [-1, 1]
|
||||
//! \~english Returns random double in range [-1, 1]
|
||||
//! \~russian Генерирует случайное число double в диапазоне [-1, 1]
|
||||
PIP_EXPORT double randomd();
|
||||
// [-1 ; 1] normal
|
||||
//! Generate random double with normal (Gaussian) distribution
|
||||
//! \~english Returns random double with normal distribution, mean=dv, stddev=sv
|
||||
//! \~russian Генерирует случайное число double с нормальным распределением, среднее=dv, стандартное отклонение=sv
|
||||
PIP_EXPORT double randomn(double dv = 0., double sv = 1.);
|
||||
|
||||
//! Absolute value of vector elements
|
||||
//! \~english Returns vector with absolute values of each element
|
||||
//! \~russian Возвращает вектор с абсолютными значениями каждого элемента
|
||||
template<typename T>
|
||||
inline PIVector<T> piAbs(const PIVector<T> & v) {
|
||||
PIVector<T> result;
|
||||
@@ -157,6 +200,9 @@ inline PIVector<T> piAbs(const PIVector<T> & v) {
|
||||
}
|
||||
|
||||
|
||||
//! Normalize angle to [0, 360) range (in-place)
|
||||
//! \~english Normalizes angle to range [0, 360) degrees
|
||||
//! \~russian Нормализует угол в диапазон [0, 360) градусов (на месте)
|
||||
template<typename T>
|
||||
void normalizeAngleDeg360(T & a) {
|
||||
while (a < 0.)
|
||||
@@ -164,6 +210,9 @@ void normalizeAngleDeg360(T & a) {
|
||||
while (a > 360.)
|
||||
a -= 360.;
|
||||
}
|
||||
//! Normalize angle to [0, 360) range
|
||||
//! \~english Returns angle normalized to range [0, 360) degrees
|
||||
//! \~russian Возвращает угол нормализованный в диапазон [0, 360) градусов
|
||||
template<typename T>
|
||||
double normalizedAngleDeg360(T a) {
|
||||
normalizeAngleDeg360(a);
|
||||
@@ -171,6 +220,9 @@ double normalizedAngleDeg360(T a) {
|
||||
}
|
||||
|
||||
|
||||
//! Normalize angle to (-180, 180] range (in-place)
|
||||
//! \~english Normalizes angle to range (-180, 180] degrees
|
||||
//! \~russian Нормализует угол в диапазон (-180, 180] градусов (на месте)
|
||||
template<typename T>
|
||||
void normalizeAngleDeg180(T & a) {
|
||||
while (a < -180.)
|
||||
@@ -178,6 +230,9 @@ void normalizeAngleDeg180(T & a) {
|
||||
while (a > 180.)
|
||||
a -= 360.;
|
||||
}
|
||||
//! Normalize angle to (-180, 180] range
|
||||
//! \~english Returns angle normalized to range (-180, 180] degrees
|
||||
//! \~russian Возвращает угол нормализованный в диапазон (-180, 180] градусов
|
||||
template<typename T>
|
||||
double normalizedAngleDeg180(T a) {
|
||||
normalizeAngleDeg180(a);
|
||||
@@ -185,6 +240,13 @@ double normalizedAngleDeg180(T a) {
|
||||
}
|
||||
|
||||
|
||||
//! Ordinary Least Squares linear regression
|
||||
//! \~english Calculates linear regression coefficients using OLS method
|
||||
//! \~russian Вычисляет коэффициенты линейной регрессии методом наименьших квадратов
|
||||
//! \param input Vector of (x, y) pairs
|
||||
//! \param out_a Output pointer for slope coefficient (a), can be nullptr
|
||||
//! \param out_b Output pointer for intercept coefficient (b), can be nullptr
|
||||
//! \return true on success
|
||||
template<typename T>
|
||||
bool OLS_Linear(const PIVector<PIPair<T, T>> & input, T * out_a, T * out_b) {
|
||||
static_assert(std::is_arithmetic<T>::value, "Type must be arithmetic");
|
||||
@@ -207,6 +269,14 @@ bool OLS_Linear(const PIVector<PIPair<T, T>> & input, T * out_a, T * out_b) {
|
||||
}
|
||||
|
||||
|
||||
//! Weighted Least Squares linear regression
|
||||
//! \~english Calculates linear regression coefficients using WLS method
|
||||
//! \~russian Вычисляет коэффициенты линейной регрессии методом взвешенных наименьших квадратов
|
||||
//! \param input Vector of (x, y) pairs
|
||||
//! \param weights Vector of weights for each point
|
||||
//! \param out_a Output pointer for slope coefficient (a), can be nullptr
|
||||
//! \param out_b Output pointer for intercept coefficient (b), can be nullptr
|
||||
//! \return true on success
|
||||
template<typename T>
|
||||
bool WLS_Linear(const PIVector<PIPair<T, T>> & input, const PIVector<T> & weights, T * out_a, T * out_b) {
|
||||
static_assert(std::is_arithmetic<T>::value, "Type must be arithmetic");
|
||||
|
||||
Reference in New Issue
Block a user