BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RealLimits Class Reference

Limits for a real fit parameter. More...

Public Member Functions

 RealLimits ()
 
bool hasLowerAndUpperLimits () const
 if has lower and upper limit More...
 
bool hasLowerLimit () const
 if has lower limit More...
 
bool hasUpperLimit () const
 if has upper limit More...
 
bool isInRange (double value) const
 returns true if proposed value is in limits range More...
 
bool isLimited () const
 
bool isLimitless () const
 
bool isLowerLimited () const
 
bool isNonnegative () const
 
bool isPositive () const
 
bool isUpperLimited () const
 
double lowerLimit () const
 Returns lower limit. More...
 
bool operator!= (const RealLimits &other) const
 
bool operator== (const RealLimits &other) const
 
void removeLimits ()
 remove limits More...
 
void removeLowerLimit ()
 remove lower limit More...
 
void removeUpperLimit ()
 remove upper limit More...
 
void setLimits (double xmin, double xmax)
 Sets lower and upper limits. More...
 
void setLowerLimit (double value)
 Sets lower limit. More...
 
void setUpperLimit (double value)
 Sets upper limit. More...
 
std::string toString () const
 
double upperLimit () const
 Returns upper limit. More...
 

Static Public Member Functions

static RealLimits limited (double left_bound_value, double right_bound_value)
 Creates an object bounded from the left and right. More...
 
static RealLimits limitless ()
 Creates an object withoud bounds (default) More...
 
static RealLimits lowerLimited (double bound_value)
 Creates an object bounded from the left. More...
 
static RealLimits nonnegative ()
 Creates an object which can have only positive values with 0. included. More...
 
static RealLimits positive ()
 Creates an object which can have only positive values (>0., zero is not included) More...
 
static RealLimits upperLimited (double bound_value)
 Creates an object bounded from the right. More...
 

Protected Member Functions

 RealLimits (bool has_lower_limit, bool has_upper_limit, double lower_limit, double upper_limit)
 

Protected Attributes

bool m_has_lower_limit
 
bool m_has_upper_limit
 parameter has lower bound More...
 
double m_lower_limit
 parameter has upper bound More...
 
double m_upper_limit
 minimum allowed value More...
 

Friends

std::ostream & operator<< (std::ostream &ostr, const RealLimits &m)
 Prints class. More...
 

Detailed Description

Limits for a real fit parameter.

Definition at line 24 of file RealLimits.h.

Constructor & Destructor Documentation

◆ RealLimits() [1/2]

RealLimits::RealLimits ( )

Definition at line 21 of file RealLimits.cpp.

23 {
24 }
bool m_has_lower_limit
Definition: RealLimits.h:104
double m_lower_limit
parameter has upper bound
Definition: RealLimits.h:106
bool m_has_upper_limit
parameter has lower bound
Definition: RealLimits.h:105
double m_upper_limit
minimum allowed value
Definition: RealLimits.h:107

Referenced by limited(), limitless(), lowerLimited(), and upperLimited().

◆ RealLimits() [2/2]

RealLimits::RealLimits ( bool  has_lower_limit,
bool  has_upper_limit,
double  lower_limit,
double  upper_limit 
)
protected

Definition at line 26 of file RealLimits.cpp.

28  : m_has_lower_limit(has_lower_limit)
29  , m_has_upper_limit(has_upper_limit)
30  , m_lower_limit(lower_limit)
31  , m_upper_limit(upper_limit)
32 {
33 }

Member Function Documentation

◆ hasLowerAndUpperLimits()

bool RealLimits::hasLowerAndUpperLimits ( ) const

if has lower and upper limit

Definition at line 79 of file RealLimits.cpp.

80 {
82 }

References m_has_lower_limit, and m_has_upper_limit.

Referenced by IRangedDistribution::checkInitialization(), and AttLimits::isLimited().

◆ hasLowerLimit()

◆ hasUpperLimit()

◆ isInRange()

bool RealLimits::isInRange ( double  value) const

