LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
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)