bpp-core3  3.0.0
ConstantDistribution.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 "ConstantDistribution.h"
6 
7 using namespace bpp;
8 
9 #include <iostream>
10 
11 using namespace std;
12 
13 /******************************************************************************/
14 
16  AbstractDiscreteDistribution(1, "Constant."),
17  value_(value)
18 {
19  addParameter_(new Parameter("Constant.value", value));
20  distribution_[value_] = 1; // One single class with probability 1.
21 }
22 
25  value_(cd.value_)
26 {}
27 
29 {
31  value_ = cd.value_;
32 
33  return *this;
34 }
35 
36 /******************************************************************************/
37 
39 {
41 
42  value_ = getParameterValue("value");
43  distribution_.clear();
44  distribution_[value_] = 1; // One single class of rate 1 with probability 1.
45 }
46 
47 /******************************************************************************/
48 
50 {
51  if (getNumberOfParameters() == 0)
52  return;
53 
54  const IntervalConstraint* pi = dynamic_cast<const IntervalConstraint*>(&c);
55  if (!pi)
56  throw Exception("ConstantDistribution::restrictToConstraint: Non-interval exception");
57 
58  if (!pi->isCorrect(getParameterValue("value")))
59  throw ConstraintException("Impossible to restrict to Constraint", &getParameter_("value"), getParameterValue("value"));
60 
62 
64 }
virtual void restrictToConstraint(const ConstraintInterface &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
ConstantDistribution & operator=(const ConstantDistribution &)
Partial implementation of the DiscreteDistribution interface.
An interval, either bounded or not, which can also have infinite bounds.
Definition: Constraints.h:101
The constraint interface.
Definition: Constraints.h:28
STL namespace.
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:97
void addParameter_(Parameter *parameter)
virtual void setConstraint(std::shared_ptr< ConstraintInterface > constraint)
Set a constraint to this parameter.
Definition: Parameter.cpp:76
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)
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
std::map< double, double, Order > distribution_
ConstantDistribution(double value)
Builds a new ConstantDistribution object from a value.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
Definition: Exceptions.h:20
Constant discrete distribution.
void restrictToConstraint(const ConstraintInterface &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
Exception thrown when a value do not match a given constraint.
Parameter & getParameter_(const std::string &name)
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
size_t getNumberOfParameters() const override
Get the number of parameters.
virtual bool isCorrect(double value) const override
Tell if a given value is correct.
Definition: Constraints.h:189