bpp-core3  3.0.0
GaussianDiscreteDistribution.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "../../Utils/MapTools.h"
6 #include "../NumConstants.h"
7 #include "../Random/RandomTools.h"
9 
10 using namespace bpp;
11 
12 // From the STL:
13 #include <cmath>
14 
15 using namespace std;
16 
20  AbstractDiscreteDistribution(n, "Gaussian."), mu_(mu), sigma_(sigma)
21 {
22  addParameter_(new Parameter("Gaussian.mu", mu));
23  addParameter_(new Parameter("Gaussian.sigma", sigma, Parameter::R_PLUS_STAR));
24  discretize();
25 }
26 
29  mu_(gdd.mu_),
30  sigma_(gdd.sigma_)
31 {}
32 
34 {
36  mu_ = gdd.mu_;
37  sigma_ = gdd.sigma_;
38 
39  return *this;
40 }
41 
43 
44 /******************************************************************************/
45 
47 {
49  mu_ = getParameterValue("mu");
50  sigma_ = getParameterValue("sigma");
51  discretize();
52 }
53 
54 /******************************************************************************/
55 
57 {
58  return RandomTools::qNorm(x, mu_, sigma_);
59 }
60 
62 {
63  return RandomTools::pNorm(x, mu_, sigma_);
64 }
65 
67 {
68  return -sigma_ / sqrt(2 * M_PI) * exp(-pow((a - mu_) / sigma_, 2) / 2)
70 }
static double pNorm(double z)
Normal cumulative function.
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...
Partial implementation of the DiscreteDistribution interface.
STL namespace.
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:97
void addParameter_(Parameter *parameter)
Discretized Gaussian distribution.
double getParameterValue(const std::string &name) const override
Get the value for parameter of name &#39;name&#39;.
The parameter list object.
Definition: ParameterList.h:27
virtual void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
static double qNorm(double prob)
Normal quantile function.
double pProb(double x) const
Return the cumulative quantile of the continuous version of the distribution, ie .
virtual void discretize()
Discretizes the distribution in equiprobable classes.
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
GaussianDiscreteDistribution(size_t n, double mu=0., double sigma=1.)
Build a new discretized normal distribution.
GaussianDiscreteDistribution & operator=(const GaussianDiscreteDistribution &)
double Expectation(double a) const
Return a primitive function used for the expectation of the continuous version of the distribution...
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
Definition: Parameter.h:308