bpp-core  2.2.0
bpp::Parameter Class Reference

This class is designed to facilitate the manipulation of parameters. More...

#include <Bpp/Numeric/Parameter.h>

+ Inheritance diagram for bpp::Parameter:
+ Collaboration diagram for bpp::Parameter:

Public Member Functions

 Parameter ()
 Default contructor. Creates a parameter with no name, no constraint, and a value of 0. More...
 
 Parameter (const std::string &name, double value, Constraint *constraint, bool attachConstraint, double precision=0) throw (ConstraintException)
 Build a new parameter. More...
 
 Parameter (const std::string &name, double value, const Constraint *constraint=0, double precision=0) throw (ConstraintException)
 Build a new parameter. More...
 
 Parameter (const Parameter &param)
 Copy constructor. More...
 
Parameteroperator= (const Parameter &param)
 Assignment operator. More...
 
virtual ~Parameter ()
 
Parameterclone () const
 Create a copy of this object and send a pointer to it. More...
 
virtual void setName (const std::string &name)
 Set the name of this parameter. More...
 
virtual void setValue (double value) throw (ConstraintException)
 Set the value of this parameter. More...
 
void setPrecision (double precision)
 Set the precision of this parameter. More...
 
virtual const std::string & getName () const
 Get the name of this parameter. More...
 
virtual double getValue () const
 Get the value of this parameter. More...
 
virtual double getPrecision () const
 Get the precision of this parameter. More...
 
virtual const ConstraintgetConstraint () const
 Return the constraint associated to this parameter if there is one. More...
 
virtual ConstraintgetConstraint ()
 Return the constraint associated to this parameter if there is one. More...
 
virtual bool hasConstraint () const
 Tells if this parameter has a constraint. More...
 
virtual const ConstraintremoveConstraint ()
 Remove the constraint associated to this parameter. More...
 
virtual void setConstraint (Constraint *constraint, bool attach=false)
 Set a constraint to this parameter. More...
 
virtual void addParameterListener (ParameterListener *listener, bool attachListener=true)
 Add a new listener to this parameter. More...
 
virtual void removeParameterListener (const std::string &listenerId)
 Remove all listeners with a given id from this parameter. More...
 
virtual bool hasParameterListener (const std::string &listenerId)
 Tell is there is a listener with a given id from this parameter. More...
 

Static Public Attributes

static const IntervalConstraint R_PLUS
 
static const IntervalConstraint R_PLUS_STAR
 
static const IntervalConstraint R_MINUS
 
static const IntervalConstraint R_MINUS_STAR
 
static const IntervalConstraint PROP_CONSTRAINT_IN
 
static const IntervalConstraint PROP_CONSTRAINT_EX
 

Protected Member Functions

void fireParameterNameChanged (ParameterEvent &event)
 
void fireParameterValueChanged (ParameterEvent &event)
 

Protected Attributes

std::string name_
 
double value_
 
double precision_
 
Constraintconstraint_
 
bool attach_
 
std::vector< ParameterListener * > listeners_
 
std::vector< bool > listenerAttach_
 

Detailed Description

This class is designed to facilitate the manipulation of parameters.

A parameter object contains a value stored as a double. It also contains a name and optionaly a constraint. Constraint objects allows to apply restriction on the value of the parameter, for instance positive number, or a particular interval and so on.

See also
ParameterList, Parametrizable, Constraint.

Definition at line 135 of file Parameter.h.

Constructor & Destructor Documentation

◆ Parameter() [1/4]

bpp::Parameter::Parameter ( )
inline

Default contructor. Creates a parameter with no name, no constraint, and a value of 0.

Definition at line 152 of file Parameter.h.

Referenced by clone().

◆ Parameter() [2/4]

Parameter::Parameter ( const std::string &  name,
double  value,
Constraint constraint,
bool  attachConstraint,
double  precision = 0 
)
throw (ConstraintException
)

Build a new parameter.

Parameters
nameThe parameter name.
valueThe parameter value.
constraintA pointer toward a constraint Object.
attachConstraintTell if the constraint must be attached to this parameter, or shared
precisionAn optional parameter precision (default 0) between different objects (the default behavior, for backward compatibility). If the first case, the constraint object will be destroyed when the parameter is destroyed, and duplicated when the parameter is copied.
Exceptions
ConstraintExceptionIf the parameter value does not match the contraint.

