#include <learning/real.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. More... | |
| real | SmoothMaxPNorm (real f1, real f2, real p) |
| Approximate max (f1,f2) via a power function. More... | |
| 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) More... | |
| 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) |
| int ArgMax | ( | int | n, |
| real * | x | ||
| ) |
| int ArgMin | ( | int | n, |
| real * | x | ||
| ) |
Definition at line 189 of file MathFunctions.cpp.
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.
|
inline |
Definition at line 30 of file MathFunctions.h.
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.
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.
Definition at line 49 of file MathFunctions.cpp.
Definition at line 63 of file MathFunctions.cpp.
Definition at line 179 of file MathFunctions.cpp.
Definition at line 209 of file MathFunctions.cpp.