returns true if proposed value is in limits range

Definition at line 96 of file RealLimits.cpp.

97 {
98  if (hasLowerLimit() && value < m_lower_limit)
99  return false;
100  if (hasUpperLimit() && value >= m_upper_limit)
101  return false;
102  return true;
103 }
bool hasUpperLimit() const
if has upper limit
Definition: RealLimits.cpp:57
bool hasLowerLimit() const
if has lower limit
Definition: RealLimits.cpp:35

References hasLowerLimit(), hasUpperLimit(), m_lower_limit, and m_upper_limit.

Referenced by RealParameter::RealParameter(), SpecularBeamWavelengthItem::setToRange(), and RealParameter::setValue().

Here is the call graph for this function:

◆ isLimited()

bool RealLimits::isLimited ( ) const

Definition at line 199 of file RealLimits.cpp.

200 {
201  return hasLowerLimit() && hasUpperLimit();
202 }

References hasLowerLimit(), and hasUpperLimit().

Referenced by DistributionItem::init_limits_group(), pyfmt::printRealLimits(), SpecularBeamWavelengthItem::setToRange(), and toString().

Here is the call graph for this function:

◆ isLimitless()

bool RealLimits::isLimitless ( ) const

Definition at line 173 of file RealLimits.cpp.

174 {
175  return !hasLowerLimit() && !hasUpperLimit();
176 }

References hasLowerLimit(), and hasUpperLimit().

Referenced by DistributionItem::init_limits_group(), pyfmt2::printRangedDistribution(), pyfmt::printRealLimits(), pyfmt::printRealLimitsArg(), and toString().

Here is the call graph for this function:

◆ isLowerLimited()

bool RealLimits::isLowerLimited ( ) const

Definition at line 189 of file RealLimits.cpp.

190 {
191  return hasLowerLimit() && !hasUpperLimit();
192 }

References hasLowerLimit(), and hasUpperLimit().

Referenced by DistributionItem::init_limits_group(), pyfmt::printRealLimits(), and toString().

Here is the call graph for this function:

◆ isNonnegative()

bool RealLimits::isNonnegative ( ) const

Definition at line 184 of file RealLimits.cpp.

185 {
186  return hasLowerLimit() && !hasUpperLimit() && lowerLimit() == 0.0;
187 }
double lowerLimit() const
Returns lower limit.
Definition: RealLimits.cpp:40

References hasLowerLimit(), hasUpperLimit(), and lowerLimit().

Referenced by DistributionItem::init_limits_group(), pyfmt::printRealLimits(), and toString().

Here is the call graph for this function:

◆ isPositive()

bool RealLimits::isPositive ( ) const

Definition at line 178 of file RealLimits.cpp.

179 {
180  return hasLowerLimit() && !hasUpperLimit()
181  && lowerLimit() == std::numeric_limits<double>::min();
182 }

References hasLowerLimit(), hasUpperLimit(), and lowerLimit().

Referenced by DistributionItem::init_limits_group(), pyfmt::printRealLimits(), and toString().

Here is the call graph for this function:

◆ isUpperLimited()

bool RealLimits::isUpperLimited ( ) const

Definition at line 194 of file RealLimits.cpp.

195 {
196  return !hasLowerLimit() && hasUpperLimit();
197 }

References hasLowerLimit(), and hasUpperLimit().

Referenced by DistributionItem::init_limits_group(), pyfmt::printRealLimits(), and toString().

Here is the call graph for this function:

◆ limited()

RealLimits RealLimits::limited ( double  left_bound_value,
double  right_bound_value 
)
static

◆ limitless()

◆ lowerLimit()

◆ lowerLimited()

RealLimits RealLimits::lowerLimited ( double  bound_value)
static

Creates an object bounded from the left.

Definition at line 105 of file RealLimits.cpp.

106 {
107  return RealLimits(true, false, bound_value, 0.);
108 }

References RealLimits().

