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

Access to the private member functions in the neldermead class. More...

Inheritance diagram for Unfit::TestNelderMead:
Unfit::NelderMead Unfit::GenericOptimizer

Public Member Functions

int AccessGeneratePopulation (GenericCostFunction &CostFunction, std::vector< double > &initial_point)
 
void AccessComputeCentroid ()
 
bool AccessContractInside (GenericCostFunction &CostFunction)
 
bool AccessContractOutside (GenericCostFunction &CostFunction)
 
bool AccessReflect (GenericCostFunction &CostFunction)
 
bool AccessExpand (GenericCostFunction &CostFunction)
 
bool AccessShrink (GenericCostFunction &CostFunction)
 
void AccessInitialiseVectors ()
 
void AccessPrintIterationOutput (double best_cost)
 
int AccessRegeneratePopulation (GenericCostFunction &CostFunction)
 
void SetCentroid (std::vector< double > &centroid_values)
 
void SetReflect (std::vector< double > &reflect_values)
 
void SetContract (std::vector< double > &contract_values)
 
void SetNumberOfDimensions_ (std::size_t number_of_dimensions)
 
std::size_t GetNumberOfDimensions_ ()
 
unsigned GetExpand (std::vector< double > &store_expand) const
 
unsigned GetCentroid (std::vector< double > &store_centroid) const
 
unsigned GetReflect (std::vector< double > &store_reflect) const
 
unsigned GetContract (std::vector< double > &store_contract) const
 
bool AccessIsDegenerate ()
 
void SetVertices (std::vector< std::vector< double > > &vertex)
 
std::size_t GetCurrentFunctionEvaluation ()
 
std::size_t GetCurrentIterations ()
 
void SetProcess (int process)
 
void SetWorstVertex (unsigned vertex_number)
 
- Public Member Functions inherited from Unfit::NelderMead
 NelderMead ()
 
virtual ~NelderMead ()
 
int FindMin (GenericCostFunction &CostFunction, std::vector< double > &coordinates) override
 Implements the Nelder-Mead optimization method. More...
 
void Reset () override
 
- Public Member Functions inherited from Unfit::GenericOptimizer
 GenericOptimizer ()
 
virtual ~GenericOptimizer ()
 
void ResetGenericOptimizer ()
 
virtual double GetCost (std::size_t index=0) const noexcept
 
virtual bool GetIsPopulationBased () const noexcept
 
virtual std::size_t GetNumberOfIterations () const noexcept
 
virtual std::size_t GetNumberOfFunctionEvaluations () const noexcept
 
virtual std::vector< std::vector< double > > GetPopulation () const
 
virtual std::vector< double > GetSolution (std::size_t index=0) const
 
virtual void SetPopulation (const std::vector< std::vector< double >> &population)
 

Additional Inherited Members

- Public Attributes inherited from Unfit::GenericOptimizer
Unfit::Bounds bounds
 
Unfit::Options options
 
- Protected Member Functions inherited from Unfit::GenericOptimizer
virtual bool CalculateCost (GenericCostFunction &CostFunction, std::vector< double > &x)
 
void GeneratePopulation (GenericCostFunction &CostFunction, std::size_t dimensions)
 
void GenerateRandomEngines ()
 
virtual bool IsConverged (const std::vector< double > &best_member, std::size_t truncated_index=0) const
 Checks to see if the population has converged. More...
 
virtual void PrintFinalOutput () const
 
virtual void SortPopulation () noexcept
 
- Protected Attributes inherited from Unfit::GenericOptimizer
std::vector< std::vector< double > > population_
 
std::vector< std::mt19937 > random_engines_
 
std::atomic< std::size_t > function_evaluations_
 
std::atomic< std::size_t > iterations_
 
bool is_population_based_
 

Detailed Description

Access to the private member functions in the neldermead class.

The main goal of this class is to access the private member functions in the neldermead class in tests. See the documentation of each function for more details.

Member Function Documentation

◆ AccessComputeCentroid()

void Unfit::TestNelderMead::AccessComputeCentroid ( )
inline

create a function to access the private method(ComputeCentroid) in class NelderMead.

Intended use: rc = AccessComputeCentroid()

◆ AccessContractInside()

bool Unfit::TestNelderMead::AccessContractInside ( GenericCostFunction CostFunction)
inline

create a function to access the private method (ContractInside) in class NelderMead.

Intended use: bool rc = AccessContractInside(CostFunction);

Parameters:

Parameters
CostFunction(input) the function to be implemented

Return Codes:

Returns
true = Success; false = Cannot compute

◆ AccessContractOutside()

bool Unfit::TestNelderMead::AccessContractOutside ( GenericCostFunction CostFunction)
inline

create a function to access the private method (ContractOutside) in class NelderMead.

