25#ifndef LSST_MODELFIT_PARAMETERS_PARAMETER_H
26#define LSST_MODELFIT_PARAMETERS_PARAMETER_H
114 return &first == &second;
118 return &first != &second;
149template <
typename T,
class C>
158 Limiter(
const Limits<T>& limits_in) : limits(limits_in){};
168 static constexpr T _default = 0;
174 static constexpr bool _linear =
false;
191 void _set_value(T value) {
227 return limits_maximal;
249 const std::string_view& namespace_separator
251 return type_name_str<C>(strip_namespace_separator, namespace_separator);
264 void set_free(
bool free)
override { _free = free; }
270 if (limits ==
nullptr) {
271 _limiter = std::make_unique<Limiter>(limits_maximal);
273 if (!((limits->get_min() >= this->get_min()) && (limits->get_max() <= this->get_max()))) {
275 +
") sets limits that are less restrictive than the minimum="
276 + limits_maximal.str();
280 _limiter = std::make_unique<Limiter>(*_limits_ptr);
289 _transformer = std::make_unique<Transformer>(this->
transform_none());
292 _transformer = std::make_unique<Transformer>(*_transform_ptr);
300 _value_transformed = _transformer->transform.forward(value_new);
304 _set_value(_transformer->transform.reverse(value_transformed));
309 _unit_ptr = unit ==
nullptr ? nullptr :
std::move(unit);
312 std::string repr(
bool name_keywords =
false,
const std::string_view& namespace_separator
314 return get_type_name(
false, namespace_separator) +
"(" + (name_keywords ?
"value=" :
"")
316 + (name_keywords ?
"transform=" :
"") +
get_transform().repr() +
", "
318 + (name_keywords ?
"label='" :
"'") + _label +
"')";
Range-based limits for parameter values.
A generic object from the parameters library.
static constexpr std::string_view CC_NAMESPACE_SEPARATOR
The C++ namespace separator.
Interface for parameters with values and metadata.
virtual T get_max() const =0
Return the maximum value for this parameter instance.
virtual T get_default() const =0
Get the default value.
virtual std::string get_desc() const =0
Get a string description for this parameter class.
virtual void set_unit(std::shared_ptr< const Unit > unit=nullptr)=0
Set the unit for this parameter instance.
virtual T get_min() const =0
Return the minimum value for this parameter instance.
virtual void set_fixed(bool fixed)=0
Set the parameter to be fixed (or not).
static const UnitTransform< T > & transform_none()
virtual const Limits< T > & get_limits() const =0
Return the limits for the untransformed value.
virtual const Unit & get_unit() const =0
Return the unit of this parameter instance.
virtual ~ParameterBase()=default
virtual void set_label(std::string label)=0
Set the string label for this parameter instance.
virtual T get_transform_derivative() const =0
Return the derivative of the transform for this parameter instance.
virtual void set_limits(std::shared_ptr< const Limits< T > > limits)=0
Set the limits for this parameter instance.
friend bool operator<(const ParameterBase< T > &first, const ParameterBase< T > &second)
virtual void set_value(T value)=0
Set the untransformed value for this parameter instance.
virtual bool get_fixed() const =0
Return whether the parameter is fixed (not free).
virtual const Limits< T > & get_limits_maximal() const =0
Return limits representing the maximum/minimum untransformed value.
virtual void set_free(bool free)=0
Set the parameter to be free (or not).
virtual std::shared_ptr< const Transform< T > > get_transform_ptr() const =0
Return the transform pointer for this parameter instance.
virtual std::string get_name() const =0
Get a string name for this parameter class.
virtual bool get_free() const =0
Return whether the parameter is free (not fixed).
virtual std::string get_label() const =0
Return a string label for this parameter instance.
friend bool operator==(const ParameterBase< T > &first, const ParameterBase< T > &second)
virtual const Transform< T > & get_transform() const =0
Return the transforming function for this parameter instance.
virtual bool get_linear() const =0
Return whether the parameter is linear.
virtual void set_value_transformed(T value_transformed)=0
Set the transformed value for this parameter instance.
virtual void set_transform(std::shared_ptr< const Transform< T > > transform)=0
Set the transforming function for this parameter instance.
friend bool operator!=(const ParameterBase< T > &first, const ParameterBase< T > &second)
virtual T get_value() const =0
Return the untransformed value of this parameter instance.
virtual T get_value_transformed() const =0
Return the transformed value of this parameter instance.
A parameter with values and metadata.
std::string get_label() const override
Return a string label for this parameter instance.
std::string get_desc() const override
Get a string description for this parameter class.
const Unit & get_unit() const override
Return the unit of this parameter instance.
bool get_fixed() const override
Return whether the parameter is fixed (not free).
static constexpr T _get_max()
T _value
The untransformed value.
static constexpr T _get_default()
Get the default value for the derived type of this.
static const std::string get_type_name(bool strip_namespace_separator=false, const std::string_view &namespace_separator=detail::NAMESPACE_SEPARATOR)
Get the name of the derived type of this.
T _value_transformed
The cached, transformed value.
static constexpr T _get_min()
Parameter(T value=_get_default(), std::shared_ptr< const Limits< T > > limits=nullptr, const std::shared_ptr< const Transform< T > > transform=nullptr, std::shared_ptr< const Unit > unit=nullptr, bool fixed=false, std::string label="")
Initialize a Parameter.
std::shared_ptr< C > ptr()
Return a shared pointer to this.
T get_value() const override
Return the untransformed value of this parameter instance.
const Limits< T > & get_limits_maximal() const override
Return limits representing the maximum/minimum untransformed value.
void set_transform(const std::shared_ptr< const Transform< T > > transform) override
Set the transforming function for this parameter instance.
const Transform< T > & get_transform() const override
Return the transforming function for this parameter instance.
T get_max() const override
Return the maximum value for this parameter instance.
void set_label(std::string label) override
Set the string label for this parameter instance.
std::string get_name() const override
Get a string name for this parameter class.
void set_limits(std::shared_ptr< const Limits< T > > limits) override
Set the limits for this parameter instance.
T get_transform_derivative() const override
Return the derivative of the transform for this parameter instance.
T get_default() const override
Get the default value.
std::shared_ptr< const Transform< T > > get_transform_ptr() const override
Return the transform pointer for this parameter instance.
void set_free(bool free) override
Set the parameter to be free (or not).
std::string str() const override
Return a brief, human-readable string representation of this.
void set_unit(std::shared_ptr< const Unit > unit=nullptr) override
Set the unit for this parameter instance.
std::string repr(bool name_keywords=false, const std::string_view &namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
static const std::string _get_desc()
bool get_free() const override
Return whether the parameter is free (not fixed).
static const std::string _get_name()
static constexpr bool _get_linear()
bool get_linear() const override
Return whether the parameter is linear.
T get_min() const override
Return the minimum value for this parameter instance.
void set_value_transformed(T value_transformed) override
Set the transformed value for this parameter instance.
void set_fixed(bool fixed) override
Set the parameter to be fixed (or not).
const Limits< T > & get_limits() const override
Return the limits for the untransformed value.
T get_value_transformed() const override
Return the transformed value of this parameter instance.
void set_value(T value) override
Set the untransformed value for this parameter instance.
A generic interface for physical units described by strings.
constexpr std::string_view NAMESPACE_SEPARATOR
T shared_from_this(T... args)