71 lines
1.4 KiB
C++
71 lines
1.4 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef K_MATH_DISTRIBUTION_VONMISES_H
|
||
#define K_MATH_DISTRIBUTION_VONMISES_H
|
||
|
||
#include <cmath>
|
||
#include <random>
|
||
|
||
#include "../Math.h"
|
||
#include "Bessel.h"
|
||
#include "LUT.h"
|
||
|
||
namespace Distribution {
|
||
|
||
/** von-mises distribution */
|
||
template <typename T> class VonMises {
|
||
|
||
private:
|
||
|
||
/** center of the distribution */
|
||
const T mu;
|
||
|
||
/** like 1.0/variance of the distribution */
|
||
T kappa;
|
||
|
||
/** pre-calcuated look-up-table */
|
||
std::vector<T> lut;
|
||
|
||
/** helper for modified bessel I_0(kappa) */
|
||
Bessel<T> bessel;
|
||
|
||
public:
|
||
|
||
/** ctor */
|
||
VonMises(const T mu, T kappa) : mu(mu), kappa(kappa) {
|
||
|
||
}
|
||
|
||
LUT<T> getLUT() const {
|
||
return LUT<T>(*this, -M_PI, +M_PI, 10000);
|
||
}
|
||
|
||
/** get probability for the given value */
|
||
T getProbability(const T _val) const {
|
||
|
||
const T val = Math::clamp((T)-M_PI, (T)+M_PI, _val);
|
||
|
||
return
|
||
std::exp(kappa * std::cos(val - mu)) /
|
||
(2 * M_PI * bessel.getModified(0, kappa));
|
||
|
||
}
|
||
|
||
void setKappa(T _kappa){
|
||
kappa = _kappa;
|
||
}
|
||
|
||
};
|
||
|
||
}
|
||
|
||
#endif // K_MATH_DISTRIBUTION_VONMISES_H
|