6 #ifndef TURI_ACCELERATED_GRADIENT_H_ 7 #define TURI_ACCELERATED_GRADIENT_H_ 10 #include <core/data/flexible_type/flexible_type.hpp> 14 #include <ml/optimization/utils.hpp> 15 #include <ml/optimization/optimization_interface.hpp> 16 #include <ml/optimization/regularizer_interface.hpp> 17 #include <ml/optimization/line_search-inl.hpp> 18 #include <core/logging/table_printer/table_printer.hpp> 28 namespace optimization {
62 template <
typename Vector = DenseVector>
64 const DenseVector& init_point,
65 std::map<std::string, flexible_type>& opts,
66 const std::shared_ptr<regularizer_interface> reg=NULL){
72 logprogress_stream <<
"--------------------------------------------------------" << std::endl;
78 <<
" than subsequent iterations." << std::endl;
88 size_t iter_limit = opts[
"max_iterations"];
89 double convergence_threshold = opts[
"convergence_threshold"];
91 double step_size = opts[
"step_size"];
95 DenseVector point = init_point;
96 DenseVector delta_point = point;
97 DenseVector y = point;
98 DenseVector xp = point;
99 DenseVector x = point;
100 delta_point.setZero();
105 Vector gradient(point.size());
111 std::vector<std::string> stat_info = {std::to_string(iters),
113 std::to_string(step_size),
115 std::vector<std::string> row = model.
get_status(point, stat_info);
116 printer.print_progress_row_strs(iters, row);
124 if (std::isnan(residual) || std::isinf(residual)){
131 while((residual >= convergence_threshold) && (iters < iter_limit)){
142 point = y - gradient * step_size;
144 reg->apply_proximal_operator(point, step_size);
153 delta_point = (point - y);
154 Qply = fy + delta_point.dot(gradient) + 0.5
155 * delta_point.squaredNorm() / step_size;
169 t = (1 + sqrt(1 + 4*tp*tp))/2;
170 y = x + (tp - 1)/t * (x - xp);
172 delta_point = x - xp;
182 if (!delta_point.array().isFinite().all()) {
196 if(std::isinf(fy) || std::isnan(fy)) {
202 stat_info = {std::to_string(iters),
204 std::to_string(step_size),
207 printer.print_progress_row_strs(iters, row);
212 <<
"Residual (" << residual <<
") " 213 <<
"Loss (" << fy <<
") " 216 printer.print_footer();
221 if (iters < iter_limit){
227 stats.
iters =
static_cast<int>(iters);
233 stats.progress_table = printer.get_tracked_table();
OPTIMIZATION_STATUS status
const double OPTIMIZATION_ZERO
Optimization method zero.
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.
solver_return accelerated_gradient(first_order_opt_interface &model, const DenseVector &init_point, std::map< std::string, flexible_type > &opts, const std::shared_ptr< regularizer_interface > reg=NULL)
Numerical overflow. Step size parameter may be too large.
double compute_residual(const DenseVector &gradient)
virtual double compute_function_value(const DenseVector &point, const size_t mbStart=0, const size_t mbSize=-1)
void print_header() const
const double LS_ZERO
Smallest allowable step length.
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).