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.");
42 double feature)
const override {
47 for (
unsigned int i = 0; i < funcs_.size(); ++i) {
48 fout = funcs_[i]->evaluate_with_derivative(feature);
49 weight_exp = weights_[i] * std::exp(-fout.first / denom_);
50 exp_sum += weight_exp;
51 derv_num += weight_exp * fout.second;
53 return DerivativePair(-std::log(exp_sum) * denom_, derv_num / exp_sum);
56 virtual double evaluate(
double feature)
const override {
58 for (
unsigned int i = 0; i < funcs_.size(); ++i) {
59 exp_sum += weights_[i] * std::exp(-funcs_[i]->evaluate(feature) / denom_);
61 return -std::log(exp_sum) * denom_;
72 "Number of weights and functions must match.");
94 "Exponential denominator must be nonzero.");
109 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.
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 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.
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.
virtual double evaluate(double feature) const override
Calculate score with respect to the given feature.