bpp-core  2.4.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)
 Build a new parameter. More...
 
 Parameter (const std::string &name, double value, const Constraint *constraint=0, double precision=0)
 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)
 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 125 of file Parameter.h.

Constructor & Destructor Documentation

bpp::Parameter::Parameter ( )
inline

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

Definition at line 142 of file Parameter.h.

References bpp::ParameterEvent::operator=().

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

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.

References setPrecision(), and setValue().

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

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 65 of file Parameter.cpp.

References setPrecision(), and setValue().

Parameter::Parameter ( const Parameter param)

Copy constructor.

Definition at line 73 of file Parameter.cpp.

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

Parameter::~Parameter ( )
virtual

Destructor:

Definition at line 111 of file Parameter.cpp.

References attach_, constraint_, listenerAttach_, and listeners_.

Member Function Documentation

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 281 of file Parameter.h.

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

Parameter* bpp::Parameter::clone ( ) const
inlinevirtual
void bpp::Parameter::fireParameterNameChanged ( ParameterEvent event)
inlineprotected

Definition at line 303 of file Parameter.h.

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

Definition at line 308 of file Parameter.h.

Referenced by setValue().

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 238 of file Parameter.h.

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

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 245 of file Parameter.h.

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

Get the precision of this parameter.

Returns
The precision value.

Definition at line 231 of file Parameter.h.

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 252 of file Parameter.h.

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

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 185 of file Parameter.cpp.

References listeners_, PROP_CONSTRAINT_EX, PROP_CONSTRAINT_IN, R_MINUS, R_MINUS_STAR, R_PLUS, and R_PLUS_STAR.

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

Assignment operator.

Definition at line 91 of file Parameter.cpp.

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

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

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 161 of file Parameter.cpp.

References constraint_.

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

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 170 of file Parameter.cpp.

References listenerAttach_, and listeners_.

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

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 141 of file Parameter.cpp.

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

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

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

Set the name of this parameter.

Parameters
namethe new parameter name.

Definition at line 191 of file Parameter.h.

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

void Parameter::setPrecision ( double  precision)

Set the precision of this parameter.

Parameters
precisionthe new parameter precision.

Precision:

Definition at line 134 of file Parameter.cpp.

References precision_.

Referenced by Parameter().

Member Data Documentation

bool bpp::Parameter::attach_
protected

Definition at line 133 of file Parameter.h.

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

Constraint* bpp::Parameter::constraint_
protected
std::vector<bool> bpp::Parameter::listenerAttach_
protected

Definition at line 135 of file Parameter.h.

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

std::vector<ParameterListener*> bpp::Parameter::listeners_
protected
std::string bpp::Parameter::name_
protected

Definition at line 129 of file Parameter.h.

Referenced by operator=(), and bpp::AutoParameter::setValue().

double bpp::Parameter::precision_
protected

Definition at line 131 of file Parameter.h.

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

const IntervalConstraint Parameter::PROP_CONSTRAINT_EX
static
const IntervalConstraint Parameter::R_MINUS
static

Definition at line 317 of file Parameter.h.

Referenced by hasParameterListener().

const IntervalConstraint Parameter::R_MINUS_STAR
static

Definition at line 318 of file Parameter.h.

Referenced by hasParameterListener().

const IntervalConstraint Parameter::R_PLUS_STAR
static
double bpp::Parameter::value_
protected

Definition at line 130 of file Parameter.h.

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


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