bpp-core  2.1.0
 All Classes Namespaces Files Functions Variables Typedefs Friends
bpp::AbstractParameterAliasable Class Referenceabstract

A partial implementation of the Parametrizable interface. More...

#include <Bpp/Numeric/AbstractParameterAliasable.h>

+ Inheritance diagram for bpp::AbstractParameterAliasable:
+ Collaboration diagram for bpp::AbstractParameterAliasable:

Public Member Functions

 AbstractParameterAliasable (const std::string &prefix)
 
 AbstractParameterAliasable (const AbstractParameterAliasable &ap)
 
AbstractParameterAliasableoperator= (const AbstractParameterAliasable &ap)
 
virtual ~AbstractParameterAliasable ()
 
void setNamespace (const std::string &prefix)
 Set the namespace for the parameter names. More...
 
const ParameterListgetIndependentParameters () const
 Get the minimal list of parameters to set the model. More...
 
size_t getNumberOfIndependentParameters () const
 Get the number of independent parameters. More...
 
void aliasParameters (const std::string &p1, const std::string &p2) throw (ParameterNotFoundException, Exception)
 Set two parameters as 'aliased'. More...
 
void unaliasParameters (const std::string &p1, const std::string &p2) throw (ParameterNotFoundException, Exception)
 Detach two parameters previously set as 'aliased'. More...
 
std::vector< std::string > getAlias (const std::string &name) const
 
void fireParameterChanged (const ParameterList &parameters)
 Notify the class when one or several parameters have changed. More...
 
bool hasParameter (const std::string &name) const
 Tell if there is a parameter with specified name. More...
 
const ParameterListgetParameters () const
 Get all parameters available. More...
 
const ParametergetParameter (const std::string &name) const throw (ParameterNotFoundException)
 Get the parameter with specified name. More...
 
double getParameterValue (const std::string &name) const throw (ParameterNotFoundException)
 Get the value for parameter of name 'name'. More...
 
void setAllParametersValues (const ParameterList &parameters) throw (ParameterNotFoundException, ConstraintException)
 Set the parameters values to be equals to those of parameters. More...
 
void setParameterValue (const std::string &name, double value) throw (ParameterNotFoundException, ConstraintException)
 Set the value of parameter with name name to be equal to value. More...
 
void setParametersValues (const ParameterList &parameters) throw (ParameterNotFoundException, ConstraintException)
 Update the parameters from parameters. More...
 
bool matchParametersValues (const ParameterList &parameters) throw (ConstraintException)
 Update the parameters from parameters. More...
 
size_t getNumberOfParameters () const
 Get the number of parameters. More...
 
std::string getNamespace () const
 
std::string getParameterNameWithoutNamespace (const std::string &name) const
 Resolves a parameter name according to the current namespace. More...
 
virtual Clonableclone () const =0
 Create a copy of this object and send a pointer to it. More...
 

Protected Member Functions

void addParameter_ (Parameter *parameter)
 
void addParameters_ (const ParameterList &parameters)
 
void deleteParameter_ (size_t index) throw (IndexOutOfBoundsException)
 
void resetParameters_ ()
 
ParametergetParameter_ (const std::string &name) throw (ParameterNotFoundException)
 
ParametergetParameter_ (size_t index) throw (IndexOutOfBoundsException)
 
const ParametergetParameter_ (size_t index) const throw (IndexOutOfBoundsException)
 
ParametergetParameterWithNamespace_ (const std::string &name) throw (ParameterNotFoundException)
 
const ParametergetParameterWithNamespace_ (const std::string &name) const throw (ParameterNotFoundException)
 
ParameterListgetParameters_ ()
 

Private Attributes

ParameterList independentParameters_
 
std::map< std::string,
AliasParameterListener * > 
aliasListenersRegister_
 

Detailed Description

A partial implementation of the Parametrizable interface.

Parameters are stored in a protected ParameterList object.

The abstract fireParameterChanged() method is provided so that the derived class know when a parameter has changed, and can be updated. All methods call the corresponding method in ParameterList and then call the fireParameterChanged() method.

Definition at line 126 of file AbstractParameterAliasable.h.

Constructor & Destructor Documentation

bpp::AbstractParameterAliasable::AbstractParameterAliasable ( const std::string &  prefix)
inline

Definition at line 141 of file AbstractParameterAliasable.h.

