IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2025 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#include <cereal/access.hpp>
13#include <cereal/types/base_class.hpp>
14#include <cereal/types/polymorphic.hpp>
15
16IMPCORE_BEGIN_NAMESPACE
17
18//! %Linear function
19/** \note The offset is not meaningful for optimization, but does
20 make the displayed energies nicer.
21 */
22class Linear : public UnaryFunction {
23 public:
24 //! Create with the given offset and slope.
25 Linear(double offset, double slope) : slope_(slope), offset_(offset) {}
26 Linear() {}
27
28 void set_slope(double f) { slope_ = f; }
29
30 double get_slope() const { return slope_; }
31
32 void set_offset(double f) { offset_ = f; }
33
34 double get_offset() const { return offset_; }
35
36 virtual double evaluate(double feature) const override {
37 return (feature - offset_) * slope_;
38 }
39
40 virtual DerivativePair evaluate_with_derivative(double feature) const
41 override {
42 return DerivativePair(evaluate(feature), slope_);
43 }
44
46
47 private:
48 double slope_, offset_;
49
50 friend class cereal::access;
51
52 template<class Archive> void serialize(Archive &ar) {
53 ar(cereal::base_class<UnaryFunction>(this),
54 slope_, offset_);
55 }
57};
58
59IMPCORE_END_NAMESPACE
60
61#endif /* IMPCORE_LINEAR_H */
Single variable function.
Linear function
Definition Linear.h:22
Linear(double offset, double slope)
Create with the given offset and slope.
Definition Linear.h:25
virtual double evaluate(double feature) const override
Calculate score with respect to the given feature.
Definition Linear.h:36
virtual DerivativePair evaluate_with_derivative(double feature) const override
Calculate score and derivative with respect to the given feature.
Definition Linear.h:40
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition types.h:22
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.