Constructors:

Definition at line 57 of file Parameter.cpp.

◆ Parameter() [3/4]

Parameter::Parameter ( const std::string &  name,
double  value,
const Constraint constraint = 0,
double  precision = 0 
)
throw (ConstraintException
)

Build a new parameter.

Parameters
nameThe parameter name.
valueThe parameter value.
constraintAn optional pointer toward a constraint Object. The constraint will be copied and attached to this instance.
precisionAn optional parameter precision (default 0)
Exceptions
ConstraintExceptionIf the parameter value does not match the contraint.

Definition at line 66 of file Parameter.cpp.

◆ Parameter() [4/4]

Parameter::Parameter ( const Parameter param)

Copy constructor.

Definition at line 75 of file Parameter.cpp.

References attach_, bpp::Constraint::clone(), constraint_, listenerAttach_, and listeners_.

◆ ~Parameter()

Parameter::~Parameter ( )
virtual

Destructor:

Definition at line 113 of file Parameter.cpp.

References attach_, constraint_, listenerAttach_, and listeners_.

Member Function Documentation

◆ addParameterListener()

virtual void bpp::Parameter::addParameterListener ( ParameterListener listener,
bool  attachListener = true 
)
inlinevirtual

Add a new listener to this parameter.

Parameters
listenerThe listener to add.
attachListenerTell if the parameter will own this listener. If so, deep copies will be made when cloning the parameter, and the listener will be destroyed upon destruction of the parameter or upon removal. Alternatively, only superficial copies will be made, and the listener will persist if the parameter is destroyed.

Definition at line 298 of file Parameter.h.

References listenerAttach_, and listeners_.

Referenced by bpp::AbstractParameterAliasable::aliasParameters().

◆ clone()

Parameter* bpp::Parameter::clone ( ) const
inlinevirtual

Create a copy of this object and send a pointer to it.

Returns
A pointer toward the copy object.

Implements bpp::Clonable.

Reimplemented in bpp::PlaceboTransformedParameter, bpp::IntervalTransformedParameter, bpp::RTransformedParameter, and bpp::TransformedParameter.

Definition at line 199 of file Parameter.h.

References Parameter().

Referenced by bpp::AbstractParameterAliasable::addParameter_(), bpp::AbstractParameterAliasable::aliasParameters(), and bpp::ParameterList::getCommonParametersWith().

◆ fireParameterNameChanged()

void bpp::Parameter::fireParameterNameChanged ( ParameterEvent event)
inlineprotected

Definition at line 320 of file Parameter.h.

References listeners_.

Referenced by setName().

◆ fireParameterValueChanged()

void bpp::Parameter::fireParameterValueChanged ( ParameterEvent event)
inlineprotected

Definition at line 325 of file Parameter.h.

References listeners_.

◆ getConstraint() [1/2]

virtual const Constraint* bpp::Parameter::getConstraint ( ) const
inlinevirtual

Return the constraint associated to this parameter if there is one.

Returns
A pointer toward the constraint, or NULL if there is no constraint.

Definition at line 255 of file Parameter.h.

References constraint_.

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::ReparametrizationFunctionWrapper::init_(), bpp::ParameterList::matchParametersValues(), bpp::ParameterList::setParametersValues(), and bpp::ParameterList::testParametersValues().

◆ getConstraint() [2/2]

virtual Constraint* bpp::Parameter::getConstraint ( )
inlinevirtual

Return the constraint associated to this parameter if there is one.

Returns
A pointer toward the constraint, or NULL if there is no constraint.

Definition at line 262 of file Parameter.h.

References constraint_.

◆ getName()

◆ getPrecision()

virtual double bpp::Parameter::getPrecision ( ) const
inlinevirtual

Get the precision of this parameter.

Returns
The precision value.

Definition at line 248 of file Parameter.h.

References precision_.

◆ getValue()

◆ hasConstraint()

virtual bool bpp::Parameter::hasConstraint ( ) const
inlinevirtual

Tells if this parameter has a constraint.

Returns
True if this parameter has a contraint.

Definition at line 269 of file Parameter.h.

References constraint_.

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::ParameterList::matchParametersValues(), bpp::ParameterList::setParametersValues(), and bpp::ParameterList::testParametersValues().

