IMP  2.2.0
The Integrative Modeling Platform
core/ConjugateGradients.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/ConjugateGradients.h
3  * \brief Simple conjugate gradients optimizer.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPCORE_CONJUGATE_GRADIENTS_H
10 #define IMPCORE_CONJUGATE_GRADIENTS_H
11 
12 #include <IMP/core/core_config.h>
13 
14 #include <IMP/AttributeOptimizer.h>
15 
16 IMPCORE_BEGIN_NAMESPACE
17 
18 //! Simple conjugate gradients optimizer.
19 /** Algorithm is as per Shanno and Phua, ACM Transactions On Mathematical
20  Software 6 (December 1980), 618-622
21 
22  Conjugate gradients optimization is sensitive to the scales of the
23  derivatives of the various attributes being optimized. By default,
24  the scales are estimated from the range of values found for the attribute
25  upon initialization. These estimates can be viewed either by calling
26  kernel::Model::get_range(my_float_key) or by turning on TERSE logging and
27  looking
28  at logged messages. If this estimate does not accurately reflect the
29  scale, then you can use kernel::Model::set_range to set a more accurate
30  range
31  for the parameters.
32 */
33 class IMPCOREEXPORT ConjugateGradients : public AttributeOptimizer {
34  public:
36  std::string name = "ConjugateGradients%1%");
37 
38  //! Set the threshold for the minimum gradient
39  void set_gradient_threshold(Float t) { threshold_ = t; }
40 
41 #ifndef IMP_DOXYGEN
42  void set_threshold(Float t) { set_gradient_threshold(t); }
43 #endif
44 
45  //! Limit how far anything can change each time step
46  void set_max_change(Float t) { max_change_ = t; }
47 
48  virtual Float do_optimize(unsigned int max_steps) IMP_OVERRIDE;
50 
51  private:
52  typedef double NT;
53 
54  // Handle optimization failing badly
55  void failure();
56 
57  NT get_score(base::Vector<FloatIndex> float_indices, base::Vector<NT> &x,
58  base::Vector<NT> &dscore);
59  bool line_search(base::Vector<NT> &x, base::Vector<NT> &dx, NT &alpha,
60  const base::Vector<FloatIndex> &float_indices, int &ifun,
61  NT &f, NT &dg, NT &dg1, int max_steps,
62  const base::Vector<NT> &search,
63  const base::Vector<NT> &estimate);
64  Float threshold_;
65  Float max_change_;
66 };
67 
68 IMPCORE_END_NAMESPACE
69 
70 #endif /* IMPCORE_CONJUGATE_GRADIENTS_H */
Simple conjugate gradients optimizer.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
Import IMP/kernel/AttributeOptimizer.h in the namespace.
void set_gradient_threshold(Float t)
Set the threshold for the minimum gradient.
void set_max_change(Float t)
Limit how far anything can change each time step.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72