BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RealLimits Class Reference
Collaboration diagram for RealLimits:

Public Member Functions

 RealLimits ()
 
bool hasLowerLimit () const
 
double lowerLimit () const
 
void setLowerLimit (double value)
 
void removeLowerLimit ()
 
bool hasUpperLimit () const
 
double upperLimit () const
 
void setUpperLimit (double value)
 
void removeUpperLimit ()
 
bool hasLowerAndUpperLimits () const
 
void setLimits (double xmin, double xmax)
 
void removeLimits ()
 
bool isInRange (double value) const
 
std::string toString () const
 
bool operator== (const RealLimits &other) const
 
bool operator!= (const RealLimits &other) const
 
bool isLimitless () const
 
bool isPositive () const
 
bool isNonnegative () const
 
bool isLowerLimited () const
 
bool isUpperLimited () const
 
bool isLimited () const
 

Static Public Member Functions

static RealLimits lowerLimited (double bound_value)
 
static RealLimits positive ()
 
static RealLimits nonnegative ()
 
static RealLimits upperLimited (double bound_value)
 
static RealLimits limited (double left_bound_value, double right_bound_value)
 
static RealLimits limitless ()
 

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
 
double m_lower_limit
 
double m_upper_limit
 

Friends

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

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:105
double m_lower_limit
parameter has upper bound
Definition: RealLimits.h:107
bool m_has_upper_limit
parameter has lower bound
Definition: RealLimits.h:106
double m_upper_limit
minimum allowed value
Definition: RealLimits.h:108

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), m_has_upper_limit(has_upper_limit),
29  m_lower_limit(lower_limit), m_upper_limit(upper_limit)
30 {
31 }

Member Function Documentation

◆ hasLowerLimit()

◆ lowerLimit()

double RealLimits::lowerLimit ( ) const

◆ setLowerLimit()

void RealLimits::setLowerLimit ( double  value)

Sets lower limit.

Definition at line 43 of file RealLimits.cpp.

44 {
45  m_lower_limit = value;
46  m_has_lower_limit = true;
47 }

References m_has_lower_limit, and m_lower_limit.

Referenced by setLimits().

◆ removeLowerLimit()

void RealLimits::removeLowerLimit ( )

remove lower limit

Definition at line 49 of file RealLimits.cpp.

50 {
51  m_lower_limit = 0.;
52  m_has_lower_limit = false;
53 }

References m_has_lower_limit, and m_lower_limit.

Referenced by removeLimits().

◆ hasUpperLimit()

◆ upperLimit()

double RealLimits::upperLimit ( ) const

◆ setUpperLimit()

void RealLimits::setUpperLimit ( double  value)

Sets upper limit.

Definition at line 65 of file RealLimits.cpp.

66 {
67  m_upper_limit = value;
68  m_has_upper_limit = true;
69 }

References m_has_upper_limit, and m_upper_limit.

Referenced by setLimits().

◆ removeUpperLimit()

void RealLimits::removeUpperLimit ( )

remove upper limit

Definition at line 71 of file RealLimits.cpp.

72 {
73  m_upper_limit = 0.;
74  m_has_upper_limit = false;
75 }

References m_has_upper_limit, and m_upper_limit.

Referenced by removeLimits().

◆ hasLowerAndUpperLimits()

bool RealLimits::hasLowerAndUpperLimits ( ) const

if has lower and upper limit

Definition at line 77 of file RealLimits.cpp.

78 {
80 }

References m_has_lower_limit, and m_has_upper_limit.

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

◆ setLimits()

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

Sets lower and upper limits.

Definition at line 82 of file RealLimits.cpp.

83 {
84  setLowerLimit(xmin);
85  setUpperLimit(xmax);
86 }
void setLowerLimit(double value)
Sets lower limit.
Definition: RealLimits.cpp:43
void setUpperLimit(double value)
Sets upper limit.
Definition: RealLimits.cpp:65

References setLowerLimit(), and setUpperLimit().

Here is the call graph for this function:

◆ removeLimits()

void RealLimits::removeLimits ( )

remove limits

Definition at line 88 of file RealLimits.cpp.

89 {
92 }
void removeLowerLimit()
remove lower limit
Definition: RealLimits.cpp:49
void removeUpperLimit()
remove upper limit
Definition: RealLimits.cpp:71

References removeLowerLimit(), and removeUpperLimit().

Referenced by AttLimits::setFixed().

Here is the call graph for this function:

◆ isInRange()

bool RealLimits::isInRange ( double  value) const

returns true if proposed value is in limits range

Definition at line 94 of file RealLimits.cpp.

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

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

Referenced by DepthProbeSimulation::generateSimulationElements(), RealParameter::RealParameter(), and RealParameter::setValue().

Here is the call graph for this function:

◆ lowerLimited()

RealLimits RealLimits::lowerLimited ( double  bound_value)
static

Creates an object bounded from the left.

Definition at line 103 of file RealLimits.cpp.

104 {
105  return RealLimits(true, false, bound_value, 0.);
106 }

References RealLimits().

Referenced by AttLimits::lowerLimited(), nonnegative(), and positive().

Here is the call graph for this function:

◆ positive()

RealLimits RealLimits::positive ( )
static

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

Definition at line 108 of file RealLimits.cpp.

109 {
110  return lowerLimited(std::numeric_limits<double>::min());
111 }
static RealLimits lowerLimited(double bound_value)
Creates an object bounded from the left.
Definition: RealLimits.cpp:103