◆ hasParameterListener()

bool Parameter::hasParameterListener ( const std::string &  listenerId)
virtual

Tell is there is a listener with a given id from this parameter.

Parameters
listenerIdThe id of listener to remove.
Returns
True if at list one listener with the given id was found.

Definition at line 187 of file Parameter.cpp.

References listeners_.

◆ operator=()

Parameter & Parameter::operator= ( const Parameter param)

Assignment operator.

Definition at line 93 of file Parameter.cpp.

References attach_, bpp::Constraint::clone(), constraint_, listenerAttach_, listeners_, name_, precision_, and value_.

Referenced by bpp::AutoParameter::operator=().

◆ removeConstraint()

const Constraint * Parameter::removeConstraint ( )
virtual

Remove the constraint associated to this parameter.

Warning! The contraint objet is not deleted.

Returns
A pointer toward the formerly used contraint.

Definition at line 163 of file Parameter.cpp.

References constraint_.

Referenced by bpp::SimpleDiscreteDistribution::restrictToConstraint().

◆ removeParameterListener()

void Parameter::removeParameterListener ( const std::string &  listenerId)
virtual

Remove all listeners with a given id from this parameter.

Parameters
listenerIdThe id of listener to remove.

Definition at line 172 of file Parameter.cpp.

References listenerAttach_, and listeners_.

◆ setConstraint()

void Parameter::setConstraint ( Constraint constraint,
bool  attach = false 
)
virtual

Set a constraint to this parameter.

Parameters
constrainta pointer to the constraint (may be null)
attachsays if the constraint is attached to the Parameter (default: false).

Constraint:

Definition at line 143 of file Parameter.cpp.

References attach_, constraint_, bpp::Constraint::isCorrect(), and value_.

Referenced by bpp::ConstantDistribution::restrictToConstraint(), bpp::TruncatedExponentialDiscreteDistribution::restrictToConstraint(), and bpp::SimpleDiscreteDistribution::restrictToConstraint().

◆ setName()

virtual void bpp::Parameter::setName ( const std::string &  name)
inlinevirtual

Set the name of this parameter.

Parameters
namethe new parameter name.

Definition at line 208 of file Parameter.h.

References fireParameterNameChanged(), and name_.

Referenced by bpp::ParametrizableCollection< N >::addObject(), bpp::FullHmmTransitionMatrix::FullHmmTransitionMatrix(), and bpp::FullHmmTransitionMatrix::setTransitionProbabilities().

◆ setPrecision()

void Parameter::setPrecision ( double  precision)

Set the precision of this parameter.

Parameters
precisionthe new parameter precision.

Precision:

Definition at line 136 of file Parameter.cpp.

References precision_.

◆ setValue()

Member Data Documentation

◆ attach_

bool bpp::Parameter::attach_
protected

Definition at line 143 of file Parameter.h.

Referenced by operator=(), Parameter(), setConstraint(), and ~Parameter().

◆ constraint_

Constraint* bpp::Parameter::constraint_
protected

◆ listenerAttach_

std::vector<bool> bpp::Parameter::listenerAttach_
protected

◆ listeners_

◆ name_

std::string bpp::Parameter::name_
protected

Definition at line 139 of file Parameter.h.

Referenced by getName(), operator=(), and setName().

◆ precision_

double bpp::Parameter::precision_
protected

Definition at line 141 of file Parameter.h.

Referenced by getPrecision(), operator=(), and setPrecision().

◆ PROP_CONSTRAINT_EX

const IntervalConstraint Parameter::PROP_CONSTRAINT_EX
static

◆ PROP_CONSTRAINT_IN

◆ R_MINUS

const IntervalConstraint Parameter::R_MINUS
static

Definition at line 334 of file Parameter.h.

◆ R_MINUS_STAR

const IntervalConstraint Parameter::R_MINUS_STAR
static

Definition at line 335 of file Parameter.h.

◆ R_PLUS

◆ R_PLUS_STAR

const IntervalConstraint Parameter::R_PLUS_STAR
static

◆ value_

double bpp::Parameter::value_
protected

Definition at line 140 of file Parameter.h.

Referenced by getValue(), operator=(), and setConstraint().


The documentation for this class was generated from the following files: