5 #ifndef BPP_NUMERIC_TRANSFORMEDPARAMETER_H 6 #define BPP_NUMERIC_TRANSFORMEDPARAMETER_H 99 RTransformedParameter(
const std::string& name,
double value,
double bound = 0,
bool positive =
true,
double scale = 1) :
113 if (positive_ ? value <= bound_ : value >= bound_)
throw ConstraintException(
"RTransformedParameter::setValue",
this, value);
114 if (positive_ & (value < 1 + bound_))
setValue(log(scale_ * (value - bound_)));
115 if (positive_ & (value >= 1 + bound_))
setValue(scale_ * (value - 1. - bound_));
116 if (!positive_ & (value > -1 + bound_))
setValue(log(-scale_ * (value - bound_)));
117 if (!positive_ & (value <= -1 + bound_))
setValue(-scale_ * (value - 1. - bound_));
124 if (x < 0)
return exp(x) / scale_ + bound_;
125 else return x / scale_ + 1. + bound_;
126 else if (x < 0)
return -exp(-x) / scale_ + bound_;
127 else return -x / scale_ - 1. + bound_;
134 if (x < 0)
return exp(x) / scale_;
135 else return 1. / scale_;
136 else if (x < 0)
return exp(-x) / scale_;
137 else return -1. / scale_;
144 if (x < 0)
return exp(x) / scale_;
146 else if (x < 0)
return -exp(-x) / scale_;
186 IntervalTransformedParameter(
const std::string& name,
double value,
double lowerBound = 0,
double upperBound = 1,
double scale = 1,
bool hyper =
true) :
188 scale * atanh(2. * (value - lowerBound) / (upperBound - lowerBound) - 1.) :
191 lowerBound_(lowerBound),
192 upperBound_(upperBound),
202 if (value <= lowerBound_ || value >= upperBound_)
throw ConstraintException(
"IntervalTransformedParameter::setValue",
this, value);
204 scale_ * atanh(2. * (value - lowerBound_) / (upperBound_ - lowerBound_) - 1.) :
212 (tanh(x / scale_) + 1.) * (upperBound_ - lowerBound_) / 2. + lowerBound_ :
222 1. / (std::pow(cosh(x / scale_), 2)) * (upperBound_ - lowerBound_) / (2. * scale_) :
223 (upperBound_ - lowerBound_) / (
NumConstants::PI() * scale_ * (std::pow(x / scale_, 2) + 1.));
230 -1. / (std::pow(cosh(x / scale_), 2)) * tanh(x / scale_) * (upperBound_ - lowerBound_) / (scale_ * scale_) :
231 -2. * x * (upperBound_ - lowerBound_) / (
NumConstants::PI() * std::pow(scale_, 3) * std::pow((std::pow(x / scale_, 2) + 1.), 2));
268 #endif // BPP_NUMERIC_TRANSFORMEDPARAMETER_H
this static class contains several useful constant values.
This class is designed to facilitate the manipulation of parameters.
virtual void setValue(double value)
Set the value of this parameter.
virtual double getValue() const
Get the value of this parameter.
Exception thrown when a value do not match a given constraint.