bpp-core  2.2.0
bpp::ParameterList Class Reference

The parameter list object. More...

#include <Bpp/Numeric/ParameterList.h>

+ Inheritance diagram for bpp::ParameterList:
+ Collaboration diagram for bpp::ParameterList:

Public Member Functions

 ParameterList ()
 Build a new ParameterList object. More...
 
 ParameterList (const ParameterList &pl)
 Copy constructor. More...
 
ParameterListoperator= (const ParameterList &pl)
 
ParameterListclone () const
 Create a copy of this object and send a pointer to it. More...
 
virtual ~ParameterList ()
 
size_t size () const
 
virtual const Parameteroperator[] (size_t i) const
 
virtual Parameteroperator[] (size_t i)
 
virtual const ParametergetParameter (const std::string &name) const throw (ParameterNotFoundException)
 Get the parameter with name name. More...
 
virtual double getParameterValue (const std::string &name) const throw (ParameterNotFoundException)
 Get the value of the parameter with name name. More...
 
virtual ParametergetParameter (const std::string &name) throw (ParameterNotFoundException)
 Get the parameter with name name. More...
 
virtual ParameterList subList (const std::vector< std::string > &names) const throw (ParameterNotFoundException)
 Get given parameters as a sublist. More...
 
virtual ParameterList subList (const std::string &name) const throw (ParameterNotFoundException)
 Get given parameter as a sublist. More...
 
virtual ParameterList subList (const std::vector< size_t > &parameters) const
 Get given parameters as a sublist. More...
 
virtual ParameterList subList (size_t parameter) const
 Get given parameter as a sublist. More...
 
virtual ParameterList getCommonParametersWith (const ParameterList &params) const
 Get the sublist containing all common parameter between this list and pl. More...
 
virtual std::vector< std::string > getParameterNames () const
 Get all parameter names in the list. More...
 
virtual std::vector< std::string > getMatchingParameterNames (const std::string &pattern) const
 Get all parameter names matching with the given name. Up to now, only "*" jokers are available. More...
 
virtual void addParameter (const Parameter &param) throw (ParameterException)
 Add a new parameter at the end of the list. More...
 
virtual void addParameter (Parameter *param) throw (ParameterException)
 Add a new parameter at the end of the list. More...
 
virtual void setParameter (size_t index, const Parameter &param) throw (IndexOutOfBoundsException)
 Change given parameter. More...
 
virtual void addParameters (const ParameterList &params) throw (ParameterException)
 Add new parameters at the end of the list. More...
 
virtual void includeParameters (const ParameterList &params)
 Add parameters to the list. If the parameter already exists, only the value is updated, otherwise the new parameter is added at the end of the list. More...
 
virtual 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...
 
virtual void setAllParametersValues (const ParameterList &params) throw (ParameterNotFoundException, ConstraintException)
 Set the parameters to be equals to params. More...
 
virtual void setParametersValues (const ParameterList &params)
 Update the parameters from the ones in params that have matching names. More...
 
A string name

Returns true if the Parameter of the given name exists.

virtual bool hasParameter (const std::string &name) const
 
virtual bool testParametersValues (const ParameterList &params) const
 Tests the parameters from params. More...
 
virtual bool matchParametersValues (const ParameterList &params, std::vector< size_t > *updatedParameters=0) throw (ConstraintException)
 Update the parameters from params. More...
 
virtual void setAllParameters (const ParameterList &params) throw (ParameterNotFoundException)
 Set the parameters to be equals to params. More...
 
virtual void setParameters (const ParameterList &params) throw (ParameterNotFoundException)
 Update the parameters from params. More...
 
virtual void matchParameters (const ParameterList &params)
 Update the parameters from params. More...
 
virtual void deleteParameter (const std::string &name) throw (ParameterNotFoundException)
 Delete a parameter from the list. More...
 
