IMP  2.0.0
The Integrative Modeling Platform
TruncatedHarmonic.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/TruncatedHarmonic.h \brief Truncated harmonic.
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  */
6 
7 #ifndef IMPCORE_TRUNCATED_HARMONIC_H
8 #define IMPCORE_TRUNCATED_HARMONIC_H
9 
10 #include <IMP/core/core_config.h>
11 #include "internal/truncated_harmonic.h"
12 #include <IMP/UnaryFunction.h>
13 #include <IMP/base/object_macros.h>
14 #include <IMP/utility.h>
15 
16 IMPCORE_BEGIN_NAMESPACE
17 
18 enum BoundDirection {LOWER, BOTH, UPPER};
19 
20 //! A function that is harmonic over an interval.
21 /** This function is harmonic between center and threshold and then
22  asymptotically converges to the limit value.
23 
24  The function form above the threshold is currently limit-b/(x-o)
25  where x is the offset from the center and b,o are constants chosen to
26  make the function smooth and continuous. This form may change
27  without notice unless someone tells us it is important that it does
28  not.
29 
30  \param[in] DIRECTION Whether to be an upper bound, lower bound, or
31  both directions. It should be one of the BoundDirection enum
32  values. If it is LOWER, than the function is 0 for all values above
33  the passed center.
34  \see Harmonic
35  \see HarmonicLowerBound
36  \see HarmonicUpperBound
37  */
38 template <int DIRECTION>
40 public:
41  /** \param[in] center The center point for the harmonic.
42  \param[in] k The spring constant for the harmonic.
43  \param[in] threshold How far the harmonic term extends from the center.
44  \param[in] limit The value to which the function converges above the
45  threshold.
46 
47  \note I don't like having 4 floats on the initializer list, but
48  don't really see an alternative. There are a few sanity checks, so
49  the order is a bit hard to get wrong.
50  */
52  Float k, Float threshold,
53  Float limit):
54  d_(center, k, threshold, limit){
55  }
56  /** Set limit to a reasonable value. */
58  Float k, Float threshold):
59  d_(center, k, threshold, k*square(threshold-center)){
60  }
61  virtual DerivativePair evaluate_with_derivative(double feature)
62  const IMP_OVERRIDE {
63  return DerivativePair(evaluate(feature),
64  ((DIRECTION == LOWER && (feature > d_.c_))
65  || (DIRECTION == UPPER && (feature < d_.c_)))?
66  0: d_.evaluate_with_derivative(feature).second);
67  }
68  virtual double evaluate(double feature) const IMP_OVERRIDE {
69  return ((DIRECTION == LOWER && (feature > d_.c_))
70  || (DIRECTION == UPPER && (feature < d_.c_)))?
71  0: d_.evaluate(feature);
72  }
74 private:
75  internal::TruncatedHarmonicData d_;
76 };
77 
78 //! A specialization for the upper bound
80 //! A specialization for the lower bound
82 //! A specialization
84 
85 IMPCORE_END_NAMESPACE
86 
87 #endif /* IMPCORE_TRUNCATED_HARMONIC_H */