bpp-core3  3.0.0
bpp::AbstractParametrizable Class Referenceabstract

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

#include <Bpp/Numeric/AbstractParametrizable.h>

+ Inheritance diagram for bpp::AbstractParametrizable:
+ Collaboration diagram for bpp::AbstractParametrizable:

Public Member Functions

 AbstractParametrizable (const std::string &prefix)
 
virtual ~AbstractParametrizable ()
 
bool hasParameter (const std::string &name) const override
 Tell if there is a parameter with specified name. More...
 
const ParameterListgetParameters () const override
 Get all parameters available. More...
 
const Parameterparameter (const std::string &name) const override
 Get the parameter with specified name. More...
 
const std::shared_ptr< Parameter > & getParameter (const std::string &name) const
 
double getParameterValue (const std::string &name) const override
 Get the value for parameter of name 'name'. More...
 
void setAllParametersValues (const ParameterList &parameters) override
 Set the parameters values to be equals to those of parameters. More...
 
void setParameterValue (const std::string &name, double value) override
 Set the value of parameter with name name to be equal to value. More...
 
void setParametersValues (const ParameterList &parameters) override
 Update the parameters from parameters. More...
 
bool matchParametersValues (const ParameterList &parameters) override
 Update the parameters from parameters. More...
 
void removeConstraint (const std::string &name) override
 Remove the constraint associated with one parameter, if any. More...
 
void setConstraint (const std::string &name, std::shared_ptr< ConstraintInterface > constraint) override
 Set/Change the constraint associated with one parameter. More...
 
size_t getNumberOfParameters () const override
 Get the number of parameters. More...
 
void setNamespace (const std::string &prefix) override
 Set the namespace for the parameter names. More...
 
std::string getNamespace () const override
 
std::string getParameterNameWithoutNamespace (const std::string &name) const override
 Resolves a parameter name according to the current namespace. More...
 
virtual void fireParameterChanged (const ParameterList &parameters)
 Notify the class when one or several parameters have changed. More...
 
virtual Clonableclone () const =0
 Create a copy of this object and send a pointer to it. More...
 

Protected Member Functions

virtual void addParameter_ (Parameter *parameter)
 
virtual void addParameters_ (const ParameterList &parameters)
 
virtual void shareParameter_ (const std::shared_ptr< Parameter > &parameter)
 
virtual void shareParameters_ (const ParameterList &parameters)
 
virtual void includeParameters_ (const ParameterList &parameters)
 
virtual void deleteParameter_ (size_t index)
 
virtual void deleteParameter_ (std::string &name)
 
virtual void deleteParameters_ (const std::vector< std::string > &names)
 
void resetParameters_ ()
 
ParametergetParameter_ (const std::string &name)
 
ParametergetParameterWithNamespace_ (const std::string &name)
 
const ParametergetParameterWithNamespace_ (const std::string &name) const
 
ParametergetParameter_ (size_t index)
 
const ParametergetParameter_ (size_t index) const
 
ParameterListgetParameters_ () override
 Get all parameters available. More...
 
const std::shared_ptr< Parameter > & getParameter (size_t i) const
 
std::shared_ptr< Parameter > & getParameter (size_t i)
 

Private Attributes

ParameterList parameters_
 
std::string prefix_
 

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 26 of file AbstractParametrizable.h.

Constructor & Destructor Documentation

◆ AbstractParametrizable()

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

Definition at line 34 of file AbstractParametrizable.h.

◆ ~AbstractParametrizable()

virtual bpp::AbstractParametrizable::~AbstractParametrizable ( )
inlinevirtual

Definition at line 36 of file AbstractParametrizable.h.

Member Function Documentation

◆ addParameter_()

virtual void bpp::AbstractParametrizable::addParameter_ ( Parameter parameter)
inlineprotectedvirtual

◆ addParameters_()