virtual void deleteParameters (const std::vector< std::string > &names, bool mustExist=true) throw (ParameterNotFoundException)
 Delete several parameters from the list. More...
 
virtual void deleteParameter (size_t index) throw (IndexOutOfBoundsException)
 Delete a parameter from the list. More...
 
virtual void deleteParameters (const std::vector< size_t > &indices) throw (IndexOutOfBoundsException)
 Delete several parameters from the list. More...
 
virtual size_t whichParameterHasName (const std::string &name) const throw (ParameterNotFoundException)
 Get the position of a given parameter according to its name. More...
 
virtual void printParameters (OutputStream &out) const
 Print all parameters. More...
 
virtual void printParameters (std::ostream &out) const
 
virtual void reset ()
 Reset the list: delete all parameters. More...
 

Private Attributes

std::vector< Parameter * > parameters_
 

Detailed Description

The parameter list object.

Author
Julien Dutheil, Laurent Gueguen This is a vector of Parameter with a few additional methods, mainly for giving name access.

Definition at line 61 of file ParameterList.h.

Constructor & Destructor Documentation

◆ ParameterList() [1/2]

bpp::ParameterList::ParameterList ( )
inline

Build a new ParameterList object.

Definition at line 71 of file ParameterList.h.

Referenced by clone().

◆ ParameterList() [2/2]

ParameterList::ParameterList ( const ParameterList pl)

Copy constructor.

All parameters in the list will be cloned.

Copy constructor:

Definition at line 51 of file ParameterList.cpp.

References parameters_, and size().

◆ ~ParameterList()

ParameterList::~ParameterList ( )
virtual

Destructor:

Definition at line 82 of file ParameterList.cpp.

References reset().

Member Function Documentation

◆ addParameter() [1/2]

◆ addParameter() [2/2]

void ParameterList::addParameter ( Parameter param)
throw (ParameterException
)
virtual

Add a new parameter at the end of the list.

This function is more efficient than its reference counterpart, as it avoid an object copy. The ParameterList will own the pointer after addition, if it is successful.

Parameters
paramA ppointer toward the parameter to add to the list.

Definition at line 233 of file ParameterList.cpp.

◆ addParameters()

void ParameterList::addParameters ( const ParameterList params)
throw (ParameterException
)
virtual

Add new parameters at the end of the list.

Parameters
paramsThe parameter list containing the new paramters to add to the list.

Definition at line 264 of file ParameterList.cpp.

Referenced by bpp::AbstractParametrizable::addParameters_(), and bpp::AbstractParameterAliasable::addParameters_().

◆ clone()

ParameterList* bpp::ParameterList::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.

Definition at line 82 of file ParameterList.h.

References ParameterList().

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::FullHmmTransitionMatrix::FullHmmTransitionMatrix(), includeParameters(), bpp::FullHmmTransitionMatrix::setTransitionProbabilities(), and subList().

◆ deleteParameter() [1/2]

void ParameterList::deleteParameter ( const std::string &  name)
throw (ParameterNotFoundException
)
virtual

Delete a parameter from the list.

Parameters
nameThe name of the parameter to delete from the list.

Definition at line 446 of file ParameterList.cpp.

References bpp::Parameter::getName().

Referenced by bpp::AbstractParametrizable::deleteParameter_(), and bpp::AbstractParameterAliasable::deleteParameter_().

◆ deleteParameter() [2/2]

void ParameterList::deleteParameter ( size_t  index)
throw (IndexOutOfBoundsException
)
virtual

Delete a parameter from the list.

Parameters
indexThe position of the parameter to delete in the list.

Definition at line 481 of file ParameterList.cpp.

◆ deleteParameters() [1/2]

void ParameterList::deleteParameters ( const std::vector< std::string > &  names,
bool  mustExist = true 
)
throw (ParameterNotFoundException
)
virtual

Delete several parameters from the list.

Parameters
namesThe names of the parameters to delete from the list.
mustExistIf true, an exception is thrown if a name does not match an extant parameter.

