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.");
32 for (
unsigned int i = 0; i < funcs_.size(); ++i) {
33 fout = funcs_[i]->evaluate_with_derivative(feature);
34 eval += weights_[i] * fout.first;
35 derv += weights_[i] * fout.second;
40 virtual double evaluate(
double feature)
const {
42 for (
unsigned int i = 0; i < funcs_.size(); ++i) {
43 ret += weights_[i] * funcs_[i]->evaluate(feature);
56 "Number of weights and functions must match.");
unsigned int get_function_number()
Get the number of functions.
#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.
virtual double evaluate(double feature) const
Calculate score with respect to the given feature.
UnaryFunction * get_function(unsigned int i)
Get function at index.
Floats get_weights()
Get the function weights.
virtual DerivativePair evaluate_with_derivative(double feature) const
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.
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)