Skip to content

Instantly share code, notes, and snippets.

View tschnz's full-sized avatar

Jens W. Schindel tschnz

View GitHub Profile
@tschnz
tschnz / 1d_gauss.h
Created December 14, 2022 17:39
Create centered & normalized 1D gaussian kernel aka normal distribution function aka probability density function
template <typename T>
T norm_pdf(T x, T mu, T sigma)
{
static const T inv_sqrt_2pi = static_cast<T>(0.3989422804014327); // Precomputed 1/sqrt(2*PI) to avoid sqrt()
T a = (x - mu) / sigma;
return inv_sqrt_2pi / sigma * std::exp(-T(0.5) * a * a);
}
template <typename T>