IMP logo
IMP Reference Guide  develop.cb469e0f11,2024/05/29
The Integrative Modeling Platform
UnaryFunction.h
Go to the documentation of this file.
1 /**
2  * \file IMP/UnaryFunction.h \brief Single variable function.
3  *
4  * Copyright 2007-2022 IMP Inventors. All rights reserved.
5  */
6 
7 #ifndef IMPKERNEL_UNARY_FUNCTION_H
8 #define IMPKERNEL_UNARY_FUNCTION_H
9 
10 #include <IMP/kernel_config.h>
11 #include "base_types.h"
12 #include <IMP/Object.h>
13 #include <cereal/access.hpp>
14 #include <cereal/types/base_class.hpp>
15 
16 IMPKERNEL_BEGIN_NAMESPACE
17 
18 //! Abstract single variable functor class for score functions.
19 /** These functors take a single feature value, and return a corresponding
20  score (and optionally also the first derivative).
21 
22  Implementers should implement two functions:
23  - virtual double evaluate(double feature) const
24  - virtual DerivativePair evaluate_with_derivative(double feature) const
25  also add IMP_OBJECT_METHODS(Name) macro for Object methods
26  */
27 class IMPKERNELEXPORT UnaryFunction : public IMP::Object {
28  public:
29  UnaryFunction(std::string name = "UnaryFunction%1%");
30 
31  //! Calculate score with respect to the given feature.
32  /** \param[in] feature Value of feature being tested.
33  \return Score
34  */
35  virtual double evaluate(double feature) const
36 #ifdef SWIG
37  = 0;
38 #else
39  {
40  // to support easy generic classes
41  return evaluate(feature);
42  }
43 #endif
44 
45  //! Calculate score and derivative with respect to the given feature.
46  /** \param[in] feature Value of feature being tested.
47  \return a DerivativePair containing the score and its partial derivative
48  with respect to the given feature.
49  */
50  virtual DerivativePair evaluate_with_derivative(double feature) const {
51  // to support easy generic classes
52  return evaluate_with_derivative(feature);
53  }
54 
56 
57 private:
58  friend class cereal::access;
59 
60  template<class Archive> void serialize(Archive &ar) {
61  ar(cereal::base_class<Object>(this));
62  }
63 };
64 
66 
67 IMPKERNEL_END_NAMESPACE
68 
69 #endif /* IMPKERNEL_UNARY_FUNCTION_H */
Basic types used by IMP.
virtual double evaluate(double feature) const
Calculate score with respect to the given feature.
Definition: UnaryFunction.h:35
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Set up destructor for a ref counted object.
Common base class for heavy weight IMP objects.
Definition: Object.h:111
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:22
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
A shared base class to help in debugging and things.
virtual DerivativePair evaluate_with_derivative(double feature) const
Calculate score and derivative with respect to the given feature.
Definition: UnaryFunction.h:50
Abstract single variable functor class for score functions.
Definition: UnaryFunction.h:27