LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
transforms.h
Go to the documentation of this file.
1#ifndef LSST_GAUSS2D_FIT_TRANSFORMS_H
2#define LSST_GAUSS2D_FIT_TRANSFORMS_H
3
4#include <cmath>
5#include <iostream>
6#include <memory>
7
9
10namespace lsst::gauss2d::fit {
11#pragma GCC diagnostic push
12#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
13
16
17struct InverseTransform : public Transform {
18 std::string description() const override { return "Inverse transform"; }
19 std::string repr(bool name_keywords = false,
20 const std::string_view& namespace_separator
21 = parameters::Object::CC_NAMESPACE_SEPARATOR) const override {
22 return parameters::type_name_str<InverseTransform>(false, namespace_separator) + "()";
23 }
24 std::string str() const override { return parameters::type_name_str<InverseTransform>(true) + "()"; }
25
26 inline double derivative(double x) const override { return 1 / (x * x); }
27 inline double forward(double x) const override { return 1 / x; }
28 inline double reverse(double x) const override { return 1 / x; }
29};
30
32 static inline const double f_nu_0 = 3630.780547701002879554236770479;
33
34 std::string description() const override { return "jansky to AB magnitude transform"; }
35 std::string repr(bool name_keywords = false,
36 const std::string_view& namespace_separator
37 = parameters::Object::CC_NAMESPACE_SEPARATOR) const override {
38 return parameters::type_name_str<JanskyToABMagTransform>(false, namespace_separator) + "()";
39 }
40 std::string str() const override {
41 return parameters::type_name_str<JanskyToABMagTransform>(true) + "()";
42 }
43
44 inline double derivative(double x) const override {
45 return -1.08573620475812959718098227313021197915 / x;
46 }
47 inline double forward(double x) const override { return -2.5 * log10(x / f_nu_0); }
48 inline double reverse(double x) const override { return f_nu_0 * pow(10.0, -0.4 * x); }
49};
50
52 std::string description() const override { return "nanojansky to AB magnitude transform"; }
53 std::string repr(bool name_keywords = false,
54 const std::string_view& namespace_separator
55 = parameters::Object::CC_NAMESPACE_SEPARATOR) const override {
56 return parameters::type_name_str<NanojanskyToABMagTransform>(false, namespace_separator) + "()";
57 }
58 std::string str() const override {
59 return parameters::type_name_str<NanojanskyToABMagTransform>(true) + "()";
60 }
61
62 inline double derivative(double x) const override { return JanskyToABMagTransform::derivative(x); }
63 inline double forward(double x) const override { return JanskyToABMagTransform::forward(x * 1e-9); }
64 inline double reverse(double x) const override { return 1e9 * JanskyToABMagTransform::reverse(x); }
65};
66
67struct LogTransform : public Transform {
68 std::string description() const override { return "Natural (base e) logarithmic transform"; }
69 std::string repr(bool name_keywords = false,
70 const std::string_view& namespace_separator
71 = parameters::Object::CC_NAMESPACE_SEPARATOR) const override {
72 return parameters::type_name_str<LogTransform>(false, namespace_separator) + "()";
73 }
74 std::string str() const override { return parameters::type_name_str<LogTransform>(true) + "()"; }
75
76 inline double derivative(double x) const override { return 1 / x; }
77 inline double forward(double x) const override { return log(x); }
78 inline double reverse(double x) const override { return exp(x); }
79};
80
81struct Log10Transform : public Transform {
82 std::string description() const override { return "Base 10 logarithmic transform"; }
83 std::string repr(bool name_keywords = false,
84 const std::string_view& namespace_separator
85 = parameters::Object::CC_NAMESPACE_SEPARATOR) const override {
86 return parameters::type_name_str<Log10Transform>(false, namespace_separator) + "()";
87 }
88 std::string str() const override { return parameters::type_name_str<Log10Transform>(true) + "()"; }
89
90 inline double derivative(double x) const override {
91 return 0.434294481903251827651128918916605082294397 / x;
92 }
93 inline double forward(double x) const override { return log10(x); }
94 inline double reverse(double x) const override { return pow(10., x); }
95};
96
97struct LogitTransform : public Transform {
98 std::string description() const override { return "Logit transform"; }
99 std::string repr(bool name_keywords = false,
100 const std::string_view& namespace_separator
101 = parameters::Object::CC_NAMESPACE_SEPARATOR) const override {
102 return parameters::type_name_str<LogitTransform>(false, namespace_separator) + "()";
103 }
104 std::string str() const override { return parameters::type_name_str<LogitTransform>(true) + "()"; }
105
106 inline double derivative(double x) const override { return 1 / x + 1 / (1 - x); }
107 inline double forward(double x) const override { return log(x / (1 - x)); }
108 inline double reverse(double x) const override { return 1 / (1 + exp(-x)); }
109};
110
112public:
114 set_limits(std::move(limits));
115 set_factor(factor);
116 _set_range();
117 }
118
119 std::string description() const override { return "Logit limited (to finite range) transform"; }
120 std::string repr(bool name_keywords = false,
121 const std::string_view& namespace_separator
122 = parameters::Object::CC_NAMESPACE_SEPARATOR) const override {
123 return parameters::type_name_str<LogitLimitedTransform>(false, namespace_separator) + "("
124 + (name_keywords ? "limits=" : "") + _limits->repr(name_keywords, namespace_separator) + ", "
125 + (name_keywords ? "factor=" : "") + std::to_string(_factor) + ")";
126 }
127 std::string str() const override {
128 return parameters::type_name_str<LogitLimitedTransform>(true) + "(limits=" + _limits->str()
129 + ", factor=" + std::to_string(_factor) + ")";
130 }
131
132 double get_factor() const { return _factor; }
133 parameters::Limits<double>& get_limits() const { return *_limits; }
134
135 double derivative(double x) const override;
136 double forward(double x) const override;
137 double reverse(double x) const override;
138
139 void set_factor(double factor) {
140 if (!(factor > 0))
141 throw std::invalid_argument("LogitLimitedTransform factor=" + std::to_string(factor) + " !>0");
142 _factor = factor;
143 }
144
146 _limits = (limits == nullptr) ? std::make_shared<parameters::Limits<double>>() : std::move(limits);
147 _set_range();
148 }
149
150private:
152 double _factor;
153 double _range;
154
155 inline void _set_range() { _range = _limits->get_max() - _limits->get_min(); }
156};
157
158template <class T>
160 static T transform_default{};
161 static std::shared_ptr<T> ptr{std::shared_ptr<T>{}, &transform_default};
162 return ptr;
163}
164#pragma GCC diagnostic pop
165} // namespace lsst::gauss2d::fit
166
167#endif // LSST_GAUSS2D_FIT_TRANSFORMS_H
std::uint64_t * ptr
Definition RangeSet.cc:95
std::string description() const override
Return a description of this transform.
Definition transforms.h:119
parameters::Limits< double > & get_limits() const
Definition transforms.h:133
double forward(double x) const override
Definition transforms.cc:19
std::string repr(bool name_keywords=false, const std::string_view &namespace_separator=parameters::Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
Definition transforms.h:120
void set_limits(std::shared_ptr< parameters::Limits< double > > limits)
Definition transforms.h:145
std::string str() const override
Return a brief, human-readable string representation of this.
Definition transforms.h:127
LogitLimitedTransform(std::shared_ptr< parameters::Limits< double > > limits, double factor=1)
Definition transforms.h:113
double derivative(double x) const override
Definition transforms.cc:10
double reverse(double x) const override
Definition transforms.cc:31
Range-based limits for parameter values.
Definition limits.h:45
A reversible transformation of a real scalar value.
Definition transform.h:45
T make_shared(T... args)
T move(T... args)
parameters::Transform< double > Transform
Definition transforms.h:15
std::shared_ptr< T > get_transform_default()
Definition transforms.h:159
double reverse(double x) const override
Definition transforms.h:28
std::string repr(bool name_keywords=false, const std::string_view &namespace_separator=parameters::Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
Definition transforms.h:19
std::string description() const override
Return a description of this transform.
Definition transforms.h:18
std::string str() const override
Return a brief, human-readable string representation of this.
Definition transforms.h:24
double derivative(double x) const override
Definition transforms.h:26
double forward(double x) const override
Definition transforms.h:27
double derivative(double x) const override
Definition transforms.h:44
std::string description() const override
Return a description of this transform.
Definition transforms.h:34
std::string repr(bool name_keywords=false, const std::string_view &namespace_separator=parameters::Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
Definition transforms.h:35
double forward(double x) const override
Definition transforms.h:47
double reverse(double x) const override
Definition transforms.h:48
std::string str() const override
Return a brief, human-readable string representation of this.
Definition transforms.h:40
std::string repr(bool name_keywords=false, const std::string_view &namespace_separator=parameters::Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
Definition transforms.h:83
std::string description() const override
Return a description of this transform.
Definition transforms.h:82
std::string str() const override
Return a brief, human-readable string representation of this.
Definition transforms.h:88
double derivative(double x) const override
Definition transforms.h:90
double forward(double x) const override
Definition transforms.h:93
double reverse(double x) const override
Definition transforms.h:94
double reverse(double x) const override
Definition transforms.h:78
std::string description() const override
Return a description of this transform.
Definition transforms.h:68
std::string str() const override
Return a brief, human-readable string representation of this.
Definition transforms.h:74
std::string repr(bool name_keywords=false, const std::string_view &namespace_separator=parameters::Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
Definition transforms.h:69
double derivative(double x) const override
Definition transforms.h:76
double forward(double x) const override
Definition transforms.h:77
std::string str() const override
Return a brief, human-readable string representation of this.
Definition transforms.h:104
double derivative(double x) const override
Definition transforms.h:106
std::string description() const override
Return a description of this transform.
Definition transforms.h:98
double reverse(double x) const override
Definition transforms.h:108
double forward(double x) const override
Definition transforms.h:107
std::string repr(bool name_keywords=false, const std::string_view &namespace_separator=parameters::Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
Definition transforms.h:99
std::string description() const override
Return a description of this transform.
Definition transforms.h:52
double reverse(double x) const override
Definition transforms.h:64
std::string repr(bool name_keywords=false, const std::string_view &namespace_separator=parameters::Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
Definition transforms.h:53
double derivative(double x) const override
Definition transforms.h:62
double forward(double x) const override
Definition transforms.h:63
std::string str() const override
Return a brief, human-readable string representation of this.
Definition transforms.h:58
T to_string(T... args)