34 #ifndef __TASMANIAN_GRADIENT_DESCENT_HPP
35 #define __TASMANIAN_GRADIENT_DESCENT_HPP
90 adaptive_stepsize(initial_stepsize), x(x0) {};
103 inline operator std::vector<double>&() {
return x;};
110 inline void getX(
double x_out[])
const {std::copy_n(x.begin(), x.size(), x_out);}
112 inline std::vector<double>
getX()
const {
return x;}
117 inline void setX(
const double x_new[]) {std::copy_n(x_new, x.size(), x.begin());}
119 inline void setX(
const std::vector<double> &x_new) {
120 checkVarSize(
"GradientDescentState::setCandidate",
"candidate point", x_new.size(), x.size());
126 const double decrease_coeff,
const int max_iterations,
const double tolerance,
129 const double increase_coeff,
const double decrease_coeff,
const int max_iterations,
132 const double tolerance, std::vector<double> &state);
135 double adaptive_stepsize;
136 std::vector<double> x;
160 const double tolerance, std::vector<double> &state);
189 const double increase_coeff,
const double decrease_coeff,
const int max_iterations,
203 const double decrease_coeff,
const int max_iterations,
const double tolerance,
Stores the information about a gradient descent run.
Definition: tsgGradientDescent.hpp:84
GradientDescentState()=delete
The default constructor is NOT allowed.
std::vector< double > getX() const
Overload for when the output is a vector.
Definition: tsgGradientDescent.hpp:112
GradientDescentState & operator=(GradientDescentState &source)=default
Copy assignment.
GradientDescentState & operator=(GradientDescentState &&source)=default
Move assignment.
void setX(const double x_new[])
Set the current candidate point.
Definition: tsgGradientDescent.hpp:117
GradientDescentState(const std::vector< double > &x0, const double initial_stepsize)
Constructor for a gradient descent state with the initial candidate x and stepsize lambda0.
Definition: tsgGradientDescent.hpp:89
double getAdaptiveStepsize() const
Return the stepsize.
Definition: tsgGradientDescent.hpp:108
void getX(double x_out[]) const
Return the current candidate point.
Definition: tsgGradientDescent.hpp:110
size_t getNumDimensions() const
Return the number of dimensions.
Definition: tsgGradientDescent.hpp:106
GradientDescentState(const GradientDescentState &source)=default
Copy constructor.
void setX(const std::vector< double > &x_new)
Overload for when the input is a vector.
Definition: tsgGradientDescent.hpp:119
void setAdaptiveStepsize(const double new_stepsize)
Set the stepsize.
Definition: tsgGradientDescent.hpp:115
GradientDescentState(GradientDescentState &&source)=default
Move constructor.
friend OptimizationStatus GradientDescent(const GradientFunctionSingle &grad, const double stepsize, const int max_iterations, const double tolerance, std::vector< double > &state)
Applies the constant step-size gradient descent algorithm for functions with unbounded domains.
friend OptimizationStatus GradientDescent(const ObjectiveFunctionSingle &func, const GradientFunctionSingle &grad, const ProjectionFunctionSingle &proj, const double increase_coeff, const double decrease_coeff, const int max_iterations, const double tolerance, GradientDescentState &state)
Applies the adaptive gradient descent algorithm on a restricted domain.
friend OptimizationStatus GradientDescent(const ObjectiveFunctionSingle &func, const GradientFunctionSingle &grad, const double increase_coeff, const double decrease_coeff, const int max_iterations, const double tolerance, GradientDescentState &state)
Applies the adaptive gradient descent algorithm on unrestricted domain.
OptimizationStatus GradientDescent(const GradientFunctionSingle &grad, const double stepsize, const int max_iterations, const double tolerance, std::vector< double > &state)
Applies the constant step-size gradient descent algorithm for functions with unbounded domains.
std::function< double(const std::vector< double > &x)> ObjectiveFunctionSingle
Generic non-batched objective function signature.
Definition: tsgOptimizationUtils.hpp:102
std::function< void(const std::vector< double > &x_single, std::vector< double > &grad)> GradientFunctionSingle
Generic non-batched gradient function signature.
Definition: tsgOptimizationUtils.hpp:159
std::function< void(const std::vector< double > &x_single, std::vector< double > &proj)> ProjectionFunctionSingle
Generic non-batched projection function signature.
Definition: tsgOptimizationUtils.hpp:175
void checkVarSize(const std::string method_name, const std::string var_name, const int var_size, const int exp_size)
Definition: tsgOptimizationUtils.hpp:80
Encapsulates the Tasmanian Optimization module.
Definition: TasmanianOptimization.hpp:86
Definition: tsgOptimizationUtils.hpp:65
Utility functions and aliases in the optimization module.