IMP logo
Public Member Functions | Protected Member Functions
IMP::Optimizer Class Reference

Detailed Description

Base class for all optimizers.

The Optimizer maintains a list of OptimizerStates which are updated each time the conformation is changed.

The optimizers have one key method Optimizer::optimize() which takes the number of steps to perform. The optimizers can have other stopping conditions as appropriate.

A typical optimization loop proceeds by:

Implementors
Developers who wish to implement a Optimizer should inherit from this class and use the IMP_OPTIMIZER() macro to help define the needed functions. Lamentably, we do not provide an example.
+ Inheritance diagram for IMP::Optimizer:

List of all members.

Public Member Functions

 Optimizer (Model *m, std::string name="Optimizer %1%")
double get_last_score () const
 Return the score found in the last evaluate.
Modelget_model () const
 Get the model being optimized.
bool get_stop_on_good_score () const
double optimize (unsigned int max_steps)
void set_model (Model *m)
 Set the model being optimized.
void set_restraints (const RestraintsTemp &rs)
 The optimizer can be told to use only a subset of the restraints to compute scores.
void set_stop_on_good_score (bool tf)
virtual void show (std::ostream &out=std::cout) const
 Print info about the optimizer state.

Macros to aid with implementing object classes

These macros are here to aid with implementing classes that inherit from the various abstract base classes in the kernel. Each IMP object class should use one of the IMP_OBJECT(), IMP_RESTRAINT() etc. macros in the body of its declaration as well as an IMP_OBJECTS() invocation on the namespace level (and an IMP_SWIG_OBJECTS() call in the corresponding swig file). See Value and Objects for a description of what it means to be an object vs a value in IMP.

Each IMP_OBJECT()/IMP_RESTRAINT()-style macro declares/defines the set of needed functions. The declared functions should be defined in the associated .cpp file. By using the macros, you ensure that your class gets the names of the functions correct and it makes it easier to update your class if the functions should change.

All of the IMP_OBJECT()/IMP_RESTRAINT()-style macros define the following methods:

  • IMP::Object::get_version_info()
  • an empty virtual destructor

In addition, they all declare:

  • IMP::Object::do_show()

For all macros, the Name parameter is the name of the class being implemented and the version_info parameter is the IMP::VersionInfo to use (probably get_version_info()).

#define IMP_OPTIMIZER(Name)
 Define the basic things you need for an Optimizer.

States

The stored OptimizerState objects are updated each time the Optimizer decides to accept a new configuration of the Model. To manipulate the list of optimizer states use the methods below.

void remove_optimizer_state (OptimizerState *d)
template<class F >
void remove_optimizer_states_if (const F &f)
template<class List >
void remove_optimizer_states (List d)
template<class List >
void set_optimizer_states (List ps)
template<class List >
void set_optimizer_states_order (List ps)
unsigned int add_optimizer_state (OptimizerState *obj)
template<class List >
void add_optimizer_states (List objs)
void clear_optimizer_states ()
unsigned int get_number_of_optimizer_states () const
bool get_has_optimizer_states () const
OptimizerStateget_optimizer_state (unsigned int i) const
OptimizerStates get_optimizer_states () const
void reserve_optimizer_states (unsigned int sz)
OptimizerStateIterator optimizer_states_begin ()
OptimizerStateIterator optimizer_states_end ()
OptimizerStateConstIterator optimizer_states_begin () const
OptimizerStateConstIterator optimizer_states_end () const

Methods for getting and setting optimized attributes

Optimizers don't have to go through the particles themselves looking for values to optimize unless they care about special properties of the optimized values. Instead they can iterate through the list of optimized attributes, each of which is identified by a FloatIndex. With these FloatIndex objects they can get and set the values and derivatives as needed.

typedef Model::FloatIndex FloatIndex
typedef vector< FloatIndex > FloatIndexes
vector< Model::FloatIndex > get_optimized_attributes () const
void set_value (Model::FloatIndex fi, double v) const
Float get_value (Model::FloatIndex fi) const
Float get_derivative (Model::FloatIndex fi) const

Methods to get and set scaled optimizable values

Certain optimizers benefit from having all the optimized values scaled to vary over a similar range. These accessors use the Model::get_range ranges to scale the values before returning them and unscale them before setting them.

void set_scaled_value (Model::FloatIndex fi, Float v) const
double get_scaled_value (Model::FloatIndex fi) const
double get_scaled_derivative (Model::FloatIndex fi) const
void clear_range_cache ()
 Clear the cache of range information. Do this at the start of optimization.

Protected Member Functions

virtual double do_optimize (unsigned int ns)=0
 override this function to do actual optimization
double evaluate (bool compute_derivatives) const
double evaluate_if_below (bool compute_derivatives, double max) const
RestraintsTemp get_restraints () const
 Return the restraint sets used in evaluation.
void update_states () const
 Update optimizer state, should be called at each successful step.
double width (FloatKey k) const

Member Function Documentation

void IMP::Optimizer::clear_range_cache ( ) [protected]

Clear the cache of range information. Do this at the start of optimization.

virtual double IMP::Optimizer::do_optimize ( unsigned int  ns) [protected, pure virtual]

override this function to do actual optimization

double IMP::Optimizer::evaluate ( bool  compute_derivatives) const [protected]

Evaluate the score of the model (or of a subset of the restraints if desired.

double IMP::Optimizer::evaluate_if_below ( bool  compute_derivatives,
double  max 
) const [protected]

Evaluate the score of the model (or of a subset of the restraints if desired.

double IMP::Optimizer::get_last_score ( ) const

Return the score found in the last evaluate.

Model* IMP::Optimizer::get_model ( ) const

Get the model being optimized.

RestraintsTemp IMP::Optimizer::get_restraints ( ) const [protected]

Return the restraint sets used in evaluation.

Use IMP::get_restraints() to get the actual restraints used.

double IMP::Optimizer::optimize ( unsigned int  max_steps)

Optimize the model

Parameters:
[in]max_stepsThe maximum number of iterations of the optimizer to perform. Increasing this number will generally make the optimizer spend more time searching for a solution, but beyond that, the details of what changes will vary.
Returns:
The final score.
void IMP::Optimizer::set_model ( Model m)

Set the model being optimized.

Note:
The model is not owned by the optimizer and so is not deleted when the optimizer is deleted. Further, the Optimizer does not prevent the model from being deleted when all Python references go away.
void IMP::Optimizer::set_restraints ( const RestraintsTemp &  rs)

The optimizer can be told to use only a subset of the restraints to compute scores.

These restraints must all be part of the model. Passing an empty list will revert to using the whole model.

void IMP::Optimizer::set_stop_on_good_score ( bool  tf)

Optimization can be stopped if all the thresholds in the Model are satisfied.

virtual void IMP::Optimizer::show ( std::ostream &  out = std::cout) const [virtual]

Print info about the optimizer state.

It should end in a newline

Reimplemented from IMP::base::Object.

void IMP::Optimizer::update_states ( ) const [protected]

Update optimizer state, should be called at each successful step.


Friends And Related Function Documentation

#define IMP_OPTIMIZER (   Name) [related]
Value:
IMP_IMPLEMENT(virtual Float do_optimize(unsigned int max_steps));     \
  IMP_OBJECT(Name)

Define the basic things you need for an Optimizer.

In addition to the methods done by IMP_OBJECT, it declares


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

Generated on Fri Feb 10 2012 23:36:21 for IMP by doxygen 1.7.5.1