Definition at line 462 of file ParameterList.cpp.

Referenced by bpp::AbstractParametrizable::deleteParameters_().

◆ deleteParameters() [2/2]

void ParameterList::deleteParameters ( const std::vector< size_t > &  indices)
throw (IndexOutOfBoundsException
)
virtual

Delete several parameters from the list.

Parameters
indicesThe positions of the parameters to delete in the list. Duplicated positions will be considered only one time.

Definition at line 490 of file ParameterList.cpp.

◆ getCommonParametersWith()

ParameterList ParameterList::getCommonParametersWith ( const ParameterList params) const
virtual

Get the sublist containing all common parameter between this list and pl.

Parameters
paramsThe list to compare to.
Returns
A list with all common parameters.

Definition at line 162 of file ParameterList.cpp.

References bpp::Parameter::clone(), bpp::Parameter::getName(), hasParameter(), parameters_, and size().

◆ getMatchingParameterNames()

vector< string > ParameterList::getMatchingParameterNames ( const std::string &  pattern) const
virtual

Get all parameter names matching with the given name. Up to now, only "*" jokers are available.

Parameters
patterna pattern of name
Returns
A vector of matching names

Definition at line 190 of file ParameterList.cpp.

References bpp::StringTokenizer::hasMoreToken(), bpp::StringTokenizer::nextToken(), parameters_, and size().

◆ getParameter() [1/2]

const Parameter & ParameterList::getParameter ( const std::string &  name) const
throw (ParameterNotFoundException
)
virtual

Get the parameter with name name.

Parameters
nameThe name of the parameter to look for.
Returns
A const reference toward the parameter with name name.
Exceptions
ParameterNotFoundExceptionIf no parameter with the given name is found.

Definition at line 89 of file ParameterList.cpp.

References bpp::Parameter::getName().

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::ParametersStopCondition::getCurrentTolerance(), bpp::AbstractParametrizable::getParameter(), bpp::AbstractParametrizable::getParameter_(), bpp::ParametersStopCondition::isToleranceReached(), matchParameters(), setParametersValues(), and testParametersValues().

◆ getParameter() [2/2]

Parameter & ParameterList::getParameter ( const std::string &  name)
throw (ParameterNotFoundException
)
virtual

Get the parameter with name name.

Parameters
nameThe name of the parameter to look for.
Returns
A reference toward the parameter with name name.
Exceptions
ParameterNotFoundExceptionIf no parameter with the given name is found.

Definition at line 111 of file ParameterList.cpp.

References bpp::Parameter::getName().

◆ getParameterNames()

std::vector< std::string > ParameterList::getParameterNames ( ) const
virtual

Get all parameter names in the list.

Returns
A vector with all names in the same order as the parameters in the list.

Definition at line 178 of file ParameterList.cpp.

References parameters_, and size().

Referenced by bpp::NumTools::computeHessianMatrix(), bpp::BppODiscreteDistributionFormat::read(), and bpp::BppODiscreteDistributionFormat::write().

◆ getParameterValue()

double ParameterList::getParameterValue ( const std::string &  name) const
throw (ParameterNotFoundException
)
virtual

Get the value of the parameter with name name.

Parameters
nameThe name of the parameter to look for.
Returns
A value of the parameter with name name.
Exceptions
ParameterNotFoundExceptionIf no parameter with the given name is found.

Definition at line 100 of file ParameterList.cpp.

References bpp::Parameter::getName(), and bpp::Parameter::getValue().

Referenced by bpp::AbstractOptimizer::getParameterValue(), bpp::TwoPointsNumericalDerivative::updateDerivatives(), bpp::ThreePointsNumericalDerivative::updateDerivatives(), and bpp::FivePointsNumericalDerivative::updateDerivatives().

◆ hasParameter()

◆ includeParameters()