Referenced by CuboctahedronItem::CuboctahedronItem(), LayerItem::LayerItem(), ResolutionFunction2DGaussianItem::ResolutionFunction2DGaussianItem(), LowerLimitedItem::createRealLimits(), DistributionLorentzItem::init_distribution(), DistributionGaussianItem::init_distribution(), DistributionLogNormalItem::init_distribution(), DistributionCosineItem::init_distribution(), AttLimits::lowerLimited(), nonnegative(), positive(), and DistributionItem::register_number_of_samples().

Here is the call graph for this function:

◆ nonnegative()

RealLimits RealLimits::nonnegative ( )
static

Creates an object which can have only positive values with 0. included.

Definition at line 115 of file RealLimits.cpp.

116 {
117  return lowerLimited(0.);
118 }
static RealLimits lowerLimited(double bound_value)
Creates an object bounded from the left.
Definition: RealLimits.cpp:105

References lowerLimited().

Referenced by ConstantBackgroundItem::ConstantBackgroundItem(), FootprintGaussianItem::FootprintGaussianItem(), FootprintSquareItem::FootprintSquareItem(), SessionItem::SessionItem(), NonnegativeItem::createRealLimits(), AttLimits::nonnegative(), and RealParameter::setNonnegative().

Here is the call graph for this function:

◆ operator!=()

bool RealLimits::operator!= ( const RealLimits other) const

Definition at line 168 of file RealLimits.cpp.

169 {
170  return !(*this == other);
171 }

◆ operator==()

bool RealLimits::operator== ( const RealLimits other) const

Definition at line 161 of file RealLimits.cpp.

162 {
163  return (m_has_lower_limit == other.m_has_lower_limit)
165  && (m_lower_limit == other.m_lower_limit) && (m_upper_limit == other.m_upper_limit);
166 }

References m_has_lower_limit, m_has_upper_limit, m_lower_limit, and m_upper_limit.

◆ positive()

RealLimits RealLimits::positive ( )
static

Creates an object which can have only positive values (>0., zero is not included)

Definition at line 110 of file RealLimits.cpp.

111 {
112  return lowerLimited(std::numeric_limits<double>::min());
113 }

References lowerLimited().

Referenced by BeamWavelengthItem::BeamWavelengthItem(), PositiveItem::createRealLimits(), AttLimits::positive(), RealParameter::setPositive(), and SpecularBeamItem::updateWavelength().

Here is the call graph for this function:

◆ removeLimits()

void RealLimits::removeLimits ( )

remove limits

Definition at line 90 of file RealLimits.cpp.

91 {
94 }
void removeLowerLimit()
remove lower limit
Definition: RealLimits.cpp:51
void removeUpperLimit()
remove upper limit
Definition: RealLimits.cpp:73

References removeLowerLimit(), and removeUpperLimit().

Referenced by AttLimits::setFixed().

Here is the call graph for this function:

◆ removeLowerLimit()

void RealLimits::removeLowerLimit ( )

remove lower limit

Definition at line 51 of file RealLimits.cpp.

52 {
53  m_lower_limit = 0.;
54  m_has_lower_limit = false;
55 }

References m_has_lower_limit, and m_lower_limit.

Referenced by removeLimits().

◆ removeUpperLimit()

void RealLimits::removeUpperLimit ( )

remove upper limit

Definition at line 73 of file RealLimits.cpp.

74 {
75  m_upper_limit = 0.;
76  m_has_upper_limit = false;
77 }

References m_has_upper_limit, and m_upper_limit.

Referenced by removeLimits().

◆ setLimits()

void RealLimits::setLimits ( double  xmin,
double  xmax 
)

Sets lower and upper limits.

Definition at line 84 of file RealLimits.cpp.

85 {
86  setLowerLimit(xmin);
87  setUpperLimit(xmax);
88 }
void setLowerLimit(double value)
Sets lower limit.
Definition: RealLimits.cpp:45
void setUpperLimit(double value)
Sets upper limit.
Definition: RealLimits.cpp:67

