IMP  2.1.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-2013 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:
35  /** \deprecated_at{2.1} Use the constructor that takes a kernel::Model. */
36  IMPCORE_DEPRECATED_FUNCTION_DECL(2.1)
39  std::string name = "ConjugateGradients%1%");
40 
41  //! Set the threshold for the minimum gradient
42  void set_gradient_threshold(Float t) { threshold_ = t; }
43 
44 #ifndef IMP_DOXYGEN
45  void set_threshold(Float t) { set_gradient_threshold(t); }
46 #endif
47 
48  //! Limit how far anything can change each time step
49  void set_max_change(Float t) { max_change_ = t; }
50 
51  virtual Float do_optimize(unsigned int max_steps) IMP_OVERRIDE;
53 
54  private:
55 
56  typedef double NT;
57 
58  // Handle optimization failing badly
59  void failure();
60 
61  NT get_score(base::Vector<FloatIndex> float_indices, base::Vector<NT> &x,
62  base::Vector<NT> &dscore);
63  bool line_search(base::Vector<NT> &x, base::Vector<NT> &dx, NT &alpha,
64  const base::Vector<FloatIndex> &float_indices, int &ifun,
65  NT &f, NT &dg, NT &dg1, int max_steps,
66  const base::Vector<NT> &search,
67  const base::Vector<NT> &estimate);
68  Float threshold_;
69  Float max_change_;
70 };
71 
72 IMPCORE_END_NAMESPACE
73 
74 #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.