◆ clone()

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::LinearMatrix< Scalar >, bpp::AssociationGraphImplObserver< N, E, GraphImpl >, bpp::AssociationGraphImplObserver< N, E, DAGraphImpl >, bpp::AssociationGraphImplObserver< N, E, TreeGraphImpl >, bpp::StdErr, bpp::FunctionStopCondition, bpp::ColMatrix< Scalar >, bpp::PlaceboTransformedParameter, bpp::StdOut, bpp::GlobalGraph, bpp::ParametersStopCondition, bpp::StlOutputStreamWrapper, bpp::ReparametrizationDerivableSecondOrderWrapper, bpp::IntervalTransformedParameter, bpp::MetaOptimizer, bpp::IntervalConstraint, bpp::BppUnsignedInteger, bpp::StlOutputStream, bpp::SecondOrderDerivable, bpp::LogsumHmmLikelihood, bpp::RescaledHmmLikelihood, bpp::ReparametrizationDerivableFirstOrderWrapper, bpp::BppInteger, bpp::RowMatrix< Scalar >, bpp::RowMatrix< double >, bpp::RowMatrix< Real >, bpp::Parameter, bpp::Simplex, bpp::LowMemoryRescaledHmmLikelihood, bpp::Table< T >, bpp::AbstractNumericalDerivative, bpp::BppDouble, bpp::RTransformedParameter, bpp::NullOutputStream, bpp::ParametrizableCollection< N >, bpp::FirstOrderDerivable, bpp::OptimizerInterface, bpp::AssociationTreeGraphImplObserver< N, E, TreeGraphImpl >, bpp::AssociationDAGraphImplObserver< N, E, DAGraphImpl >, bpp::ThreePointsNumericalDerivative, bpp::DirichletDiscreteDistribution, bpp::SimpleDiscreteDistribution, bpp::DownhillSimplexMethod, bpp::Number< T >, bpp::Number< double >, bpp::Number< int >, bpp::Number< unsigned int >, bpp::FivePointsNumericalDerivative, bpp::ReparametrizationFunctionWrapper, bpp::DataTable, bpp::PrincipalComponentAnalysis, bpp::DualityDiagram, bpp::TruncatedExponentialDiscreteDistribution, bpp::MetaOptimizerInfos, bpp::BrentOneDimension, bpp::NewtonBacktrackOneDimension, bpp::FunctionOperator< F >, bpp::AutoParameter, bpp::GammaDiscreteDistribution, bpp::MixtureOfDiscreteDistributions, bpp::AliasParameterListener, bpp::Range< T >, bpp::PowellMultiDimensions, bpp::InvariantMixedDiscreteDistribution, bpp::TwoPointsNumericalDerivative, bpp::ParameterListener, bpp::OutputStream, bpp::GoldenSectionSearch, bpp::DirectionFunction, bpp::Point2D< T >, bpp::BetaDiscreteDistribution, bpp::ExponentialDiscreteDistribution, bpp::ParameterList, bpp::CorrespondenceAnalysis, bpp::HmmLikelihood, bpp::GaussianDiscreteDistribution, bpp::BfgsMultiDimensions, bpp::NewtonBacktrackOneDimension::NBODStopCondition, bpp::FullHmmTransitionMatrix, bpp::BppNotANumber, bpp::UniformDiscreteDistribution, bpp::ContingencyTableTest, bpp::Font, bpp::ConstantDistribution, bpp::DiscreteDistributionInterface, bpp::MultipleDiscreteDistribution, bpp::DownhillSimplexMethod::DSMStopCondition, bpp::MathOperator, bpp::BrentOneDimension::BODStopCondition, bpp::ConjugateGradientMultiDimensions, bpp::OptimizationStopCondition, bpp::AutoCorrelationTransitionMatrix, bpp::ParameterEvent, bpp::ComputationTree, bpp::GoldenSectionSearch::GSSStopCondition, bpp::PowellMultiDimensions::PMDStopCondition, bpp::ConstraintInterface, bpp::HmmStateAlphabet, bpp::RGBColor, bpp::SimpleMultiDimensions, bpp::SimpleNewtonMultiDimensions, bpp::HmmEmissionProbabilities, bpp::BinaryOperator, bpp::BppVector< T >, bpp::TransformedParameter, bpp::BppString, bpp::ConstantOperator, bpp::NegativeOperator, bpp::HmmTransitionMatrix, bpp::BppNumberI, bpp::BppBoolean, and bpp::NewtonOneDimension.

Referenced by bpp::FirstOrderDerivable::~FirstOrderDerivable(), and bpp::SecondOrderDerivable::~SecondOrderDerivable().

◆ deleteParameter_() [1/2]

virtual void bpp::AbstractParametrizable::deleteParameter_ ( size_t  index)
inlineprotectedvirtual

◆ deleteParameter_() [2/2]

virtual void bpp::AbstractParametrizable::deleteParameter_ ( std::string &  name)
inlineprotectedvirtual

◆ deleteParameters_()

virtual void bpp::AbstractParametrizable::deleteParameters_ ( const std::vector< std::string > &  names)
inlineprotectedvirtual

◆ fireParameterChanged()

virtual void bpp::AbstractParametrizable::fireParameterChanged ( const ParameterList parameters)
inlinevirtual

Notify the class when one or several parameters have changed.

Parameters
parametersA ParameterList object with parameters that changed.

