IMP  2.4.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-2015 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 {
19  LOWER,
20  BOTH,
21  UPPER
22 };
23 
24 //! A function that is harmonic over an interval.
25 /** This function is harmonic between center and threshold and then
26  asymptotically converges to the limit value.
27 
28  The function form above the threshold is currently limit-b/(x-o)
29  where x is the offset from the center and b,o are constants chosen to
30  make the function smooth and continuous. This form may change
31  without notice unless someone tells us it is important that it does
32  not.
33 
34  \param[in] DIRECTION Whether to be an upper bound, lower bound, or
35  both directions. It should be one of the BoundDirection enum
36  values. If it is LOWER, than the function is 0 for all values above
37  the passed center.
38  \see Harmonic
39  \see HarmonicLowerBound
40  \see HarmonicUpperBound
41  */
42 template <int DIRECTION>
44  public:
45  /** \param[in] center The center point for the harmonic.
46  \param[in] k The spring constant for the harmonic.
47  \param[in] threshold How far the harmonic term extends from the center.
48  \param[in] limit The value to which the function converges above the
49  threshold.
50 
51  \note I don't like having 4 floats on the initializer list, but
52  don't really see an alternative. There are a few sanity checks, so
53  the order is a bit hard to get wrong.
54  */
55  TruncatedHarmonic(Float center, Float k, Float threshold, Float limit)
56  : d_(center, k, threshold, limit) {}
57  /** Set limit to a reasonable value. */
58  TruncatedHarmonic(Float center, Float k, Float threshold)
59  : d_(center, k, threshold, k * square(threshold)) {}
60  virtual DerivativePair evaluate_with_derivative(double feature) const
61  IMP_OVERRIDE {
62  return DerivativePair(evaluate(feature),
63  ((DIRECTION == LOWER && (feature > d_.c_)) ||
64  (DIRECTION == UPPER && (feature < d_.c_)))
65  ? 0
66  : 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
72  : d_.evaluate(feature);
73  }
75 
76  private:
77  internal::TruncatedHarmonicData d_;
78 };
79 
80 //! A specialization for the upper bound
82 //! A specialization for the lower bound
84 //! A specialization
86 
87 IMPCORE_END_NAMESPACE
88 
89 #endif /* IMPCORE_TRUNCATED_HARMONIC_H */
Various general useful macros for IMP.
A function that is harmonic over an interval.
TruncatedHarmonic(Float center, Float k, Float threshold, Float limit)
TruncatedHarmonic(Float center, Float k, Float threshold)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Import IMP/kernel/UnaryFunction.h in the namespace.
Abstract single variable functor class for score functions.
virtual DerivativePair evaluate_with_derivative(double feature) const
Calculate score and derivative with respect to the given feature.
virtual double evaluate(double feature) const
Calculate score with respect to the given feature.
Import IMP/kernel/utility.h in the namespace.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:23
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
TruncatedHarmonic< BOTH > TruncatedHarmonicBound
A specialization.
TruncatedHarmonic< UPPER > TruncatedHarmonicUpperBound
A specialization for the upper bound.
TruncatedHarmonic< LOWER > TruncatedHarmonicLowerBound
A specialization for the lower bound.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.