8 #ifndef TPZSTOCHASTICSEARCH_H 9 #define TPZSTOCHASTICSEARCH_H 17 template <
typename TVar>
37 std::vector<TVar>
DoSearch(std::function<REAL(std::vector<TVar>)> objective_function,
const uint64_t n_max_iterations, REAL min_relative_error);
46 template <
typename TVar>
56 template <
typename TVar>
59 std::vector<TVar> guess(nvars);
60 for (
unsigned int i = 0; i < nvars; ++i) {
69 uint64_t n_iterations = 0;
70 std::vector<TVar> best_guess = guess;
71 REAL best_score = objective_function(best_guess);
72 REAL relative_error = std::numeric_limits<REAL>::max();
73 while (n_iterations < n_max_iterations && relative_error > min_relative_error) {
74 for (
unsigned int i = 0; i < nvars; ++i) {
77 REAL score = objective_function(guess);
78 if (score < best_score){
79 relative_error = (best_score-score)/best_score;
TPZStochasticSearch(const TPZStochasticSearch &orig)
virtual void resize(const int64_t newsize)
Templated vector implementation.
This class implements a simple vector storage scheme for a templated class T. Utility.
virtual ~TPZStochasticSearch()
int64_t size() const
Returns the number of elements of the vector.
TPZStochasticSearch(const uint64_t n_vars)
void SetDistribution(const uint64_t var, TPZAutoPointer< TPZConstrainedRandom< TVar >> distribution)
#define DebugStop()
Returns a message to user put a breakpoint in.
TPZAutoPointer< TPZConstrainedRandom< TVar > > GetDistribution(const int index) const
Contains declaration of the TPZAutoPointer class which has Increment and Decrement actions are mutexe...
std::vector< TVar > DoSearch(std::function< REAL(std::vector< TVar >)> objective_function, const uint64_t n_max_iterations, REAL min_relative_error)
TPZVec< TPZAutoPointer< TPZConstrainedRandom< TVar > > > fdistributions
This class implements a reference counter mechanism to administer a dynamically allocated object...