Reimplemented in bpp::TestFunction, bpp::OrderedSimplex, bpp::LogsumHmmLikelihood, bpp::RescaledHmmLikelihood, bpp::LowMemoryRescaledHmmLikelihood, bpp::Simplex, bpp::ParametrizableCollection< N >, bpp::ReparametrizationFunctionWrapper, bpp::MixtureOfDiscreteDistributions, bpp::SimpleDiscreteDistribution, bpp::DirichletDiscreteDistribution, bpp::FullHmmTransitionMatrix, bpp::TruncatedExponentialDiscreteDistribution, bpp::AutoCorrelationTransitionMatrix, bpp::GammaDiscreteDistribution, bpp::InvariantMixedDiscreteDistribution, bpp::BetaDiscreteDistribution, bpp::ExponentialDiscreteDistribution, bpp::GaussianDiscreteDistribution, bpp::UniformDiscreteDistribution, and bpp::ConstantDistribution.

Definition at line 108 of file AbstractParametrizable.h.

Referenced by bpp::ConstantDistribution::fireParameterChanged(), bpp::GaussianDiscreteDistribution::fireParameterChanged(), bpp::ExponentialDiscreteDistribution::fireParameterChanged(), bpp::BetaDiscreteDistribution::fireParameterChanged(), bpp::InvariantMixedDiscreteDistribution::fireParameterChanged(), bpp::GammaDiscreteDistribution::fireParameterChanged(), bpp::TruncatedExponentialDiscreteDistribution::fireParameterChanged(), bpp::DirichletDiscreteDistribution::fireParameterChanged(), bpp::SimpleDiscreteDistribution::fireParameterChanged(), bpp::MixtureOfDiscreteDistributions::fireParameterChanged(), matchParametersValues(), setAllParametersValues(), setParametersValues(), and setParameterValue().

◆ getNamespace()

std::string bpp::AbstractParametrizable::getNamespace ( ) const
inlineoverridevirtual

◆ getNumberOfParameters()

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

◆ getParameter() [1/3]

const std::shared_ptr<Parameter>& bpp::AbstractParametrizable::getParameter ( const std::string &  name) const
inline

◆ getParameter() [2/3]

const std::shared_ptr<Parameter>& bpp::AbstractParametrizable::getParameter ( size_t  i) const
inlineprotected
Returns
The shared_ptr parameter at a given position.
Warning
No check is performed on the validity of the index given as input!

Definition at line 211 of file AbstractParametrizable.h.

References bpp::ParameterList::getParameter().

◆ getParameter() [3/3]

std::shared_ptr<Parameter>& bpp::AbstractParametrizable::getParameter ( size_t  i)
inlineprotected

Definition at line 216 of file AbstractParametrizable.h.

References bpp::ParameterList::getParameter().

◆ getParameter_() [1/3]

Parameter& bpp::AbstractParametrizable::getParameter_ ( const std::string &  name)
inlineprotected

◆ getParameter_() [2/3]

Parameter& bpp::AbstractParametrizable::getParameter_ ( size_t  index)
inlineprotected

Definition at line 190 of file AbstractParametrizable.h.

References bpp::ParameterList::size().

◆ getParameter_() [3/3]

const Parameter& bpp::AbstractParametrizable::getParameter_ ( size_t  index) const
inlineprotected

Definition at line 197 of file AbstractParametrizable.h.

References bpp::ParameterList::size().

◆ getParameterNameWithoutNamespace()

std::string AbstractParametrizable::getParameterNameWithoutNamespace ( const std::string &  name) const
overridevirtual

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 28 of file AbstractParametrizable.cpp.

References bpp::TextTools::startsWith().

Referenced by bpp::AbstractParameterAliasable::AbstractParameterAliasable(), getNamespace(), and bpp::AbstractParameterAliasable::operator=().

◆ getParameters()

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

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 41 of file AbstractParametrizable.h.

References parameters_.

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::FullHmmTransitionMatrix::FullHmmTransitionMatrix(), bpp::MixtureOfDiscreteDistributions::MixtureOfDiscreteDistributions(), and bpp::ParametrizableCollection< N >::removeObject().

◆ getParameters_()

ParameterList& bpp::AbstractParametrizable::getParameters_ ( )
inlineoverrideprotectedvirtual

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 205 of file AbstractParametrizable.h.

References parameters_.

Referenced by bpp::AbstractParameterAliasable::AbstractParameterAliasable(), bpp::AbstractParameterAliasable::aliasParameters(), and bpp::AbstractParameterAliasable::operator=().

◆ getParameterValue()

◆ getParameterWithNamespace_() [1/2]

Parameter& bpp::AbstractParametrizable::getParameterWithNamespace_ ( const std::string &  name)
inlineprotected
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 176 of file AbstractParametrizable.h.

References getParameter_().

◆ getParameterWithNamespace_() [2/2]

const Parameter& bpp::AbstractParametrizable::getParameterWithNamespace_ ( const std::string &  name) const
inlineprotected
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 185 of file AbstractParametrizable.h.

References parameter().

