Unfit  3.1.1
Data fitting and optimization software
Public Member Functions | Private Attributes | List of all members
Unfit::Bounds Class Reference

#include <Bounds.hpp>

Public Member Functions

 Bounds ()
 
 Bounds (std::size_t number_of_bounds)
 
void ClampWithinBounds (std::vector< double > &point)
 
void GetBounds (std::vector< double > &lower_bound, std::vector< double > &upper_bound) const
 
std::size_t GetNumberOfBounds () const noexcept
 
bool IsAboveLowerBound (std::size_t index, double point) const noexcept
 
bool IsBelowUpperBound (std::size_t index, double point) const noexcept
 
bool IsWithinBounds (std::size_t index, double point) const noexcept
 
bool IsWithinBounds (const std::vector< double > &point) const noexcept
 
void ResetBounds ()
 
bool SetBounds (std::size_t index, double lower_bound, double upper_bound)
 
bool SetBounds (const std::vector< double > &lower_bound, const std::vector< double > &upper_bound)
 
void SetNumberOfBounds (std::size_t number_of_bounds)
 
double GetLowerBound (std::size_t index) const noexcept
 
bool SetLowerBound (std::size_t index, double lower_bound)
 
double GetUpperBound (std::size_t index) const noexcept
 
bool SetUpperBound (std::size_t index, double upper_bound)
 

Private Attributes

std::vector< double > upper_bound_
 
std::vector< double > lower_bound_
 

Detailed Description

This class is designed to handle all of the bounds work for Unfit. To ensure safety, internally a pair of bounds should be created for all variables, even if there is no desire to set them to specific values. This is as easy as passing the number of variables to the constructor (if known), or later calling SetNumberOfBounds which will also create the default bounds for you. Remember that all indices start from zero in C++, so that is the location of the first bound. Note that bounds are always set (or removed) in pairs, so if there is an upper bound there will always be a lower bound.

Constructor & Destructor Documentation

◆ Bounds() [1/2]

Unfit::Bounds::Bounds ( )

Create an empty Bounds object where no bounds are set.

◆ Bounds() [2/2]

Unfit::Bounds::Bounds ( std::size_t  number_of_bounds)

Create a Bounds object and sets number_of_bounds variables to have a lower bound at equal to the maximum negative float and an upper bound equal to the maximum positive float (stored as doubles). The reason for this is that on some platforms using the minimum and maximum doubles has caused issues.

Parameters
number_of_boundsThe number of variables in the problem

Member Function Documentation

◆ ClampWithinBounds()

void Unfit::Bounds::ClampWithinBounds ( std::vector< double > &  point)

Checks if the coordinates of the point provided to the method are within bounds of the domain. The check is INCLUSIVE. This means that if the value of a variable is on the domain boundary it is considered to be within the domain. If any of the variables are outside the bounds it will change that coordinate such that it lies on the bound.

Parameters
pointthe coordinates of the point to check

◆ GetBounds()

void Unfit::Bounds::GetBounds ( std::vector< double > &  lower_bound,
std::vector< double > &  upper_bound 
) const

Here, the current values for all of the upper and lower bounds are written into the upper_bound and lower_bound arguments, respectively.

Parameters
lower_bound(input) vector containing the lower bounds;
upper_bound(input) vector containing the upper bounds;

◆ GetLowerBound()

double Unfit::Bounds::GetLowerBound ( std::size_t  index) const
noexcept

Returns the lower bound value of given index. The index should be the smaller than the size of the lower bound vector. If not, method assumes that there is no contraints and returns the largest negative double precision number.

Parameters
indexThe position of the variable on which the bound will be set
Returns
The value of lower bound of given index

◆ GetNumberOfBounds()

std::size_t Unfit::Bounds::GetNumberOfBounds ( ) const
noexcept

Returns the number of variables that are currently bounded. This should be the same as the number of variables in the problem. If not, use SetNumberOfBounds to fix this.

Returns
The number of bounded variables

◆ GetUpperBound()

double Unfit::Bounds::GetUpperBound ( std::size_t  index) const
noexcept

Returns the upper bound value of given index. The index should be the smaller than the size of the upper bound vector. If not, method assumes that there is no contraints and returns the largest positive double precision number.

Parameters
indexThe position of the variable on which the bound will be set
Returns
The value of upper bound of given index

◆ IsAboveLowerBound()

bool Unfit::Bounds::IsAboveLowerBound ( std::size_t  index,
double  point 
) const
noexcept

Checks if the point provided to the method is above the lower bound on that variable. The check is INCLUSIVE. This means that if the value of a variable is on the domain boundary it is considered to be within the domain. An invalid index will return false.

Parameters
indexthe location of the point to check
pointthe value of the point to check
Returns
true if the point is within the bounds
false if the point is not within the bounds

