6 #ifndef TURI_GRADIENT_DESCENT_H_ 7 #define TURI_GRADIENT_DESCENT_H_ 9 #include <core/data/flexible_type/flexible_type.hpp> 12 #include <ml/optimization/utils.hpp> 13 #include <ml/optimization/optimization_interface.hpp> 14 #include <ml/optimization/regularizer_interface.hpp> 15 #include <ml/optimization/line_search-inl.hpp> 16 #include <core/logging/table_printer/table_printer.hpp> 25 namespace optimization {
48 template <
typename Vector = DenseVector>
50 const DenseVector& init_point,
51 std::map<std::string, flexible_type>& opts,
52 const std::shared_ptr<regularizer_interface> reg=NULL){
59 logprogress_stream <<
"--------------------------------------------------------" << std::endl;
67 size_t iter_limit = opts[
"max_iterations"];
68 double convergence_threshold = opts[
"convergence_threshold"];
69 double step_size = opts[
"step_size"];
82 DenseVector point = init_point;
83 Vector gradient(point.size());
92 DenseVector delta_point = point;
93 delta_point.setZero();
97 <<
" than subsequent iterations." << std::endl;
101 if (!std::isfinite(residual)) {
108 while((residual >= convergence_threshold) && (iters <= iter_limit)){
140 if (ls_stats.
status ==
false){
147 point = point -step_size * gradient;
149 reg->apply_proximal_operator(point, step_size);
150 delta_point = point - delta_point;
158 if (!delta_point.array().array().isFinite().all()) {
170 auto stat_info = {std::to_string(iters),
172 std::to_string(step_size),
175 auto row = model.
get_status(point, stat_info);
176 printer.print_progress_row_strs(iters, row);
179 printer.print_footer();
184 if (iters < iter_limit){
190 stats.
iters =
static_cast<int>(iters);
196 stats.progress_table = printer.get_tracked_table();
OPTIMIZATION_STATUS status
ls_return backtracking(first_order_opt_interface &model, double init_step, double init_func_value, DenseVector point, Vector gradient, DenseVector direction, const std::shared_ptr< regularizer_interface > reg=NULL)
const double OPTIMIZATION_ZERO
Optimization method zero.
ls_return more_thuente(first_order_opt_interface &model, double init_step, double init_func_value, DenseVector point, Vector gradient, DenseVector direction, double function_scaling=1.0, const std::shared_ptr< smooth_regularizer_interface > reg=NULL, size_t max_function_evaluations=LS_MAX_ITER)
solver_return gradient_descent(first_order_opt_interface &model, const DenseVector &init_point, std::map< std::string, flexible_type > &opts, const std::shared_ptr< regularizer_interface > reg=NULL)
virtual std::vector< std::string > get_status(const DenseVector &coefs, const std::vector< std::string > &stats)
virtual std::vector< std::pair< std::string, size_t > > get_status_header(const std::vector< std::string > &stats)
double current_time() const
Returns the elapsed time in seconds since turi::timer::start was last called.
#define logprogress_stream
Optimizer wasn't called.
Line search iteration limit hit.
Numerical overflow. Step size parameter may be too large.
double compute_residual(const DenseVector &gradient)
void print_header() const
A simple class that can be used for benchmarking/timing up to microsecond resolution.
void log_solver_summary_stats(const solver_return &stats, bool simple_mode=false)
virtual void compute_first_order_statistics(const DenseVector &point, DenseVector &gradient, double &function_value, const size_t mbStart=0, const size_t mbSize=-1)=0
Numerical underflow (not enough progress).