log_exp.cpp
Go to the documentation of this file.
#include <itpp/base/math/log_exp.h>
#include <itpp/base/itcompat.h>
namespace itpp
{
// log-2 of the elements
vec log2(const vec &x) { return apply_function<double>(::log2, x); }
mat log2(const mat &x) { return apply_function<double>(::log2, x); }
// Safe substitute for <tt>log(exp(log_a) + exp(log_b))</tt>
double log_add(double log_a, double log_b)
{
if (log_a < log_b) {
double tmp = log_a;
log_a = log_b;
log_b = tmp;
}
double negdelta = log_b - log_a;
if ((negdelta < log_double_min) || std::isnan(negdelta))
return log_a;
else
return (log_a + log1p(std::exp(negdelta)));
}
}
itpp::log_add
double log_add(double log_a, double log_b)
Safe substitute for log(exp(log_a) + exp(log_b))
Definition: log_exp.cpp:40
itpp::log_double_min
const double log_double_min
Constant definition to speed up trunc_log(), trunc_exp() and log_add()
Definition: log_exp.h:101
log_exp.h
Logarithmic and exponenential functions - header file.
itpp::exp
vec exp(const vec &x)
Exp of the elements of a vector x.
Definition: log_exp.h:155
itpp::log2
vec log2(const vec &x)
log-2 of the elements
Definition: log_exp.cpp:36
itpp
itpp namespace
Definition: itmex.h:36
itcompat.h
IT++ compatibility types and functions.

Generated on Sat Sep 30 2017 07:04:09 for IT++ by Doxygen 1.8.13