References lowerLimited().

Referenced by AttLimits::positive(), and RealParameter::setPositive().

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 113 of file RealLimits.cpp.

114 {
115  return lowerLimited(0.);
116 }

References lowerLimited().

Referenced by AttLimits::nonnegative(), and RealParameter::setNonnegative().

Here is the call graph for this function:

◆ upperLimited()

RealLimits RealLimits::upperLimited ( double  bound_value)
static

Creates an object bounded from the right.

Definition at line 118 of file RealLimits.cpp.

119 {
120  return RealLimits(false, true, 0., bound_value);
121 }

References RealLimits().

Referenced by AttLimits::upperLimited().

Here is the call graph for this function:

◆ limited()

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

Creates an object bounded from the left and right.

Definition at line 123 of file RealLimits.cpp.

124 {
125  return RealLimits(true, true, left_bound_value, right_bound_value);
126 }

References RealLimits().

Referenced by SpheresWithLimitsDistributionBuilder::buildSample(), ConesWithLimitsDistributionBuilder::buildSample(), LinkedBoxDistributionBuilder::buildSample(), DepthProbeSimulation::initialize(), SpecularSimulation::initialize(), AttLimits::limited(), and RealParameter::setLimited().

Here is the call graph for this function:

◆ limitless()

RealLimits RealLimits::limitless ( )
static

Creates an object withoud bounds (default)

Definition at line 128 of file RealLimits.cpp.

129 {
130  return RealLimits();
131 }

References RealLimits().

Referenced by AttLimits::fixed().

Here is the call graph for this function:

◆ toString()

std::string RealLimits::toString ( ) const

Definition at line 133 of file RealLimits.cpp.

134 {
135  std::ostringstream result;
136 
137  if (isLimitless())
138  result << "unlimited";
139 
140  else if (isPositive())
141  result << "positive";
142 
143  else if (isNonnegative())
144  result << "nonnegative";
145 
146  else if (isLowerLimited())
147  result << "lowerLimited(" << std::fixed << std::setprecision(2) << lowerLimit() << ")";
148 
149  else if (isUpperLimited())
150  result << "upperLimited(" << std::fixed << std::setprecision(2) << upperLimit() << ")";
151 
152  else if (isLimited())
153  result << "limited(" << std::fixed << std::setprecision(2) << lowerLimit() << ","
154  << std::fixed << std::setprecision(2) << upperLimit() << ")";
155 
156  return result.str();
157 }
bool isLimited() const
Definition: RealLimits.cpp:197
bool isLowerLimited() const
Definition: RealLimits.cpp:187
bool isPositive() const
Definition: RealLimits.cpp:176
double upperLimit() const
Returns upper limit.
Definition: RealLimits.cpp:60
double lowerLimit() const
Returns lower limit.
Definition: RealLimits.cpp:38
bool isNonnegative() const
Definition: RealLimits.cpp:182
bool isLimitless() const
Definition: RealLimits.cpp:171
bool isUpperLimited() const
Definition: RealLimits.cpp:192

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

Here is the call graph for this function:

◆ operator==()

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

Definition at line 159 of file RealLimits.cpp.

160 {
161  return (m_has_lower_limit == other.m_has_lower_limit)
163  && (m_lower_limit == other.m_lower_limit) && (m_upper_limit == other.m_upper_limit);
164 }

References m_has_lower_limit, m_has_upper_limit, m_lower_limit, and m_upper_limit.

◆ operator!=()

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

Definition at line 166 of file RealLimits.cpp.

167 {
168  return !(*this == other);
169 }

◆ isLimitless()

bool RealLimits::isLimitless ( ) const

Definition at line 171 of file RealLimits.cpp.

172 {
173  return !hasLowerLimit() && !hasUpperLimit();
174 }

References hasLowerLimit(), and hasUpperLimit().

Referenced by pyfmt::printRealLimits(), pyfmt::printRealLimitsArg(), RangedDistribution::pyString(), and toString().

Here is the call graph for this function:

◆ isPositive()

bool RealLimits::isPositive ( ) const

Definition at line 176 of file RealLimits.cpp.

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

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

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

Here is the call graph for this function:

◆ isNonnegative()

bool RealLimits::isNonnegative ( ) const

Definition at line 182 of file RealLimits.cpp.

183 {
184  return hasLowerLimit() && !hasUpperLimit() && lowerLimit() == 0.0;
185 }

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

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

Here is the call graph for this function:

◆ isLowerLimited()

bool RealLimits::isLowerLimited ( ) const

Definition at line 187 of file RealLimits.cpp.

188 {
189  return hasLowerLimit() && !hasUpperLimit();
190 }

References hasLowerLimit(), and hasUpperLimit().

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

Here is the call graph for this function:

◆ isUpperLimited()

bool RealLimits::isUpperLimited ( ) const

Definition at line 192 of file RealLimits.cpp.

193 {
194  return !hasLowerLimit() && hasUpperLimit();
195 }

References hasLowerLimit(), and hasUpperLimit().

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

Here is the call graph for this function:

◆ isLimited()

bool RealLimits::isLimited ( ) const

Definition at line 197 of file RealLimits.cpp.

198 {
199  return hasLowerLimit() && hasUpperLimit();
200 }

References hasLowerLimit(), and hasUpperLimit().

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

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 86 of file RealLimits.h.

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

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 106 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 107 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 108 of file RealLimits.h.

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


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