bpp-core  2.4.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 std::shared_ptr< Parameter > & getSharedParameter (size_t i) const
 
virtual std::shared_ptr< Parameter > & getSharedParameter (size_t i)
 
virtual const ParametergetParameter (const std::string &name) const
 Get the parameter with name name. More...
 
virtual const std::shared_ptr< Parameter > & getSharedParameter (const std::string &name) const
 Get the parameter with name name as a shared pointer. More...
 
virtual double getParameterValue (const std::string &name) const
 Get the value of the parameter with name name. More...
 
virtual ParametergetParameter (const std::string &name)
 Get the parameter with name name. More...
 
virtual std::shared_ptr< Parameter > & getSharedParameter (const std::string &name)
 Get the parameter with name name as a shared pointer. More...
 
virtual ParameterList subList (const std::vector< std::string > &names) const
 Get given parameters as a sublist. More...
 
virtual ParameterList subList (const std::string &name) const
 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)
 Add a new parameter at the end of the list. More...
 
virtual void addParameter (Parameter *param)
 Add a new parameter at the end of the list. More...
 
virtual void shareParameter (const std::shared_ptr< Parameter > &param)
 Share a parameter at the end of the list. More...
 
virtual void setParameter (size_t index, const Parameter &param)
 Change given parameter. More...
 
virtual void addParameters (const ParameterList &params)
 Add new parameters at the end of the list. More...
 
virtual void shareParameters (const ParameterList &params)
 Share parameters with a given list. They are added the end of this 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)
 Set the value of parameter with name name to be equal to value. More...
 
virtual void setAllParametersValues (const ParameterList &params)
 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)
 Update the parameters from params. More...
 
virtual void setAllParameters (const ParameterList &params)
 Set the parameters to be equals to params. More...
 
virtual void setParameters (const ParameterList &params)
 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)
 Delete a parameter from the list. More...
 
virtual void deleteParameters (const std::vector< std::string > &names, bool mustExist=true)
 Delete several parameters from the list. More...
 
virtual void deleteParameter (size_t index)
 Delete a parameter from the list. More...
 
virtual void deleteParameters (const std::vector< size_t > &indices)
 Delete several parameters from the list. More...
 
virtual size_t whichParameterHasName (const std::string &name) const
 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< std::shared_ptr< 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

bpp::ParameterList::ParameterList ( )
inline

Build a new ParameterList object.

Definition at line 71 of file ParameterList.h.

References operator=().

Referenced by clone().

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 ( )
virtual

Destructor:

Definition at line 79 of file ParameterList.cpp.

References reset().

Referenced by clone().

Member Function Documentation

void ParameterList::addParameter ( Parameter param)
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 269 of file ParameterList.cpp.

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

void ParameterList::addParameters ( const ParameterList params)
virtual

Add new parameters at the end of the list.

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

Definition at line 311 of file ParameterList.cpp.

References addParameter(), and size().

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

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(), and ~ParameterList().

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

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

Delete a parameter from the list.

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

Definition at line 497 of file ParameterList.cpp.

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

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

void ParameterList::deleteParameter ( size_t  index)
virtual

Delete a parameter from the list.

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

Definition at line 532 of file ParameterList.cpp.

References parameters_, and size().

void ParameterList::deleteParameters ( const std::vector< std::string > &  names,
bool  mustExist = true 
)
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 513 of file ParameterList.cpp.

References deleteParameter().

Referenced by bpp::AbstractParametrizable::deleteParameters_(), and getSharedParameter().

void ParameterList::deleteParameters ( const std::vector< size_t > &  indices)
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 541 of file ParameterList.cpp.

References parameters_, and size().

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 197 of file ParameterList.cpp.

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

Referenced by getSharedParameter().

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 225 of file ParameterList.cpp.

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

Referenced by getSharedParameter().

const Parameter & ParameterList::getParameter ( const std::string &  name) const
virtual
Parameter & ParameterList::getParameter ( const std::string &  name)
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 125 of file ParameterList.cpp.

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

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 213 of file ParameterList.cpp.

References parameters_, and size().

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

double ParameterList::getParameterValue ( const std::string &  name) const
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 113 of file ParameterList.cpp.

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

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

virtual const std::shared_ptr<Parameter>& bpp::ParameterList::getSharedParameter ( size_t  i) const
inlinevirtual
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 103 of file ParameterList.h.

Referenced by bpp::AbstractParametrizable::getSharedParameter(), getSharedParameter(), and shareParameters().

const shared_ptr< Parameter > & ParameterList::getSharedParameter ( const std::string &  name) const
virtual

Get the parameter with name name as a shared pointer.

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

Definition at line 99 of file ParameterList.cpp.

References parameters_, and size().

shared_ptr< Parameter > & ParameterList::getSharedParameter ( const std::string &  name)
virtual

Get the parameter with name name as a shared pointer.

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

Definition at line 137 of file ParameterList.cpp.

References parameters_, and size().

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 298 of file ParameterList.cpp.

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

Referenced by getSharedParameter(), and bpp::AbstractParametrizable::includeParameters_().

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 484 of file ParameterList.cpp.

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

Referenced by getSharedParameter().

bool ParameterList::matchParametersValues ( const ParameterList params,
std::vector< size_t > *  updatedParameters = 0 
)
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 417 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::MetaOptimizer::doInit(), bpp::SimpleNewtonMultiDimensions::doStep(), bpp::SimpleMultiDimensions::doStep(), bpp::MetaOptimizer::doStep(), getSharedParameter(), bpp::AbstractParametrizable::matchParametersValues(), and bpp::AbstractOptimizer::step().

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