void ParameterList::includeParameters ( const ParameterList params)
virtual

Add parameters to the list. If the parameter already exists, only the value is updated, otherwise the new parameter is added at the end of the list.

Parameters
paramsThe parameter list containing the new paramters to add to the list.

Definition at line 251 of file ParameterList.cpp.

References clone(), hasParameter(), parameters_, setParameterValue(), and size().

◆ matchParameters()

void ParameterList::matchParameters ( const ParameterList params)
virtual

Update the parameters from params.

Only common parameters with params will be updated.

Parameters
paramsA list of parameters.
See also
setParameters(), setAllParameters()

Definition at line 433 of file ParameterList.cpp.

References getParameter(), hasParameter(), and parameters_.

◆ matchParametersValues()

bool ParameterList::matchParametersValues ( const ParameterList params,
std::vector< size_t > *  updatedParameters = 0 
)
throw (ConstraintException
)
virtual

Update the parameters from params.

Only common parameters with params will be updated.

Parameters
paramsA list of parameters.
updatedParametersAn optional pointer toward a vector which will store the indices of parameters for which a value has changed. Indices are relative on the input parameter list "params".
Returns
true iff a least one parameter value has been changed.
See also
setParameters(), setAllParameters()

Definition at line 363 of file ParameterList.cpp.

References bpp::Parameter::getConstraint(), bpp::Parameter::getValue(), bpp::Parameter::hasConstraint(), bpp::Constraint::isCorrect(), and bpp::Parameter::setValue().

Referenced by bpp::SimpleNewtonMultiDimensions::doStep(), bpp::SimpleMultiDimensions::doStep(), bpp::MetaOptimizer::doStep(), bpp::AbstractParameterAliasable::fireParameterChanged(), bpp::AbstractParametrizable::matchParametersValues(), and bpp::AbstractOptimizer::step().

◆ operator=()

ParameterList & ParameterList::operator= ( const ParameterList pl)

Assignation operator:

Definition at line 63 of file ParameterList.cpp.

References parameters_, reset(), and size().

◆ operator[]() [1/2]

virtual const Parameter& bpp::ParameterList::operator[] ( size_t  i) const
inlinevirtual
Returns
The parameter at a given position.
Warning
No check is performed on the validity of the index given as input!

Definition at line 96 of file ParameterList.h.

References parameters_.

◆ operator[]() [2/2]

virtual Parameter& bpp::ParameterList::operator[] ( size_t  i)
inlinevirtual

Definition at line 97 of file ParameterList.h.

References parameters_.

◆ printParameters() [1/2]

void ParameterList::printParameters ( OutputStream out) const
virtual

Print all parameters.

Definition at line 515 of file ParameterList.cpp.

References bpp::OutputStream::endLine(), parameters_, and size().

Referenced by printParameters().

◆ printParameters() [2/2]

virtual void bpp::ParameterList::printParameters ( std::ostream &  out) const
inlinevirtual

Definition at line 377 of file ParameterList.h.

References printParameters().

◆ reset()

void ParameterList::reset ( )
virtual

Reset the list: delete all parameters.

Definition at line 529 of file ParameterList.cpp.

References parameters_, and size().

Referenced by operator=(), bpp::AbstractParametrizable::resetParameters_(), bpp::AbstractParameterAliasable::resetParameters_(), and ~ParameterList().

◆ setAllParameters()

void ParameterList::setAllParameters ( const ParameterList params)
throw (ParameterNotFoundException
)
virtual

Set the parameters to be equals to params.

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

Parameters
paramsA list with all parameters.
See also
setParameters(), matchParameters();

Definition at line 399 of file ParameterList.cpp.

◆ setAllParametersValues()

void ParameterList::setAllParametersValues ( const ParameterList params)
throw (ParameterNotFoundException,
ConstraintException
)
virtual

Set the parameters to be equals to params.

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

