IMP  2.1.0
The Integrative Modeling Platform
Linear.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/Linear.h \brief A linear function.
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  */
6 
7 #ifndef IMPCORE_LINEAR_H
8 #define IMPCORE_LINEAR_H
9 
10 #include <IMP/core/core_config.h>
11 #include <IMP/UnaryFunction.h>
13 
14 IMPCORE_BEGIN_NAMESPACE
15 
16 //! %Linear function
17 /** \note The offset is not meaningful for optimization, but does
18  make the displayed energies nicer.
19  */
20 class Linear : public UnaryFunction {
21  public:
22  //! Create with the given offset and slope.
23  Linear(double offset, double slope) : slope_(slope), offset_(offset) {}
24 
25  void set_slope(double f) { slope_ = f; }
26 
27  void set_offset(double f) { offset_ = f; }
28 
29  virtual double evaluate(double feature) const IMP_OVERRIDE {
30  return (feature - offset_) * slope_;
31  }
32 
33  virtual DerivativePair evaluate_with_derivative(double feature) const
34  IMP_OVERRIDE {
35  return DerivativePair(evaluate(feature), slope_);
36  }
37 
39 
40  private:
41  double slope_, offset_;
42 };
43 
44 IMPCORE_END_NAMESPACE
45 
46 #endif /* IMPCORE_LINEAR_H */
virtual double evaluate(double feature) const
Calculate score with respect to the given feature.
Definition: Linear.h:29
Import IMP/kernel/UnaryFunction.h in the namespace.
Abstract single variable functor class for score functions.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
virtual DerivativePair evaluate_with_derivative(double feature) const
Calculate score and derivative with respect to the given feature.
Definition: Linear.h:33
Linear function
Definition: Linear.h:20
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: base/types.h:23
Import IMP/kernel/unary_function_macros.h in the namespace.
Linear(double offset, double slope)
Create with the given offset and slope.
Definition: Linear.h:23