TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
MathFunctions.h File Reference
#include <learning/real.h>
Include dependency graph for MathFunctions.h:

Go to the source code of this file.

Functions

int ArgMin (int n, real *x)
int ArgMax (int n, real *x)
real SmoothMaxGamma (real f1, real f2, real lambda, real c)
 Approximate max (f1,f2) via a gamma function.
real SmoothMaxPNorm (real f1, real f2, real p)
 Approximate max (f1,f2) via a power function.
void SoftMax (int n, real *Q, real *p, real beta)
void SoftMin (int n, real *Q, real *p, real beta)
void Normalise (real *src, real *dst, int n_elements)
 Normalise a vector to a destination vector (low level)
real EuclideanNorm (real *a, real *b, int n)
real SquareNorm (real *a, real *b, int n)
real LNorm (real *a, real *b, int n, real p)
real Sum (real *a, int n)
template<class T>
const T sign (const T &x)

Function Documentation

◆ ArgMax()

int ArgMax ( int n,
real * x )
extern

Definition at line 36 of file MathFunctions.cpp.

Here is the call graph for this function:

◆ ArgMin()

int ArgMin ( int n,
real * x )
extern

Definition at line 24 of file MathFunctions.cpp.

Here is the call graph for this function:

◆ EuclideanNorm()

real EuclideanNorm ( real * a,
real * b,
int n )
extern

Definition at line 189 of file MathFunctions.cpp.

◆ LNorm()

real LNorm ( real * a,
real * b,
int n,
real p )
extern

Definition at line 199 of file MathFunctions.cpp.

◆ Normalise()

void Normalise ( real * src,
real * dst,
int n_elements )
extern

Normalise a vector to a destination vector (low level)

src is the source vector. dst is the destination vector. n_elements is the number of elements. As pointers are raw, make sure n_elements is correct. It is safe for src and dst to point at the same vector.

Definition at line 160 of file MathFunctions.cpp.

◆ sign()

template<class T>
const T sign ( const T & x)
inline

Definition at line 30 of file MathFunctions.h.

◆ SmoothMaxGamma()

real SmoothMaxGamma ( real f1,
real f2,
real lambda,
real c )
extern

Approximate max (f1,f2) via a gamma function.

We have:

\[ f(x) = \max \{f_1(x), f_2(x)\} = f_1(x) + \max \{0, f_2(x) - f_1(x)\}. \]

We can then approximate the second term with

\[ \max \{0, f_2(x) - f_1(x)\} = \lim_{c \rightarrow \infty} \gamma(f_2(x)-f_1(x), \lambda, c), \]

where \(\lambda \in [0,1], \quad c>0\). The function has the form

\[ \gamma(t,\lambda,c) = \begin{cases} t - \frac{(1-\lambda)^2}{2c} & \textrm{if}~ \frac{1-\lambda}{c} \leq t,\\ \lambda t - \frac{c}{2} t^2 & \textrm{if}~ -\frac{\lambda}{c} \leq t \leq \frac{1-\lambda}{c},\\ -\frac{\lambda^2}{2c} & \text{if}~ t \leq -\frac{\lambda}{c}. \end{cases} \]

The error in the positive region is \((1-\lambda)^2/2c\) and in the negative region it is \(\lambda^2/2c\). The transition region width is \(1/c\).

The advantage of this function is that it is continuously differentiable. Its derivative is

\[ \frac{\partial \gamma(t,\lambda,c)}{\partial t} = \begin{cases} 1 & \textrm{if}~ \frac{1-\lambda}{c} \leq t,\\ \lambda - c t & \textrm{if}~ -\frac{\lambda}{c} \leq t \leq \frac{1-\lambda}{c},\\ 0 & \text{if}~ t \leq -\frac{\lambda}{c}. \end{cases} \]

The error

Definition at line 117 of file MathFunctions.cpp.

◆ SmoothMaxPNorm()

real SmoothMaxPNorm ( real f1,
real f2,
real p )
extern

Approximate max (f1,f2) via a power function.

We have:

\[ f(x) = \max \{f_1(x), f_2(x)\} = \lim_{p \rightarrow \infty} (f_1(x)^p, f_2(x)^p)^{1/p}. \]

The advantage of this function is that it is differentiable. Unlike SmoothMaxGamma, the error is not fixed, but it is proportional to the ratio between.

Definition at line 147 of file MathFunctions.cpp.

◆ SoftMax()

void SoftMax ( int n,
real * Q,
real * p,
real beta )
extern

Definition at line 49 of file MathFunctions.cpp.

◆ SoftMin()

void SoftMin ( int n,
real * Q,
real * p,
real beta )
extern

Definition at line 63 of file MathFunctions.cpp.

◆ SquareNorm()

real SquareNorm ( real * a,
real * b,
int n )
extern

Definition at line 179 of file MathFunctions.cpp.

◆ Sum()

real Sum ( real * a,
int n )
extern

Definition at line 209 of file MathFunctions.cpp.