◆ IsBelowUpperBound()

bool Unfit::Bounds::IsBelowUpperBound ( std::size_t  index,
double  point 
) const
noexcept

Checks if the point provided to the method is below the upper bound on that variable. The check is INCLUSIVE. This means that if the value of a variable is on the domain boundary it is considered to be within the domain. An invalid index will return false.

Parameters
indexthe location of the point to check
pointthe value of the point to check
Returns
true if the point is within the bounds
false if the point is not within the bounds

◆ IsWithinBounds() [1/2]

bool Unfit::Bounds::IsWithinBounds ( std::size_t  index,
double  point 
) const
noexcept

Checks if the point provided to the method is within the bounds of the variable. The check is INCLUSIVE. This means that if the value of a variable is on the domain boundary it is considered to be within the domain. An invalid index will return false.

Parameters
indexthe location of the point to check
pointthe value of the point to check
Returns
true if the point is within the bounds
false if the point is not within the bounds

◆ IsWithinBounds() [2/2]

bool Unfit::Bounds::IsWithinBounds ( const std::vector< double > &  point) const
noexcept

Checks if the coordinates of the point provided to the method are within bounds of the domain. The check is INCLUSIVE. This means that if the value of a variable is on the domain boundary it is considered to be within the domain.

Parameters
pointthe coordinates of the point to check
Returns
true if the coordinates are within the bounds
false if the coordinates are not within the bounds

◆ ResetBounds()

void Unfit::Bounds::ResetBounds ( )

This method keeps the number of bounds unchanged, but resets them such that all of the lower bounds are the maximum negative float and all of the upper bounds are the maximum positive float (stored as doubles).

◆ SetBounds() [1/2]

bool Unfit::Bounds::SetBounds ( std::size_t  index,
double  lower_bound,
double  upper_bound 
)

Sets the upper and lower bound at the position "index". If setting the bound fails, the original state of the bounds will be preserved (including remaining undefined if they have not been set previously).

Parameters
indexThe position of the variable on which the bound will be set
lower_boundThe value of the lower bound
upper_boundThe value of the upper bound
Returns
true = Sucess
false = Failure; invalid bound or bounds

◆ SetBounds() [2/2]

bool Unfit::Bounds::SetBounds ( const std::vector< double > &  lower_bound,
const std::vector< double > &  upper_bound 
)

Sets the upper and lower bounds at all positions. All existing bounds will be overwritten if this method succeeds. This includes changing the number of bounds, if necessary. The number of upper bounds must be equal to the number of lower bounds, which should be equal to the number of variables you have. If setting the bounds fails, the original state of the bounds will be preserved (including remaining undefined if they have not been set previously).

Parameters
lower_boundA vector containing the lower bounds
upper_boundA vector containing the upper bounds
Returns
true = Sucess
false = Failure; invalid bound or bounds

◆ SetLowerBound()

bool Unfit::Bounds::SetLowerBound ( std::size_t  index,
double  lower_bound 
)

Set the lower bound at the position "index". The corresponding upper bound will be set to the largest positive double precision number. If setting the bound fails, the original state of the bounds will be preserved (including remaining undefined if they have not been set previously).

Parameters
indexThe position of the variable on which the bound will be set
lower_boundThe value of the lower bound
Returns
true = Sucess
false = Failure; invalid upper bound

◆ SetNumberOfBounds()

void Unfit::Bounds::SetNumberOfBounds ( std::size_t  number_of_bounds)

Set the number of bounds in the problem. This should be the same as the number of variables. If number_of_bounds is equal to the current number of bounds no updates will occur (existing bounds will be preserved). If number_of_bounds is less that the current number of bounds, the bounds above number_of_bounds will be deleted (other bounds will be preserved). If number_of_bounds is greater than the current number of bounds, new bounds will be appended (lower = -max; upper = +max) to the existing set of bounds (if any). NOTE: An upper and a lower bound on the same variable only count as one bound.

Parameters
number_of_boundsThe number of variables in the problem

◆ SetUpperBound()

bool Unfit::Bounds::SetUpperBound ( std::size_t  index,
double  upper_bound 
)

Set the upper bound at the position "index". The corresponding lower bound will be set to the largest negative double precision number. If setting the bound fails, the original state of the bounds will be preserved (including remaining undefined if they have not been set previously).

Parameters
indexThe position of the variable on which the bound will be set
upper_boundThe value of the upper bound
Returns
true = Sucess
false = Failure; invalid upper bound

Member Data Documentation

◆ lower_bound_

std::vector<double> Unfit::Bounds::lower_bound_
private

Stores the lower bounds of the variables

◆ upper_bound_

std::vector<double> Unfit::Bounds::upper_bound_
private

Stores the upper bounds of the variables


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