imate
C++/CUDA Reference
Loading...
Searching...
No Matches
gaussian_int.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3 * SPDX-License-Identifier: BSD-3-Clause
4 * SPDX-FileType: SOURCE
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the license found in the LICENSE.txt file in the root
8 * directory of this source tree.
9 */
10
11
12// =======
13// Headers
14// =======
15
16// Before including cmath, define _USE_MATH_DEFINES. This is only required to
17// define the math constants like M_PI, etc, in win32 operating system.
18#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && \
19 !defined(__CYGWIN__)
20 #define _USE_MATH_DEFINES
21#endif
22
23#include <cmath> // erf, M_SQRT1_2
24#include "./gaussian_int.h"
25
26
27// ============
28// Gaussian Int
29// ============
30
33
34GaussianInt::GaussianInt(double mu_, double sigma_)
35{
36 this->mu = mu_;
37 this->sigma = sigma_;
38}
39
40// =====================
41// Gaussian Int function (float)
42// =====================
43
47
48float GaussianInt::function(const float lambda_) const
49{
50 float mu_ = static_cast<float>(this->mu);
51 float sigma_ = static_cast<float>(this->sigma);
52 float x = (lambda_ - mu_) / sigma_;
53
54 // C++11 and later
55 #if __cplusplus >= 201103L
56 return 0.5f * (1.0f + std::erf(x * M_SQRT1_2));
57 #else
58 return 0.5f * (1.0f + static_cast<float>(erf(x * M_SQRT1_2)));
59 #endif
60}
61
62
63// =====================
64// Gaussian Int function (double)
65// =====================
66
70
71double GaussianInt::function(const double lambda_) const
72{
73 double x = (lambda_ - this->mu) / this->sigma;
74
75 // C++11 and later
76 #if __cplusplus >= 201103L
77 return 0.5 * (1.0 + std::erf(x * M_SQRT1_2));
78 #else
79 return 0.5 * (1.0 + erf(x * M_SQRT1_2));
80 #endif
81}
82
83
84// =====================
85// Gaussian Int function (long double)
86// =====================
87
91
92long double GaussianInt::function(const long double lambda_) const
93{
94 long double mu_ = static_cast<long double>(this->mu);
95 long double sigma_ = static_cast<long double>(this->sigma);
96 long double x = (lambda_ - mu_) / sigma_;
97
98 // C++11 and later
99 #if __cplusplus >= 201103L
100 return 0.5l * (1.0l + std::erf(x * M_SQRT1_2));
101 #else
102 return 0.5l * (1.0l + static_cast<long double>(erf(x * M_SQRT1_2)));
103 #endif
104}
GaussianInt(double mu_, double sigma_)
Sets the default for the parameter mu to 0.0 and for the parameter sigma to 1.0.
virtual float function(const float lambda_) const