7#ifndef IMPCORE_LINEAR_H
8#define IMPCORE_LINEAR_H
10#include <IMP/core/core_config.h>
12#include <cereal/access.hpp>
13#include <cereal/types/base_class.hpp>
14#include <cereal/types/polymorphic.hpp>
16IMPCORE_BEGIN_NAMESPACE
25 Linear(
double offset,
double slope) : slope_(slope), offset_(offset) {}
28 void set_slope(
double f) { slope_ = f; }
30 double get_slope()
const {
return slope_; }
32 void set_offset(
double f) { offset_ = f; }
34 double get_offset()
const {
return offset_; }
36 virtual double evaluate(
double feature)
const override {
37 return (feature - offset_) * slope_;
48 double slope_, offset_;
50 friend class cereal::access;
52 template<
class Archive>
void serialize(Archive &ar) {
53 ar(cereal::base_class<UnaryFunction>(
this),
Single variable function.
Linear(double offset, double slope)
Create with the given offset and slope.
virtual double evaluate(double feature) const override
Calculate score with respect to the given feature.
virtual DerivativePair evaluate_with_derivative(double feature) const override
Calculate score and derivative with respect to the given feature.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
#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.