Parameters
paramsA list with all parameters.
See also
setParameters(), matchParameters();
Exceptions
ParameterNotFoundExceptionIf at least one name does not correspond to a parameter in the list.
ConstraintExceptionIf one value is incorrect (and the two parameter list do not have the same constraints).

Definition at line 284 of file ParameterList.cpp.

References bpp::Parameter::getValue(), and bpp::Parameter::setValue().

Referenced by bpp::AbstractParametrizable::setAllParametersValues().

◆ setParameter()

void ParameterList::setParameter ( size_t  index,
const Parameter param 
)
throw (IndexOutOfBoundsException
)
virtual

Change given parameter.

Parameters
indexThe position of the parameter to alter.
paramThe parameter to add to the list.
Exceptions
IndexOutOfBoundsExceptionif the index is not valid.

Definition at line 242 of file ParameterList.cpp.

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

◆ setParameters()

void ParameterList::setParameters ( const ParameterList params)
throw (ParameterNotFoundException
)
virtual

Update the parameters from params.

params must be a subset of all parameters available.

Parameters
paramsA list containing all parameters to update.
See also
setAllParameters(), matchParameters()

Definition at line 410 of file ParameterList.cpp.

Referenced by bpp::TwoPointsNumericalDerivative::updateDerivatives(), bpp::ThreePointsNumericalDerivative::updateDerivatives(), and bpp::FivePointsNumericalDerivative::updateDerivatives().

◆ setParametersValues()

void ParameterList::setParametersValues ( const ParameterList params)
virtual

Update the parameters from the ones in params that have matching names.

Parameters
paramsA list containing all parameters to update.
See also
setAllParameters(), matchParameters()
Exceptions
ConstraintExceptionIf one value is incorrect (and the two parameter list do not have the same constraints).

Definition at line 305 of file ParameterList.cpp.

References bpp::Parameter::getConstraint(), getParameter(), bpp::Parameter::getValue(), bpp::Parameter::hasConstraint(), hasParameter(), bpp::Constraint::isCorrect(), parameters_, and bpp::Parameter::setValue().

Referenced by bpp::AbstractParametrizable::setParametersValues().

◆ setParameterValue()

void ParameterList::setParameterValue ( const std::string &  name,
double  value 
)
throw (ParameterNotFoundException,
ConstraintException
)
virtual

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 with the given name is found in the list.
ConstraintExceptionIf the value is incorrect.

Definition at line 275 of file ParameterList.cpp.

References bpp::Parameter::setValue().

Referenced by bpp::FunctionTools::computeGrid(), bpp::DirichletDiscreteDistribution::discretize(), includeParameters(), and bpp::AbstractParametrizable::setParameterValue().

◆ size()

size_t bpp::ParameterList::size ( ) const
inline
Returns
The number of parameters in the list.

Definition at line 90 of file ParameterList.h.

References parameters_.

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::AbstractOptimizer::autoParameter(), bpp::NumTools::computeHessianMatrix(), bpp::AbstractParametrizable::deleteParameter_(), bpp::ConjugateGradientMultiDimensions::doStep(), bpp::BfgsMultiDimensions::doStep(), bpp::PowellMultiDimensions::doStep(), bpp::FullHmmTransitionMatrix::fireParameterChanged(), bpp::ParametrizableCollection< N >::fireParameterChanged(), bpp::FullHmmTransitionMatrix::FullHmmTransitionMatrix(), getCommonParametersWith(), bpp::ParametersStopCondition::getCurrentTolerance(), bpp::NumCalcApplicationTools::getDefaultValue(), getMatchingParameterNames(), bpp::AbstractParameterAliasable::getNumberOfIndependentParameters(), bpp::DirectionFunction::getNumberOfParameters(), bpp::AbstractParametrizable::getNumberOfParameters(), bpp::AbstractParametrizable::getParameter_(), getParameterNames(), hasParameter(), bpp::AbstractOptimizer::ignoreConstraints(), includeParameters(), bpp::BppODiscreteDistributionFormat::initialize_(), bpp::ParametersStopCondition::isToleranceReached(), bpp::OneDimensionOptimizationTools::lineMinimization(), bpp::OneDimensionOptimizationTools::lineSearch(), operator=(), bpp::BackupListener::optimizationStepPerformed(), ParameterList(), bpp::ParametersStopCondition::ParametersStopCondition(), printParameters(), bpp::AbstractOptimizer::printPoint(), bpp::ParametrizableCollection< N >::removeObject(), reset(), bpp::BfgsMultiDimensions::setDirection(), bpp::AbstractParameterAliasable::setNamespace(), bpp::FullHmmTransitionMatrix::setTransitionProbabilities(), subList(), and bpp::BppOParametrizableFormat::write().

