8 #ifndef IMPCORE_WEIGHTED_SUM_OF_EXPONENTIAL_H
9 #define IMPCORE_WEIGHTED_SUM_OF_EXPONENTIAL_H
11 #include <IMP/core/core_config.h>
15 IMPCORE_BEGIN_NAMESPACE
31 Float denom = 1.0) : funcs_(funcs), weights_(weights), denom_(denom) {
33 "Number of functions and weights must match.");
35 "More than one function and weight must be provided.");
37 "Exponential denominator must be nonzero.");
46 for (
unsigned int i = 0; i < funcs_.size(); ++i) {
47 fout = funcs_[i]->evaluate_with_derivative(feature);
48 weight_exp = weights_[i] * std::exp(-fout.first / denom_);
49 exp_sum += weight_exp;
50 derv_num += weight_exp * fout.second;
52 return DerivativePair(-std::log(exp_sum) * denom_, derv_num / exp_sum);
55 virtual double evaluate(
double feature)
const {
57 for (
unsigned int i = 0; i < funcs_.size(); ++i) {
58 exp_sum += weights_[i] * std::exp(-funcs_[i]->evaluate(feature) / denom_);
60 return -std::log(exp_sum) * denom_;
71 "Number of weights and functions must match.");
93 "Exponential denominator must be nonzero.");
108 IMPCORE_END_NAMESPACE
double get_weight(unsigned int i) const
Get function weight at index.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
WeightedSumOfExponential(UnaryFunctions funcs, Floats weights, Float denom=1.0)
Single variable function.
virtual DerivativePair evaluate_with_derivative(double feature) const
Calculate score and derivative with respect to the given feature.
Floats get_weights()
Get the function weights.
void set_denominator(double denom)
Set the denominator of the exponential.
UnaryFunction * get_function(unsigned int i)
Get function at index.
Negative logarithm of weighted sum of negative exponential of unary functions.
double get_denominator()
Get the denominator of the exponential.
void set_weights(Floats weights)
Set the function weights.
virtual double evaluate(double feature) const
Calculate score with respect to the given feature.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
double Float
Basic floating-point value (could be float, double...)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
unsigned int get_function_number()
Get the number of functions.
Abstract single variable functor class for score functions.