7 #ifndef IMPCORE_WEIGHTED_SUM_H
8 #define IMPCORE_WEIGHTED_SUM_H
10 #include <IMP/core/core_config.h>
13 IMPCORE_BEGIN_NAMESPACE
23 "Number of functions and weights must match.");
25 "More than one function and weight must be provided.");
29 double feature)
const override {
33 for (
unsigned int i = 0; i < funcs_.size(); ++i) {
34 fout = funcs_[i]->evaluate_with_derivative(feature);
35 eval += weights_[i] * fout.first;
36 derv += weights_[i] * fout.second;
41 virtual double evaluate(
double feature)
const override {
43 for (
unsigned int i = 0; i < funcs_.size(); ++i) {
44 ret += weights_[i] * funcs_[i]->evaluate(feature);
57 "Number of weights and functions must match.");
unsigned int get_function_number()
Get the number of functions.
virtual DerivativePair evaluate_with_derivative(double feature) const override
Calculate score and derivative with respect to the given feature.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Single variable function.
Weighted sum of unary functions.
double get_weight(unsigned int i) const
Get function weight at index.
UnaryFunction * get_function(unsigned int i)
Get function at index.
virtual double evaluate(double feature) const override
Calculate score with respect to the given feature.
Floats get_weights()
Get the function weights.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
void set_weights(Floats weights)
Set the function weights.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Abstract single variable functor class for score functions.
WeightedSum(UnaryFunctions funcs, Floats weights)