◆ subList() [1/4]

ParameterList ParameterList::subList ( const std::vector< std::string > &  names) const
throw (ParameterNotFoundException
)
virtual

Get given parameters as a sublist.

Parameters
namesName of the parameters to be included in the list.
Returns
A list with all parameters specified.
Exceptions
ParameterNotFoundExceptionIf at least one name does not correspond to a parameter in the list.

Definition at line 122 of file ParameterList.cpp.

References addParameter().

Referenced by bpp::FunctionTools::computeGrid(), bpp::ReparametrizationFunctionWrapper::setParameters(), bpp::AbstractParametrizable::setParameterValue(), bpp::AbstractNumericalDerivative::setParameterValue(), bpp::TwoPointsNumericalDerivative::updateDerivatives(), bpp::ThreePointsNumericalDerivative::updateDerivatives(), bpp::FivePointsNumericalDerivative::updateDerivatives(), and bpp::BppOParametrizableFormat::write().

◆ subList() [2/4]

ParameterList ParameterList::subList ( const std::string &  name) const
throw (ParameterNotFoundException
)
virtual

Get given parameter as a sublist.

Parameters
nameName of the parameter to be included in the list.
Returns
A list with the parameter specified.
Exceptions
ParameterNotFoundExceptionIf no parameter with the given name is found.

Definition at line 134 of file ParameterList.cpp.

References addParameter().

◆ subList() [3/4]

ParameterList ParameterList::subList ( const std::vector< size_t > &  parameters) const
virtual

Get given parameters as a sublist.

Parameters
parametersPositions of the parameters to be included in the list.
Returns
A list with all parameters specified.

Definition at line 143 of file ParameterList.cpp.

References parameters_, and size().

◆ subList() [4/4]

ParameterList ParameterList::subList ( size_t  parameter) const
virtual

Get given parameter as a sublist.

Parameters
parameterPosition of the parameters to be included in the list.
Returns
A list with the parameter specified.

Definition at line 154 of file ParameterList.cpp.

References clone(), parameters_, and size().

◆ testParametersValues()

bool ParameterList::testParametersValues ( const ParameterList params) const
virtual

Tests the parameters from params.

Only common parameters with params are compared.

Parameters
paramsA list of parameters.
Returns
true iff a least one parameter value is different.

Definition at line 333 of file ParameterList.cpp.

References bpp::Parameter::getConstraint(), getParameter(), bpp::Parameter::getValue(), bpp::Parameter::hasConstraint(), hasParameter(), bpp::Constraint::isCorrect(), and parameters_.

◆ whichParameterHasName()

size_t ParameterList::whichParameterHasName ( const std::string &  name) const
throw (ParameterNotFoundException
)
virtual

Get the position of a given parameter according to its name.

Parameters
nameThe name of the parameter to look for.
Returns
The position of the parameter if found. If several parameters exist with the given name, the position of the first one is returned.
Exceptions
ParameterNotFoundExceptionIf no parameter with the given name is found.

Definition at line 505 of file ParameterList.cpp.

Member Data Documentation

◆ parameters_


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