SourceXtractorPlusPlus  0.19
SourceXtractor++, the next generation SExtractor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SigmoidConverter.cpp
Go to the documentation of this file.
1 
23 #include <cmath>
24 #include <iostream>
25 
26 #include <ElementsKernel/Logging.h>
27 
29 
30 namespace ModelFitting {
31 
32 using namespace std;
33 
35 
37 
38 double SigmoidConverter::worldToEngine(const double world_value) const {
39  if (world_value < m_min_value || world_value > m_max_value) {
40  logger.warn() << "WorldToEngine SigmoidConverter: world values outside of possible range";
41  }
42 
43  double num = world_value - m_min_value;
44  double den = m_max_value - world_value;
45  return (num > 1e-50 ? (den > 1e-50 ? log(num/den) : 50.0) : -50.0);
46 }
47 
48 double SigmoidConverter::engineToWorld(const double engine_value) const {
49  auto clamped_value = std::max(-50.0, std::min(50.0, engine_value));
50  return m_min_value + (m_max_value - m_min_value) / (1 + exp(-clamped_value));
51 }
52 
53 double SigmoidConverter::getEngineToWorldDerivative(const double value) const {
54  return (value - m_min_value) * (m_max_value - value) / (m_max_value - m_min_value);
55 }
56 
57 
58 }// namespace ModelFitting
T exp(T...args)
double engineToWorld(const double engine_value) const override
Engine to world coordinate converter.
auto log
double getEngineToWorldDerivative(const double value) const override
static Elements::Logging logger
T min(T...args)
constexpr double e
void warn(const std::string &logMessage)
T max(T...args)
double worldToEngine(const double world_value) const override
World to engine coordinate converter.
virtual ~SigmoidConverter()
Destructor.
static Logging getLogger(const std::string &name="")