◆ hasParameter()

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

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 39 of file AbstractParametrizable.h.

References bpp::ParameterList::hasParameter().

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::GammaDiscreteDistribution::fireParameterChanged(), getParameter_(), and bpp::AbstractParameterAliasable::unaliasParameters().

◆ includeParameters_()

virtual void bpp::AbstractParametrizable::includeParameters_ ( const ParameterList parameters)
inlineprotectedvirtual

◆ matchParametersValues()

bool bpp::AbstractParametrizable::matchParametersValues ( const ParameterList parameters)
inlineoverridevirtual

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 76 of file AbstractParametrizable.h.

References fireParameterChanged(), bpp::ParameterList::matchParametersValues(), and bpp::ParameterList::shareSubList().

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::Simplex::setFrequencies(), bpp::ReparametrizationFunctionWrapper::setParameters(), and bpp::FullHmmTransitionMatrix::setTransitionProbabilities().

◆ parameter()

const Parameter& bpp::AbstractParametrizable::parameter ( const std::string &  name) const
inlineoverridevirtual

◆ removeConstraint()

void bpp::AbstractParametrizable::removeConstraint ( const std::string &  name)
inlineoverridevirtual

Remove the constraint associated with one parameter, if any.

Parameters
nameThe name of the parameter to look for.
Exceptions
ParameterNotFoundExceptionif no parameter with this name is found.

Implements bpp::Parametrizable.

Definition at line 85 of file AbstractParametrizable.h.

References getParameter_(), and bpp::Parameter::removeConstraint().

◆ resetParameters_()

void bpp::AbstractParametrizable::resetParameters_ ( )
inlineprotected

◆ setAllParametersValues()

void bpp::AbstractParametrizable::setAllParametersValues ( const ParameterList parameters)
inlineoverridevirtual

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 58 of file AbstractParametrizable.h.

References fireParameterChanged(), and bpp::ParameterList::setAllParametersValues().

◆ setConstraint()

void bpp::AbstractParametrizable::setConstraint ( const std::string &  name,
std::shared_ptr< ConstraintInterface constraint 
)
inlineoverridevirtual

Set/Change the constraint associated with one parameter.

Parameters
nameThe name of the parameter to look for.
constraintA pointer to the constraint (may be null)
Exceptions
ParameterNotFoundExceptionif no parameter with this name is found.

Implements bpp::Parametrizable.

Definition at line 90 of file AbstractParametrizable.h.

References getParameter_(), and bpp::Parameter::setConstraint().

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

◆ setNamespace()

void AbstractParametrizable::setNamespace ( const std::string &  prefix)
overridevirtual

Set the namespace for the parameter names.

Parameters
prefixThe 'namespace', that is a prefix to add to all parameter names. If parameter names are already prefixed, the new prefix will be used instead.

Implements bpp::Parametrizable.

Reimplemented in bpp::LogsumHmmLikelihood, bpp::RescaledHmmLikelihood, bpp::LowMemoryRescaledHmmLikelihood, bpp::MixtureOfDiscreteDistributions, and bpp::InvariantMixedDiscreteDistribution.

Definition at line 10 of file AbstractParametrizable.cpp.

References bpp::TextTools::startsWith().

Referenced by getNumberOfParameters(), bpp::AbstractParameterAliasable::setNamespace(), bpp::LowMemoryRescaledHmmLikelihood::setNamespace(), bpp::LogsumHmmLikelihood::setNamespace(), and bpp::RescaledHmmLikelihood::setNamespace().

◆ setParametersValues()

void bpp::AbstractParametrizable::setParametersValues ( const ParameterList parameters)
inlineoverridevirtual

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 70 of file AbstractParametrizable.h.

References fireParameterChanged(), and bpp::ParameterList::setParametersValues().

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

◆ setParameterValue()

void bpp::AbstractParametrizable::setParameterValue ( const std::string &  name,
double  value 
)
inlineoverridevirtual

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 64 of file AbstractParametrizable.h.

References bpp::ParameterList::createSubList(), fireParameterChanged(), and bpp::ParameterList::setParameterValue().

◆ shareParameter_()

virtual void bpp::AbstractParametrizable::shareParameter_ ( const std::shared_ptr< Parameter > &  parameter)
inlineprotectedvirtual

◆ shareParameters_()

virtual void bpp::AbstractParametrizable::shareParameters_ ( const ParameterList parameters)
inlineprotectedvirtual

Member Data Documentation

◆ parameters_

ParameterList bpp::AbstractParametrizable::parameters_
private

Definition at line 30 of file AbstractParametrizable.h.

Referenced by getParameters(), and getParameters_().

◆ prefix_

std::string bpp::AbstractParametrizable::prefix_
private

Definition at line 31 of file AbstractParametrizable.h.

Referenced by getNamespace().


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