Intended use: bool rc = AccessContractOutside(CostFunction);

Parameters:

Parameters
CostFunction(input) the function to be implemented

Return Codes:

Returns
true = Success; false = Cannot compute

◆ AccessExpand()

bool Unfit::TestNelderMead::AccessExpand ( GenericCostFunction CostFunction)
inline

create a function to access the private method(Expand) in class NelderMead.

Intended use: bool rc = AccessExpand(CostFunction);

Parameters:

Parameters
CostFunction(input) the function specified by the user

Return Codes:

Returns
true = Success; false = Cannot compute

◆ AccessGeneratePopulation()

int Unfit::TestNelderMead::AccessGeneratePopulation ( GenericCostFunction CostFunction,
std::vector< double > &  initial_point 
)
inline

create a function to access the private method(GeneratePopulation) in class NelderMead.

Intended use: AccessGeneratePopulation(CostFunction, min_point)

Parameters:

Parameters
CostFunction(input) the function to be implemented
initial_point(input) vector which contain the initial guess

Return Codes

Returns
GeneratePopulation(CostFunction, initial_point)

◆ AccessInitialiseVectors()

void Unfit::TestNelderMead::AccessInitialiseVectors ( )
inline

Initialise the working vectors population_, contract_, centroid_, reflect_, expand_ to size depending on the dimension of the problem. Elements are assigned 0 value.

Behaviour: For population_: population_[number_of_dimensions+1][number_of_dimensions+1] For the rest: workingvector_[number_of_dimensions+1]

Intended use: AccessInitialiseVectors();

◆ AccessIsDegenerate()

bool Unfit::TestNelderMead::AccessIsDegenerate ( )
inline

Check if the termination criteria are met and stops the NelderMead iteration. Two termination criteria are checked against a user-defined tolerance, and both have to be met. Criteria 1: Check how different the minima calculated are - difference in costs comparing the best vertex to the other vertices Criteria 2: Check how different the coordinates are relative to one another, comparing the best vertex to the other vertices

Intended use: AccessIsDegenerate()

Return Codes:

Returns
false = Termination criteria not met, NOT okay to stop iterating; true = Termination criteria met, okay to stop iterating

◆ AccessPrintIterationOutput()

void Unfit::TestNelderMead::AccessPrintIterationOutput ( double  best_cost)
inline

Calls the PrintIterationOutput method of NelderMead. Requires that the number of iterations, number of function evaluations, cost of the best vertex, and the process be set.

Parameters
best_costThe best cost at the current iteration

◆ AccessReflect()

bool Unfit::TestNelderMead::AccessReflect ( GenericCostFunction CostFunction)
inline

create a function to access the private method(Reflect) in class NelderMead.

Intended use: bool rc = AccessReflect(CostFunction);

Parameters:

Parameters
CostFunction(input) the function to be implemented

Return Codes:

Returns
true = Success; false = Cannot compute

◆ AccessRegeneratePopulation()

int Unfit::TestNelderMead::AccessRegeneratePopulation ( GenericCostFunction CostFunction)
inline

create a function to access the private method(RegeneratePopulation) in class NelderMead.

Intended use: int rc = AccessRegeneratePopulation(CostFunction);

Parameters:

Parameters
CostFunction(input) the function specified by the user
Returns
rc return code; zero upon success, non-zero upon failure

Return Codes: 0 = Success 1 = invalid simplex

◆ AccessShrink()

bool Unfit::TestNelderMead::AccessShrink ( GenericCostFunction CostFunction)
inline

create a function to access the private method(Shrink) in class NelderMead. Intended use: bool rc = AccessShrink(CostFunction);

Parameters:

Parameters
CostFunction(input) the function to be implemented

Return Codes:

Returns
true = Success; false = When the points are the same

◆ GetCentroid()

unsigned Unfit::TestNelderMead::GetCentroid ( std::vector< double > &  store_centroid) const
inline

Gets the centroid coordinates and f(x, y) of the mid point. The mid point vector is stored in a temporary vector store_centroid_. Returns 0 when it is successful.

Intended use: unsigned rc = GetCentroid(store_mid_point);

Parameters:

Parameters
store_centroid(input) a vector of values to be put inside the centroid_ vector

Return Codes:

Returns
0 = Success; 1 = Cannot compute

◆ GetContract()

unsigned Unfit::TestNelderMead::GetContract ( std::vector< double > &  store_contract) const
inline

Gets the expanded coordinates and f(x, y) after the contract function. The vector is stored in a temporary vector store_contract. It returns 0 when it is successful.

Intended use: unsigned rc = GetContract(store_contract);

Parameters:

Parameters
store_contract(input) vector to be filled in with contract_ values obtained from the Contract function

Return Codes:

Returns
0 = Success; 1 = Cannot get the vector

◆ GetCurrentFunctionEvaluation()

std::size_t Unfit::TestNelderMead::GetCurrentFunctionEvaluation ( )
inline

Get the value of the parameter current_function_evaluations

Intended use: unsigned rc = GetCurrentFunctionEvaluation();

Return Code:

Returns
number of function evaluations

◆ GetCurrentIterations()

std::size_t Unfit::TestNelderMead::GetCurrentIterations ( )
inline

Get the value of the parameter current_iterations_

Intended use: unsigned rc = GetCurrentIterations();

Return Code:

Returns
number of iterations;

◆ GetExpand()

unsigned Unfit::TestNelderMead::GetExpand ( std::vector< double > &  store_expand) const
inline

Gets the expanded coordinates and f(x, y) after the expand function. The vector is stored in a temporary vector store_expand. It returns 0 when it is successful.

Intended use: unsigned rc = GetExpand(store_expand);

Parameters:

Parameters
store_expand(input) an empty vector to store the expand_ vector that contains the expand point

Return Codes:

Returns
0 = Success; 1 = Cannot get the vector

◆ GetNumberOfDimensions_()

std::size_t Unfit::TestNelderMead::GetNumberOfDimensions_ ( )
inline

Get the number of dimensions stored in the variable dimensions_. NOTE: the size of the variable must be 2 and above.

Intended use: unsigned rc = GetNumberOfDimensions_();

Return Codes:

Returns
rc = number of dimensions

◆ GetReflect()

unsigned Unfit::TestNelderMead::GetReflect ( std::vector< double > &  store_reflect) const
inline

Gets the reflect point coordinates and f(x, y) of the reflect point. The reflect vector is stored in a temporary vector store_reflect_

Intended use: unsigned rc = GetCentroid(store_reflect);

Parameters:

Parameters
store_reflect(input) a vector of values to be put inside the reflect_ vector

Return Codes:

Returns
0 = Success; 1 = Cannot get the vector

◆ SetCentroid()

void Unfit::TestNelderMead::SetCentroid ( std::vector< double > &  centroid_values)
inline

Set the values stored in the vector centroid_. NOTE: the size of the vector that is passed in must be 3.

Intended use: SetCentroid(centroid_values);

Parameters:

Parameters
centroid_values(input) a vector of values to be put inside the centroid_ vector

◆ SetContract()

void Unfit::TestNelderMead::SetContract ( std::vector< double > &  contract_values)
inline

Set the values stored in the vector contract_. NOTE: the size of the vector that is passed in must be 3.

Intended use: SetContract(Contract_values);

Parameters:

Parameters
contract_values(input) a vector of values to be put inside the contract_ vector

◆ SetNumberOfDimensions_()

void Unfit::TestNelderMead::SetNumberOfDimensions_ ( std::size_t  number_of_dimensions)
inline

Set the number of dimensions stored in the variable dimensions_. NOTE: the size of the variable must be 2 and above.

Intended use: SetNumberOfDimensions_(number of dimensions);

Parameters:

Parameters
number_of_dimensions(input) an integer to be the number of dimensions

◆ SetProcess()

void Unfit::TestNelderMead::SetProcess ( int  process)
inline

Set the value of the Operation enum (process_ variable). See the documentation for NelderMead.hpp to see what entries are valid.

Parameters:

Parameters
processMust be selected from the Operation enum

◆ SetReflect()

void Unfit::TestNelderMead::SetReflect ( std::vector< double > &  reflect_values)
inline

Set the values stored in the vector reflect_. NOTE: the size of the vector that is passed in must be 3.

Intended use: SetReflect(Reflect_values);

Parameters:

Parameters
reflect_values(input) a vector of values to be put inside the reflect_ vector

◆ SetVertices()

void Unfit::TestNelderMead::SetVertices ( std::vector< std::vector< double > > &  vertex)
inline

Set the values stored in the simplex as a vector of vectors NOTE: the size of the vector that is passed in must be at least 2 and include the cost of the vertex. Size of the vector vector should be a matrix of (n+1) x (n+1) where n is the number of dimensions. This function also helps to set the number of dimension based on the size of the vectors given.

Intended use: SetVertices(vertex);

Parameters:

Parameters
vertex(input) a vector of vectors to be put inside the population_ vector

◆ SetWorstVertex()

void Unfit::TestNelderMead::SetWorstVertex ( unsigned  vertex_number)
inline

Set the vertex that has the worst cost. If it is not clear which one it should be, just call AccessSortPopulation, and then the index of the vertex with the worst cost will be the same as the number of dimensions.

Parameters:

Parameters
vertex_numberThe index of the vertex with the worst cost (index starts from zero and ends at dimensions_)

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