IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
IMP::example::ExampleUnaryFunction Class Reference

A simple unary function. More...

#include <IMP/example/ExampleUnaryFunction.h>

Inheritance diagram for IMP::example::ExampleUnaryFunction:

Detailed Description

A simple unary function.

This one happens to be a harmonic. The source code is as follows:

/**
* \file IMP/example/ExampleUnaryFunction.h
* \brief A simple unary function.
*
* Copyright 2007-2026 IMP Inventors. All rights reserved.
*
*/
#ifndef IMPEXAMPLE_EXAMPLE_UNARY_FUNCTION_H
#define IMPEXAMPLE_EXAMPLE_UNARY_FUNCTION_H
#include <IMP/example/example_config.h>
#include <IMP/utility.h>
#include <cereal/access.hpp>
#include <cereal/types/base_class.hpp>
#include <cereal/types/polymorphic.hpp>
IMPEXAMPLE_BEGIN_NAMESPACE
//! A simple unary function
/** This one happens to be a harmonic.
The source code is as follows:
\include ExampleUnaryFunction.h
*/
class IMPEXAMPLEEXPORT ExampleUnaryFunction : public UnaryFunction {
Float center_;
Float k_;
public:
/** Create with the given center and spring constant. While it
is generally bad form to have two Float arguments, it is
hard to avoid here, and there is a bit of a sanity check.*/
ExampleUnaryFunction(Float center, Float k) : center_(center), k_(k) {
IMP_USAGE_CHECK(k > 0, "The spring constant must be positive.");
}
Float get_center() const { return center_; }
Float get_force_constant() const { return k_; }
virtual DerivativePair evaluate_with_derivative(double feature) const
override {
return DerivativePair(evaluate(feature), k_ * (feature - center_));
}
virtual double evaluate(double feature) const override {
return .5 * k_ * algebra::get_squared(feature - center_);
}
IMP_OBJECT_METHODS(ExampleUnaryFunction);
private:
friend class cereal::access;
template<class Archive> void serialize(Archive &ar) {
ar(cereal::base_class<UnaryFunction>(this), center_, k_);
}
IMP_OBJECT_SERIALIZE_DECL(ExampleUnaryFunction);
};
IMPEXAMPLE_END_NAMESPACE
#endif /* IMPEXAMPLE_EXAMPLE_UNARY_FUNCTION_H */
Single variable function.
Functions to deal with very common math operations.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
ExampleUnaryFunction(Float center, Float k)
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
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.
Various general useful functions for IMP.

Definition at line 27 of file ExampleUnaryFunction.h.

Public Member Functions

 ExampleUnaryFunction (Float center, Float k)
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.
Float get_center () const
Float get_force_constant () const
virtual std::string get_type_name () const override
virtual ::IMP::VersionInfo get_version_info () const override
 Get information about the module and version of the object.
Public Member Functions inherited from IMP::UnaryFunction
 UnaryFunction (std::string name="UnaryFunction%1%")
Public Member Functions inherited from IMP::Object
CheckLevel get_check_level () const
 get_derived_object (self)
 Return this object cast to the most derived subclass.
LogLevel get_log_level () const
void set_check_level (CheckLevel l)
void set_log_level (LogLevel l)
 Set the logging level used in this object.
const std::string & get_name () const
 Get the (not necessarily unique) name of this object.
void set_name (std::string name)
void set_was_used (bool tf) const
void show (std::ostream &out=std::cout) const
virtual void clear_caches ()

Additional Inherited Members

Protected Member Functions inherited from IMP::Object
 Object (std::string name)
 Construct an object with the given name.
virtual void do_destroy ()

Constructor & Destructor Documentation

◆ ExampleUnaryFunction() [1/2]

IMP::example::ExampleUnaryFunction::ExampleUnaryFunction ( Float center,
Float k )

Create with the given center and spring constant. While it is generally bad form to have two Float arguments, it is hard to avoid here, and there is a bit of a sanity check.

Definition at line 35 of file ExampleUnaryFunction.h.

◆ ExampleUnaryFunction() [2/2]

IMP::example::ExampleUnaryFunction::ExampleUnaryFunction ( )

Definition at line 39 of file ExampleUnaryFunction.h.

◆ ~ExampleUnaryFunction()

virtual IMP::example::ExampleUnaryFunction::~ExampleUnaryFunction ( )
virtual

Definition at line 51 of file ExampleUnaryFunction.h.

Member Function Documentation

◆ evaluate()

virtual double IMP::example::ExampleUnaryFunction::evaluate ( double feature) const
overridevirtual

Calculate score with respect to the given feature.

Parameters
[in]featureValue of feature being tested.
Returns
Score

Reimplemented from IMP::UnaryFunction.

Definition at line 48 of file ExampleUnaryFunction.h.

◆ evaluate_with_derivative()

virtual DerivativePair IMP::example::ExampleUnaryFunction::evaluate_with_derivative ( double feature) const
overridevirtual

Calculate score and derivative with respect to the given feature.

Parameters
[in]featureValue of feature being tested.
Returns
a DerivativePair containing the score and its partial derivative with respect to the given feature.

Reimplemented from IMP::UnaryFunction.

Definition at line 44 of file ExampleUnaryFunction.h.

Here is the call graph for this function:

◆ get_center()

Float IMP::example::ExampleUnaryFunction::get_center ( ) const

Definition at line 41 of file ExampleUnaryFunction.h.

◆ get_force_constant()

Float IMP::example::ExampleUnaryFunction::get_force_constant ( ) const

Definition at line 42 of file ExampleUnaryFunction.h.

◆ get_type_name()

virtual std::string IMP::example::ExampleUnaryFunction::get_type_name ( ) const
overridevirtual

Reimplemented from IMP::Object.

Definition at line 51 of file ExampleUnaryFunction.h.

◆ get_version_info()

virtual ::IMP::VersionInfo IMP::example::ExampleUnaryFunction::get_version_info ( ) const
overridevirtual

Get information about the module and version of the object.

Reimplemented from IMP::Object.

Definition at line 51 of file ExampleUnaryFunction.h.

Here is the call graph for this function:

The documentation for this class was generated from the following file: