bpp-core  2.1.0
bpp::AutoParameter Class Reference

The AutoParameter class. More...

#include <Bpp/Numeric/AutoParameter.h>

+ Inheritance diagram for bpp::AutoParameter:
+ Collaboration diagram for bpp::AutoParameter:

List of all members.

Public Member Functions

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

Static Public Attributes

static std::string CONSTRAINTS_AUTO = "auto"
static std::string CONSTRAINTS_IGNORE = "ignore"
static std::string CONSTRAINTS_KEEP = "keep"
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_

Private Attributes

OutputStreammessageHandler_

Detailed Description

The AutoParameter class.

This class overides the setValue() method of class Parameter so that no Exception is thrown. This allows to perform optimization under constraint.

Definition at line 58 of file AutoParameter.h.


Constructor & Destructor Documentation

AutoParameter::AutoParameter ( const std::string &  name = "",
double  value = 0,
Constraint constraint = 0,
bool  attachConstraint = false 
) throw (ConstraintException)

Build a new AutoParameter.

Parameters:
nameThe parameter name.
valueThe parameter value.
constraintAn optional pointer toward a Constraint object.
attachConstraintTell if the constraint must be attached to this parameter, or shared between different objects. See Parameter.
Exceptions:
ConstraintExceptionIf the parameter value does not match the contraint.

Constructors:

Definition at line 61 of file AutoParameter.cpp.

Referenced by clone().

Copy constructor.

Parameters:
paramThe parameter to copy.

Definition at line 64 of file AutoParameter.cpp.

Copy constructor.

Parameters:
paramThe parameter to copy.

Definition at line 66 of file AutoParameter.cpp.

virtual bpp::AutoParameter::~AutoParameter ( ) [inline, virtual]

Definition at line 99 of file AutoParameter.h.


Member Function Documentation

virtual void bpp::Parameter::addParameterListener ( ParameterListener listener,
bool  attachListener = true 
) [inline, virtual, inherited]

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

References bpp::Parameter::listenerAttach_, and bpp::Parameter::listeners_.

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

AutoParameter* bpp::AutoParameter::clone ( ) const [inline, virtual]

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

Returns:
A pointer toward the copy object.

Reimplemented from bpp::Parameter.

Definition at line 101 of file AutoParameter.h.

References AutoParameter().

void bpp::Parameter::fireParameterNameChanged ( ParameterEvent event) [inline, protected, inherited]

Definition at line 321 of file Parameter.h.

References bpp::Parameter::listeners_.

Referenced by bpp::Parameter::setName().

void bpp::Parameter::fireParameterValueChanged ( ParameterEvent event) [inline, protected, inherited]

Definition at line 326 of file Parameter.h.

References bpp::Parameter::listeners_.

virtual const Constraint* bpp::Parameter::getConstraint ( ) const [inline, virtual, inherited]

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 bpp::Parameter::constraint_.

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

virtual Constraint* bpp::Parameter::getConstraint ( ) [inline, virtual, inherited]

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 bpp::Parameter::constraint_.

virtual double bpp::Parameter::getPrecision ( ) const [inline, virtual, inherited]

Get the precision of this parameter.

Returns:
The precision value.

Definition at line 248 of file Parameter.h.

References bpp::Parameter::precision_.

virtual bool bpp::Parameter::hasConstraint ( ) const [inline, virtual, inherited]

Tells if this parameter has a constraint.

Returns:
True if this parameter has a contraint.

Definition at line 269 of file Parameter.h.

References bpp::Parameter::constraint_.

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

bool Parameter::hasParameterListener ( const std::string &  listenerId) [virtual, inherited]

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 bpp::Parameter::listeners_.

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

Assignment operator.

Parameters:
paramThe parameter to copy.

Definition at line 68 of file AutoParameter.cpp.

References messageHandler_.

const Constraint * Parameter::removeConstraint ( ) [virtual, inherited]

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 bpp::Parameter::constraint_.

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

void Parameter::removeParameterListener ( const std::string &  listenerId) [virtual, inherited]

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 bpp::Parameter::listenerAttach_, and bpp::Parameter::listeners_.

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

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).
Returns:
A pointer toward the formerly used contraint.

Constraint:

Definition at line 143 of file Parameter.cpp.

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

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

virtual void bpp::AutoParameter::setMessageHandler ( OutputStream mh) [inline, virtual]

Set the message handler for this AutoParameter.

The message handler keeps all messages that the parameter may send. The default handler is set to standard output, but you can pass any ostream object (cerr, ofstream, etc.).

A NULL pointer disable message output.

Parameters:
mhThe message handler to use.

Definition at line 134 of file AutoParameter.h.

References messageHandler_.

Referenced by bpp::DirectionFunction::autoParameter(), bpp::AbstractOptimizer::autoParameter(), and bpp::BppODiscreteDistributionFormat::initialize_().

virtual void bpp::Parameter::setName ( const std::string &  name) [inline, virtual, inherited]

Set the name of this parameter.

Parameters:
namethe new parameter name.

Definition at line 208 of file Parameter.h.

References bpp::Parameter::fireParameterNameChanged(), and bpp::Parameter::name_.

void Parameter::setPrecision ( double  precision) [inherited]

Set the precision of this parameter.

Parameters:
precisionthe new parameter precision.

Precision:

Definition at line 136 of file Parameter.cpp.

References bpp::Parameter::precision_.

void AutoParameter::setValue ( double  value) throw (ConstraintException) [virtual]

Set the value of this parameter.

This method is redefined so that no constraintException is thrown! When a Constraint is match, we automatically apply a correct value instead. This correct value is the nearest limit reached by the value, or a value next to the limit if the limit is not reachable.

This allow to perform optimization under constraint whith algorithms that are not initially built for this.

Parameters:
valuethe new parameter value.
Exceptions:
ConstraintExceptionNever thrown!

Reimplemented from bpp::Parameter.

Definition at line 77 of file AutoParameter.cpp.

References bpp::ConstraintException::getBadValue(), bpp::Parameter::setValue(), and bpp::NumConstants::TINY().


Member Data Documentation

Definition at line 62 of file AutoParameter.h.

Referenced by operator=(), and setMessageHandler().

std::string bpp::Parameter::name_ [protected, inherited]
double bpp::Parameter::precision_ [protected, inherited]

Definition at line 338 of file Parameter.h.

const IntervalConstraint Parameter::R_MINUS [static, inherited]

Definition at line 335 of file Parameter.h.

const IntervalConstraint Parameter::R_MINUS_STAR [static, inherited]

Definition at line 336 of file Parameter.h.

double bpp::Parameter::value_ [protected, inherited]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Friends