Assignation operator:

Definition at line 63 of file ParameterList.cpp.

References parameters_, and size().

Referenced by ParameterList().

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.

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

Definition at line 97 of file ParameterList.h.

void ParameterList::printParameters ( OutputStream out) const
virtual

Print all parameters.

Definition at line 566 of file ParameterList.cpp.

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

Referenced by getSharedParameter(), and printParameters().

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

Definition at line 420 of file ParameterList.h.

References printParameters(), and reset().

void ParameterList::reset ( )
virtual

Reset the list: delete all parameters.

Definition at line 580 of file ParameterList.cpp.

References parameters_.

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

void ParameterList::setAllParameters ( const ParameterList params)
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 452 of file ParameterList.cpp.

References getParameter(), and parameters_.

Referenced by getSharedParameter().

void ParameterList::setAllParametersValues ( const ParameterList params)
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 339 of file ParameterList.cpp.

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

Referenced by getSharedParameter(), and bpp::AbstractParametrizable::setAllParametersValues().

void ParameterList::setParameter ( size_t  index,
const Parameter param 
)
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 289 of file ParameterList.cpp.

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

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

void ParameterList::setParameters ( const ParameterList params)
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 462 of file ParameterList.cpp.

References getParameter(), and parameters_.

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

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 359 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 getSharedParameter(), and bpp::AbstractParametrizable::setParametersValues().

void ParameterList::setParameterValue ( const std::string &  name,
double  value 
)
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 331 of file ParameterList.cpp.

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

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

void ParameterList::shareParameters ( const ParameterList params)
virtual

Share parameters with a given list. They are added the end of this list.

Parameters
paramsThe parameter list containing the parameters to share with to the list.

Definition at line 321 of file ParameterList.cpp.

References getSharedParameter(), shareParameter(), and size().

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), getSharedParameter(), and bpp::AbstractParametrizable::shareParameters_().

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

Definition at line 90 of file ParameterList.h.

Referenced by bpp::AbstractParameterAliasable::AbstractParameterAliasable(), addParameters(), bpp::AbstractParameterAliasable::addParameters_(), bpp::AbstractParameterAliasable::aliasParameters(), bpp::AbstractOptimizer::autoParameter(), bpp::NumTools::computeHessianMatrix(), deleteParameter(), bpp::AbstractParametrizable::deleteParameter_(), deleteParameters(), bpp::NewtonOneDimension::doInit(), bpp::SimpleNewtonMultiDimensions::doInit(), bpp::SimpleMultiDimensions::doInit(), bpp::ConjugateGradientMultiDimensions::doInit(), bpp::BfgsMultiDimensions::doInit(), bpp::PowellMultiDimensions::doInit(), bpp::NewtonBacktrackOneDimension::doInit(), bpp::GoldenSectionSearch::doInit(), bpp::BrentOneDimension::doInit(), bpp::DownhillSimplexMethod::doInit(), bpp::ConjugateGradientMultiDimensions::doStep(), bpp::BfgsMultiDimensions::doStep(), bpp::PowellMultiDimensions::doStep(), bpp::ParametrizableCollection< N >::fireParameterChanged(), getCommonParametersWith(), bpp::ParametersStopCondition::getCurrentTolerance(), bpp::NumCalcApplicationTools::getDefaultValue(), getMatchingParameterNames(), bpp::AbstractParameterAliasable::getNumberOfIndependentParameters(), bpp::DirectionFunction::getNumberOfParameters(), bpp::AbstractParametrizable::getNumberOfParameters(), getParameter(), bpp::AbstractParametrizable::getParameter_(), getParameterNames(), bpp::ParametrizableCollection< N >::getParametersForObject(), getParameterValue(), getSharedParameter(), hasParameter(), bpp::AbstractOptimizer::ignoreConstraints(), includeParameters(), bpp::AbstractParameterAliasable::includeParameters_(), bpp::AbstractOptimizer::init(), bpp::BppODiscreteDistributionFormat::initialize_(), bpp::ParametersStopCondition::isToleranceReached(), bpp::OneDimensionOptimizationTools::lineMinimization(), bpp::OneDimensionOptimizationTools::lineSearch(), operator=(), bpp::AbstractParameterAliasable::operator=(), bpp::BackupListener::optimizationStepPerformed(), ParameterList(), bpp::ParametersStopCondition::ParametersStopCondition(), printParameters(), bpp::AbstractOptimizer::printPoint(), bpp::ParametrizableCollection< N >::removeObject(), bpp::BfgsMultiDimensions::setDirection(), setParameter(), bpp::FullHmmTransitionMatrix::setTransitionProbabilities(), shareParameters(), subList(), whichParameterHasName(), and bpp::BppOParametrizableFormat::write().

ParameterList ParameterList::subList ( const std::vector< std::string > &  names) const
virtual
ParameterList ParameterList::subList ( const std::string &  name) const
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 164 of file ParameterList.cpp.

References addParameter(), and getParameter().

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 174 of file ParameterList.cpp.

References parameters_, and size().

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 187 of file ParameterList.cpp.

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

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 387 of file ParameterList.cpp.

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

Referenced by getSharedParameter().

size_t ParameterList::whichParameterHasName ( const std::string &  name) const
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 556 of file ParameterList.cpp.

References parameters_, and size().

Referenced by getSharedParameter().

Member Data Documentation


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