AbstractParameterAliasable::~AbstractParameterAliasable ( )
virtual

Member Function Documentation

void bpp::AbstractParameterAliasable::addParameter_ ( Parameter parameter)
inlineprotected

Definition at line 177 of file AbstractParameterAliasable.h.

References bpp::AbstractParametrizable::addParameter_(), bpp::Parameter::clone(), and independentParameters_.

Referenced by bpp::BetaDiscreteDistribution::BetaDiscreteDistribution(), bpp::BetaDiscreteDistribution::BetaDiscreteDistribution(), bpp::ConstantDistribution::ConstantDistribution(), bpp::DirichletDiscreteDistribution::DirichletDiscreteDistribution(), bpp::ExponentialDiscreteDistribution::ExponentialDiscreteDistribution(), bpp::GammaDiscreteDistribution::GammaDiscreteDistribution(), bpp::GammaDiscreteDistribution::GammaDiscreteDistribution(), bpp::GaussianDiscreteDistribution::GaussianDiscreteDistribution(), bpp::GaussianDiscreteDistribution::GaussianDiscreteDistribution(), bpp::InvariantMixedDiscreteDistribution::InvariantMixedDiscreteDistribution(), bpp::MixtureOfDiscreteDistributions::MixtureOfDiscreteDistributions(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::Simplex::Simplex(), bpp::Simplex::Simplex(), bpp::Simplex::Simplex(), bpp::Simplex::Simplex(), bpp::TruncatedExponentialDiscreteDistribution::TruncatedExponentialDiscreteDistribution(), and bpp::TruncatedExponentialDiscreteDistribution::TruncatedExponentialDiscreteDistribution().

void AbstractParameterAliasable::aliasParameters ( const std::string &  p1,
const std::string &  p2 
) throw (ParameterNotFoundException, Exception)
virtual

Set two parameters as 'aliased'.

The values of the two parameters will be synchronized, so that setting the value of one parameter will automatically set the value of the other one accordingly.

Parameters
p1Original parameter.
p2Aliased parameter.
Exceptions
ParameterNotFoundExceptionif p1 or p2 do not correspond to existing parameters.
Exceptionwhen trying to perform non-valid association.

Implements bpp::ParameterAliasable.

Definition at line 103 of file AbstractParameterAliasable.cpp.

References bpp::Parameter::addParameterListener(), bpp::Parameter::getConstraint(), bpp::Parameter::getConstraint(), bpp::Parameter::hasConstraint(), bpp::Parameter::hasConstraint(), and bpp::Parameter::hasConstraint().

virtual Clonable* bpp::Clonable::clone ( ) const
pure virtualinherited

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

Returns
A pointer toward the copy object.

Implemented in bpp::TestFunction, bpp::InfinityDerivableSecondOrderWrapper, bpp::InfinityDerivableFirstOrderWrapper, bpp::InfinityFunctionWrapper, bpp::StdErr, bpp::FunctionStopCondition, bpp::StdOut, bpp::LinearMatrix< Scalar >, bpp::PlaceboTransformedParameter, bpp::StlOutputStreamWrapper, bpp::ParametersStopCondition, bpp::ReparametrizationDerivableSecondOrderWrapper, bpp::IntervalTransformedParameter, bpp::MetaOptimizer, bpp::StlOutputStream, bpp::DerivableSecondOrder, bpp::Parameter, bpp::ReparametrizationDerivableFirstOrderWrapper, bpp::IntervalConstraint, bpp::RowMatrix< Scalar >, bpp::RowMatrix< double >, bpp::RowMatrix< Real >, bpp::LowMemoryRescaledHmmLikelihood, bpp::NullOutputStream, bpp::LogsumHmmLikelihood, bpp::Simplex, bpp::RTransformedParameter, bpp::RescaledHmmLikelihood, bpp::DerivableFirstOrder, bpp::Optimizer, bpp::DownhillSimplexMethod, bpp::AbstractNumericalDerivative, bpp::SimpleDiscreteDistribution, bpp::DirichletDiscreteDistribution, bpp::DualityDiagram, bpp::ReparametrizationFunctionWrapper, bpp::PrincipalComponentAnalysis, bpp::TruncatedExponentialDiscreteDistribution, bpp::DataTable, bpp::MetaOptimizerInfos, bpp::MixtureOfDiscreteDistributions, bpp::NewtonBacktrackOneDimension, bpp::AutoParameter, bpp::FivePointsNumericalDerivative, bpp::ParameterListener, bpp::ThreePointsNumericalDerivative, bpp::UNode, bpp::InvariantMixedDiscreteDistribution, bpp::PowellMultiDimensions, bpp::Range< T >, bpp::OutputStream, bpp::AliasParameterListener, bpp::BrentOneDimension, bpp::GammaDiscreteDistribution, bpp::GoldenSectionSearch, bpp::DirectionFunction, bpp::TwoPointsNumericalDerivative, bpp::BetaDiscreteDistribution, bpp::ExponentialDiscreteDistribution, bpp::BppVector< TYPE >, bpp::CorrespondenceAnalysis, bpp::Point2D< T >, bpp::Number< T >, bpp::BppString, bpp::BasicTNode, bpp::ParameterList, bpp::ContingencyTableTest, bpp::Font, bpp::BfgsMultiDimensions, bpp::BppBoolean, bpp::TNode, bpp::HmmLikelihood, bpp::GaussianDiscreteDistribution, bpp::NewtonBacktrackOneDimension::NBODStopCondition, bpp::OptimizationStopCondition, bpp::ParameterEvent, bpp::UniformDiscreteDistribution, bpp::DiscreteDistribution, bpp::MultipleDiscreteDistribution, bpp::ConstantDistribution, bpp::ConjugateGradientMultiDimensions, bpp::DownhillSimplexMethod::DSMStopCondition, bpp::RGBColor, bpp::BrentOneDimension::BODStopCondition, bpp::ONode, bpp::GoldenSectionSearch::GSSStopCondition, bpp::PowellMultiDimensions::PMDStopCondition, bpp::SimpleMultiDimensions, bpp::SimpleNewtonMultiDimensions, bpp::HmmEmissionProbabilities, bpp::Constraint, bpp::TransformedParameter, and bpp::NewtonOneDimension.

void bpp::AbstractParameterAliasable::deleteParameter_ ( size_t  index) throw (IndexOutOfBoundsException)
inlineprotected
vector< string > AbstractParameterAliasable::getAlias ( const std::string &  name) const
virtual
Returns
The list of names of the parameters that are aliased with a given parameter. The implementation is recursive, which means that in the case of A->B->C, getalias(C) will return both A and B.
Parameters
nameThe name of the parameter to look for.

Implements bpp::ParameterAliasable.

Definition at line 190 of file AbstractParameterAliasable.cpp.

References aliasListenersRegister_, aliasListenersRegister_, and bpp::VectorTools::append().

const ParameterList& bpp::AbstractParameterAliasable::getIndependentParameters ( ) const
inlinevirtual

Get the minimal list of parameters to set the model.

If no parameters are aliased, this is the same a getParameters().

Returns
A minimal set of parameters.

Implements bpp::ParameterAliasable.

Definition at line 156 of file AbstractParameterAliasable.h.

References independentParameters_.

std::string bpp::AbstractParametrizable::getNamespace ( ) const
inlinevirtualinherited
size_t bpp::AbstractParameterAliasable::getNumberOfIndependentParameters ( ) const
inlinevirtual

Get the number of independent parameters.

Returns
The number of independent parameters. If no parameters are aliased, this is equivalent to the getNumberOfParameters() method.

Implements bpp::ParameterAliasable.

Definition at line 158 of file AbstractParameterAliasable.h.

References independentParameters_.

size_t bpp::AbstractParametrizable::getNumberOfParameters ( ) const
inlinevirtualinherited

Get the number of parameters.

See Also
getNumberOfIndependentParameters If some parameters are aliased.
Returns
The number of parameters.

Implements bpp::Parametrizable.

Definition at line 120 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::parameters_.

Referenced by AbstractParameterAliasable(), bpp::SimpleDiscreteDistribution::fireParameterChanged(), operator=(), bpp::ConstantDistribution::restrictToConstraint(), and bpp::SimpleDiscreteDistribution::restrictToConstraint().

Parameter& bpp::AbstractParametrizable::getParameter_ ( size_t  index) throw (IndexOutOfBoundsException)
inlineprotectedinherited
const Parameter& bpp::AbstractParametrizable::getParameter_ ( size_t  index) const throw (IndexOutOfBoundsException)
inlineprotectedinherited
std::string AbstractParametrizable::getParameterNameWithoutNamespace ( const std::string &  name) const
virtualinherited

Resolves a parameter name according to the current namespace.

Returns
The parameter name without the namespace prefix, if any.

Implements bpp::Parametrizable.

Definition at line 63 of file AbstractParametrizable.cpp.

References bpp::TextTools::startsWith().

const ParameterList& bpp::AbstractParametrizable::getParameters ( ) const
inlinevirtualinherited

Get all parameters available.

See Also
getIndependentParameters if some parameters are aliased.
Returns
A list with all parameters available.

Implements bpp::Parametrizable.

Definition at line 77 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::parameters_.

Referenced by fireParameterChanged(), and bpp::MixtureOfDiscreteDistributions::MixtureOfDiscreteDistributions().

double bpp::AbstractParametrizable::getParameterValue ( const std::string &  name) const throw (ParameterNotFoundException)
inlinevirtualinherited

Get the value for parameter of name 'name'.

Parameters
nameThe name of the parameter.
Returns
the value of parameter name.

Implements bpp::Parametrizable.

Definition at line 84 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::getParameter(), and bpp::Parameter::getValue().

Referenced by bpp::DirichletDiscreteDistribution::applyParameters(), bpp::ConstantDistribution::fireParameterChanged(), bpp::GaussianDiscreteDistribution::fireParameterChanged(), bpp::GaussianDiscreteDistribution::fireParameterChanged(), bpp::ExponentialDiscreteDistribution::fireParameterChanged(), bpp::GammaDiscreteDistribution::fireParameterChanged(), bpp::GammaDiscreteDistribution::fireParameterChanged(), bpp::BetaDiscreteDistribution::fireParameterChanged(), bpp::BetaDiscreteDistribution::fireParameterChanged(), bpp::InvariantMixedDiscreteDistribution::fireParameterChanged(), bpp::TruncatedExponentialDiscreteDistribution::fireParameterChanged(), bpp::TruncatedExponentialDiscreteDistribution::fireParameterChanged(), bpp::SimpleDiscreteDistribution::fireParameterChanged(), bpp::SimpleDiscreteDistribution::fireParameterChanged(), bpp::SimpleDiscreteDistribution::fireParameterChanged(), bpp::SimpleDiscreteDistribution::fireParameterChanged(), bpp::MixtureOfDiscreteDistributions::fireParameterChanged(), bpp::MixtureOfDiscreteDistributions::fireParameterChanged(), bpp::Simplex::fireParameterChanged(), bpp::Simplex::fireParameterChanged(), bpp::GammaDiscreteDistribution::randC(), bpp::ExponentialDiscreteDistribution::randC(), bpp::GammaDiscreteDistribution::randC(), bpp::GammaDiscreteDistribution::randC(), bpp::ExponentialDiscreteDistribution::randC(), bpp::GammaDiscreteDistribution::randC(), bpp::BetaDiscreteDistribution::randC(), bpp::BetaDiscreteDistribution::randC(), bpp::BetaDiscreteDistribution::randC(), bpp::BetaDiscreteDistribution::randC(), bpp::TruncatedExponentialDiscreteDistribution::randC(), bpp::TruncatedExponentialDiscreteDistribution::randC(), bpp::ConstantDistribution::restrictToConstraint(), and bpp::ConstantDistribution::restrictToConstraint().

Parameter& bpp::AbstractParametrizable::getParameterWithNamespace_ ( const std::string &  name) throw (ParameterNotFoundException)
inlineprotectedinherited
Parameters
nameThe name of the parameter, including its namespace.
Returns
A reference toward the corresponding parameter.
Exceptions
ParameterNotFoundExceptionIf no parameter with that name is found in the list.

Definition at line 174 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::getParameter_().

const Parameter& bpp::AbstractParametrizable::getParameterWithNamespace_ ( const std::string &  name) const throw (ParameterNotFoundException)
inlineprotectedinherited
Parameters
nameThe name of the parameter, including its namespace.
Returns
A reference toward the corresponding parameter.
Exceptions
ParameterNotFoundExceptionIf no parameter with that name is found in the list.

Definition at line 183 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::getParameter().

bool bpp::AbstractParametrizable::hasParameter ( const std::string &  name) const
inlinevirtualinherited

Tell if there is a parameter with specified name.

Parameters
nameThe name of the parameter to look for.
Returns
y/n.

Implements bpp::Parametrizable.

Definition at line 75 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::parameters_.

Referenced by bpp::ConstantDistribution::fireParameterChanged().

bool bpp::AbstractParametrizable::matchParametersValues ( const ParameterList parameters) throw (ConstraintException)
inlinevirtualinherited

Update the parameters from parameters.

Only common parameters with parameters will be updated.

Parameters
parametersA list of parameters.
Returns
True if at least one parameter value has been changed.
Exceptions
ConstraintExceptionIf a value in parameters does not match the constraint in the corresponding parameter in the list.

Implements bpp::Parametrizable.

Definition at line 111 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::fireParameterChanged(), and bpp::AbstractParametrizable::parameters_.

Referenced by bpp::Simplex::setFrequencies(), bpp::ReparametrizationFunctionWrapper::setParameters(), and bpp::TestFunction::setParameters().

void bpp::AbstractParameterAliasable::resetParameters_ ( )
inlineprotected
void bpp::AbstractParametrizable::setAllParametersValues ( const ParameterList parameters) throw (ParameterNotFoundException, ConstraintException)
inlinevirtualinherited

Set the parameters values to be equals to those of parameters.

The list must contain exactly the same parameters (ie same names) than the parameters available.

Parameters
parametersA list with all parameters.
Exceptions
ParameterNotFoundExceptionIf a some parameter in the list is not in params.
ConstraintExceptionIf a value in parameters does not match the constraint in the corresponding parameter in the list.

Implements bpp::Parametrizable.

Definition at line 90 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::fireParameterChanged(), and bpp::AbstractParametrizable::parameters_.

void bpp::AbstractParametrizable::setParametersValues ( const ParameterList parameters) throw (ParameterNotFoundException, ConstraintException)
inlinevirtualinherited

Update the parameters from parameters.

parameters must be a subset of all parameters available.

Parameters
parametersA list containing all parameters to update.
Exceptions
ParameterNotFoundExceptionIf a some parameter in params is not in the list.
ConstraintExceptionIf a value in parameters does not match the constraint in the corresponding parameter in the list.

Implements bpp::Parametrizable.

Definition at line 104 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::fireParameterChanged(), and bpp::AbstractParametrizable::parameters_.

Referenced by bpp::RescaledHmmLikelihood::setParameters(), bpp::LogsumHmmLikelihood::setParameters(), and bpp::LowMemoryRescaledHmmLikelihood::setParameters().

void bpp::AbstractParametrizable::setParameterValue ( const std::string &  name,
double  value 
) throw (ParameterNotFoundException, ConstraintException)
inlinevirtualinherited

Set the value of parameter with name name to be equal to value.

Parameters
namethe name of the parameter to set.
valueThe value of the parameter.
Exceptions
ParameterNotFoundExceptionIf no parameter in the list has the name name.
ConstraintExceptionIf value does not match the constraint associated to parameter name.

Implements bpp::Parametrizable.

Definition at line 97 of file AbstractParametrizable.h.

References bpp::AbstractParametrizable::fireParameterChanged(), and bpp::AbstractParametrizable::parameters_.

void AbstractParameterAliasable::unaliasParameters ( const std::string &  p1,
const std::string &  p2 
) throw (ParameterNotFoundException, Exception)
virtual

Detach two parameters previously set as 'aliased'.

The values of the two parameters will now be independent.

Parameters
p1Original parameter.
p2Aliased parameter.
Exceptions
ParameterNotFoundExceptionif p1 or p2 do not correspond to existing parameters.
Exceptionwhen trying to perform non-valid dissociation.

Implements bpp::ParameterAliasable.

Definition at line 143 of file AbstractParameterAliasable.cpp.

Member Data Documentation

std::map<std::string, AliasParameterListener *> bpp::AbstractParameterAliasable::aliasListenersRegister_
private

Contains all parameter listeners for maintening alias relationships. The registry will be updated appropriately upon cloning and deleting.

Definition at line 138 of file AbstractParameterAliasable.h.

Referenced by AbstractParameterAliasable(), AbstractParameterAliasable(), AbstractParameterAliasable(), getAlias(), getAlias(), operator=(), operator=(), operator=(), setNamespace(), setNamespace(), ~AbstractParameterAliasable(), and ~AbstractParameterAliasable().


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