References setLowerLimit(), and setUpperLimit().

Referenced by PropertyEditorFactory::CreateEditor().

Here is the call graph for this function:

◆ setLowerLimit()

void RealLimits::setLowerLimit ( double  value)

Sets lower limit.

Definition at line 45 of file RealLimits.cpp.

46 {
47  m_lower_limit = value;
48  m_has_lower_limit = true;
49 }

References m_has_lower_limit, and m_lower_limit.

Referenced by setLimits().

◆ setUpperLimit()

void RealLimits::setUpperLimit ( double  value)

Sets upper limit.

Definition at line 67 of file RealLimits.cpp.

68 {
69  m_upper_limit = value;
70  m_has_upper_limit = true;
71 }

References m_has_upper_limit, and m_upper_limit.

Referenced by setLimits().

◆ toString()

std::string RealLimits::toString ( ) const

Definition at line 135 of file RealLimits.cpp.

136 {
137  std::ostringstream result;
138 
139  if (isLimitless())
140  result << "unlimited";
141 
142  else if (isPositive())
143  result << "positive";
144 
145  else if (isNonnegative())
146  result << "nonnegative";
147 
148  else if (isLowerLimited())
149  result << "lowerLimited(" << std::fixed << std::setprecision(2) << lowerLimit() << ")";
150 
151  else if (isUpperLimited())
152  result << "upperLimited(" << std::fixed << std::setprecision(2) << upperLimit() << ")";
153 
154  else if (isLimited())
155  result << "limited(" << std::fixed << std::setprecision(2) << lowerLimit() << ","
156  << std::fixed << std::setprecision(2) << upperLimit() << ")";
157 
158  return result.str();
159 }
bool isLimited() const
Definition: RealLimits.cpp:199
bool isLowerLimited() const
Definition: RealLimits.cpp:189
bool isPositive() const
Definition: RealLimits.cpp:178
double upperLimit() const
Returns upper limit.
Definition: RealLimits.cpp:62
bool isNonnegative() const
Definition: RealLimits.cpp:184
bool isLimitless() const
Definition: RealLimits.cpp:173
bool isUpperLimited() const
Definition: RealLimits.cpp:194

References isLimited(), isLimitless(), isLowerLimited(), isNonnegative(), isPositive(), isUpperLimited(), lowerLimit(), and upperLimit().

Here is the call graph for this function:

◆ upperLimit()

◆ upperLimited()

RealLimits RealLimits::upperLimited ( double  bound_value)
static

Creates an object bounded from the right.

Definition at line 120 of file RealLimits.cpp.

121 {
122  return RealLimits(false, true, 0., bound_value);
123 }

References RealLimits().

Referenced by UpperLimitedItem::createRealLimits(), and AttLimits::upperLimited().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  ostr,
const RealLimits m 
)
friend

Prints class.

Definition at line 85 of file RealLimits.h.

86  {
87  ostr << m.toString();
88  return ostr;
89  }
std::string toString() const
Definition: RealLimits.cpp:135

Member Data Documentation

◆ m_has_lower_limit

bool RealLimits::m_has_lower_limit
protected

◆ m_has_upper_limit

bool RealLimits::m_has_upper_limit
protected

parameter has lower bound

Definition at line 105 of file RealLimits.h.

Referenced by hasLowerAndUpperLimits(), hasUpperLimit(), operator==(), removeUpperLimit(), and setUpperLimit().

◆ m_lower_limit

double RealLimits::m_lower_limit
protected

parameter has upper bound

Definition at line 106 of file RealLimits.h.

Referenced by isInRange(), lowerLimit(), operator==(), removeLowerLimit(), and setLowerLimit().

◆ m_upper_limit

double RealLimits::m_upper_limit
protected

minimum allowed value

Definition at line 107 of file RealLimits.h.

Referenced by isInRange(), operator==(), removeUpperLimit(), setUpperLimit(), and upperLimit().


The documentation for this class was generated from the following files: