IMP logo
IMP Reference Guide  2.13.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-2020 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>
12 
13 IMPCORE_BEGIN_NAMESPACE
14 
15 //! %Linear function
16 /** \note The offset is not meaningful for optimization, but does
17  make the displayed energies nicer.
18  */
19 class Linear : public UnaryFunction {
20  public:
21  //! Create with the given offset and slope.
22  Linear(double offset, double slope) : slope_(slope), offset_(offset) {}
23 
24  void set_slope(double f) { slope_ = f; }
25 
26  void set_offset(double f) { offset_ = f; }
27 
28  virtual double evaluate(double feature) const IMP_OVERRIDE {
29  return (feature - offset_) * slope_;
30  }
31 
32  virtual DerivativePair evaluate_with_derivative(double feature) const
33  IMP_OVERRIDE {
34  return DerivativePair(evaluate(feature), slope_);
35  }
36 
38 
39  private:
40  double slope_, offset_;
41 };
42 
43 IMPCORE_END_NAMESPACE
44 
45 #endif /* IMPCORE_LINEAR_H */
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
virtual double evaluate(double feature) const
Calculate score with respect to the given feature.
Definition: Linear.h:28
Single variable function.
virtual DerivativePair evaluate_with_derivative(double feature) const
Calculate score and derivative with respect to the given feature.
Definition: Linear.h:32
Linear function
Definition: Linear.h:19
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:23
Linear(double offset, double slope)
Create with the given offset and slope.
Definition: Linear.h:22
Abstract single variable functor class for score functions.
Definition: UnaryFunction.h:25
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.