Vowpal Wabbit
|
#include <cmath>
#include <fstream>
#include <float.h>
#include <netdb.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <sys/timeb.h>
#include "accumulate.h"
#include "reductions.h"
#include "gd.h"
#include "vw_exception.h"
#include <exception>
Go to the source code of this file.
Classes | |
class | curv_exception |
struct | bfgs |
Macros | |
#define | CG_EXTRA 1 |
#define | MEM_GT 0 |
#define | MEM_XT 1 |
#define | MEM_YT 0 |
#define | MEM_ST 1 |
#define | W_XT 0 |
#define | W_GT 1 |
#define | W_DIR 2 |
#define | W_COND 3 |
#define | LEARN_OK 0 |
#define | LEARN_CURV 1 |
#define | LEARN_CONV 2 |
Functions | |
void | zero_derivative (vw &all) |
void | zero_preconditioner (vw &all) |
void | reset_state (vw &all, bfgs &b, bool zero) |
constexpr bool | test_example (example &ec) noexcept |
float | bfgs_predict (vw &all, example &ec) |
void | add_grad (float &d, float f, float &fw) |
float | predict_and_gradient (vw &all, example &ec) |
void | add_precond (float &d, float f, float &fw) |
void | update_preconditioner (vw &all, example &ec) |
void | add_DIR (float &p, const float fx, float &fw) |
float | dot_with_direction (vw &all, example &ec) |
template<class T > | |
double | regularizer_direction_magnitude (vw &, bfgs &b, double regularizer, T &weights) |
double | regularizer_direction_magnitude (vw &all, bfgs &b, float regularizer) |
template<class T > | |
float | direction_magnitude (vw &, T &weights) |
float | direction_magnitude (vw &all) |
template<class T > | |
void | bfgs_iter_start (vw &all, bfgs &b, float *mem, int &lastj, double importance_weight_sum, int &origin, T &weights) |
void | bfgs_iter_start (vw &all, bfgs &b, float *mem, int &lastj, double importance_weight_sum, int &origin) |
template<class T > | |
void | bfgs_iter_middle (vw &all, bfgs &b, float *mem, double *rho, double *alpha, int &lastj, int &origin, T &weights) |
void | bfgs_iter_middle (vw &all, bfgs &b, float *mem, double *rho, double *alpha, int &lastj, int &origin) |
template<class T > | |
double | wolfe_eval (vw &all, bfgs &b, float *mem, double loss_sum, double previous_loss_sum, double step_size, double importance_weight_sum, int &origin, double &wolfe1, T &weights) |
double | wolfe_eval (vw &all, bfgs &b, float *mem, double loss_sum, double previous_loss_sum, double step_size, double importance_weight_sum, int &origin, double &wolfe1) |
template<class T > | |
double | add_regularization (vw &all, bfgs &b, float regularization, T &weights) |
double | add_regularization (vw &all, bfgs &b, float regularization) |
template<class T > | |
void | finalize_preconditioner (vw &, bfgs &b, float regularization, T &weights) |
void | finalize_preconditioner (vw &all, bfgs &b, float regularization) |
template<class T > | |
void | preconditioner_to_regularizer (vw &all, bfgs &b, float regularization, T &weights) |
void | preconditioner_to_regularizer (vw &all, bfgs &b, float regularization) |
template<class T > | |
void | regularizer_to_weight (vw &, bfgs &b, T &weights) |
void | regularizer_to_weight (vw &all, bfgs &b) |
void | zero_state (vw &all) |
template<class T > | |
double | derivative_in_direction (vw &, bfgs &b, float *mem, int &origin, T &weights) |
double | derivative_in_direction (vw &all, bfgs &b, float *mem, int &origin) |
template<class T > | |
void | update_weight (vw &, float step_size, T &w) |
void | update_weight (vw &all, float step_size) |
int | process_pass (vw &all, bfgs &b) |
void | process_example (vw &all, bfgs &b, example &ec) |
void | end_pass (bfgs &b) |
template<bool audit> | |
void | predict (bfgs &b, base_learner &, example &ec) |
template<bool audit> | |
void | learn (bfgs &b, base_learner &base, example &ec) |
void | save_load_regularizer (vw &all, bfgs &b, io_buf &model_file, bool read, bool text) |
void | save_load (bfgs &b, io_buf &model_file, bool read, bool text) |
void | init_driver (bfgs &b) |
base_learner * | bfgs_setup (options_i &options, vw &all) |
Variables | |
curv_exception | curv_ex |
constexpr float | max_precond_ratio = 10000.f |
constexpr const char * | curv_message |
#define CG_EXTRA 1 |
Definition at line 29 of file bfgs.cc.
Referenced by save_load().
#define LEARN_CONV 2 |
Definition at line 43 of file bfgs.cc.
Referenced by process_pass().
#define LEARN_CURV 1 |
Definition at line 42 of file bfgs.cc.
Referenced by process_pass().
#define LEARN_OK 0 |
Definition at line 41 of file bfgs.cc.
Referenced by end_pass(), and process_pass().
#define MEM_GT 0 |
Definition at line 31 of file bfgs.cc.
Referenced by bfgs_iter_middle(), bfgs_iter_start(), derivative_in_direction(), and wolfe_eval().
#define MEM_ST 1 |
Definition at line 34 of file bfgs.cc.
Referenced by bfgs_iter_middle().
#define MEM_XT 1 |
Definition at line 32 of file bfgs.cc.
Referenced by bfgs_iter_middle(), and bfgs_iter_start().
#define MEM_YT 0 |
Definition at line 33 of file bfgs.cc.
Referenced by bfgs_iter_middle().
#define W_COND 3 |
Definition at line 39 of file bfgs.cc.
Referenced by add_precond(), bfgs_iter_middle(), bfgs_iter_start(), finalize_preconditioner(), preconditioner_to_regularizer(), process_pass(), regularizer_to_weight(), wolfe_eval(), zero_preconditioner(), and zero_state().
#define W_DIR 2 |
Definition at line 38 of file bfgs.cc.
Referenced by add_DIR(), bfgs_iter_middle(), bfgs_iter_start(), derivative_in_direction(), direction_magnitude(), regularizer_direction_magnitude(), update_weight(), wolfe_eval(), and zero_state().
#define W_GT 1 |
Definition at line 37 of file bfgs.cc.
Referenced by add_grad(), add_regularization(), bfgs_iter_middle(), bfgs_iter_start(), wolfe_eval(), zero_derivative(), and zero_state().
#define W_XT 0 |
Definition at line 36 of file bfgs.cc.
Referenced by bfgs_iter_middle(), bfgs_iter_start(), and update_weight().
|
inline |
|
inline |
|
inline |
double add_regularization | ( | vw & | all, |
bfgs & | b, | ||
float | regularization, | ||
T & | weights | ||
) |
Definition at line 448 of file bfgs.cc.
References constant, vw::no_bias, bfgs::regularizers, and W_GT.
Referenced by add_regularization(), and process_pass().
Definition at line 489 of file bfgs.cc.
References add_regularization(), parameters::dense_weights, parameters::sparse, parameters::sparse_weights, and vw::weights.
void bfgs_iter_middle | ( | vw & | all, |
bfgs & | b, | ||
float * | mem, | ||
double * | rho, | ||
double * | alpha, | ||
int & | lastj, | ||
int & | origin, | ||
T & | weights | ||
) |
Definition at line 270 of file bfgs.cc.
References curv_ex, f, bfgs::m, MEM_GT, MEM_ST, bfgs::mem_stride, MEM_XT, MEM_YT, vw::num_bits, vw::quiet, W_COND, W_DIR, W_GT, and W_XT.
Referenced by bfgs_iter_middle(), and process_pass().
void bfgs_iter_middle | ( | vw & | all, |
bfgs & | b, | ||
float * | mem, | ||
double * | rho, | ||
double * | alpha, | ||
int & | lastj, | ||
int & | origin | ||
) |
Definition at line 400 of file bfgs.cc.
References bfgs_iter_middle(), parameters::dense_weights, parameters::sparse, parameters::sparse_weights, and vw::weights.
void bfgs_iter_start | ( | vw & | all, |
bfgs & | b, | ||
float * | mem, | ||
int & | lastj, | ||
double | importance_weight_sum, | ||
int & | origin, | ||
T & | weights | ||
) |
Definition at line 238 of file bfgs.cc.
References bfgs::m, MEM_GT, bfgs::mem_stride, MEM_XT, vw::quiet, W_COND, W_DIR, W_GT, and W_XT.
Referenced by bfgs_iter_start(), and process_pass().
void bfgs_iter_start | ( | vw & | all, |
bfgs & | b, | ||
float * | mem, | ||
int & | lastj, | ||
double | importance_weight_sum, | ||
int & | origin | ||
) |
Definition at line 261 of file bfgs.cc.
References bfgs_iter_start(), parameters::dense_weights, parameters::sparse, parameters::sparse_weights, and vw::weights.
Definition at line 149 of file bfgs.cc.
References GD::finalize_prediction(), GD::inline_predict(), example::partial_prediction, and vw::sd.
Referenced by predict(), and predict_and_gradient().
base_learner* bfgs_setup | ( | options_i & | options, |
vw & | all | ||
) |
Definition at line 1093 of file bfgs.cc.
References VW::config::option_group_definition::add(), VW::config::options_i::add_and_parse(), vw::audit, vw::bfgs, LEARNER::end_pass(), VW::config::options_i::get_typed_option(), vw::hash_inv, vw::hessian_on, shared_data::holdout_best_loss, vw::holdout_set_off, init_driver(), LEARNER::init_learner(), LEARNER::make_base(), VW::config::make_option(), vw::numpasses, vw::quiet, save_load(), vw::sd, parameters::stride(), parameters::stride_shift(), THROW, vw::training, and vw::weights.
Referenced by parse_reductions().
double derivative_in_direction | ( | vw & | , |
bfgs & | b, | ||
float * | mem, | ||
int & | origin, | ||
T & | weights | ||
) |
Definition at line 605 of file bfgs.cc.
References MEM_GT, bfgs::mem_stride, and W_DIR.
Referenced by derivative_in_direction(), and process_pass().
Definition at line 616 of file bfgs.cc.
References parameters::dense_weights, derivative_in_direction(), parameters::sparse, parameters::sparse_weights, and vw::weights.
float direction_magnitude | ( | vw & | , |
T & | weights | ||
) |
Definition at line 218 of file bfgs.cc.
References W_DIR.
Referenced by direction_magnitude(), and process_pass().
float direction_magnitude | ( | vw & | all | ) |
Definition at line 228 of file bfgs.cc.
References parameters::dense_weights, direction_magnitude(), parameters::sparse, parameters::sparse_weights, and vw::weights.
Definition at line 179 of file bfgs.cc.
References label_data::initial, example::l, and polylabel::simple.
Referenced by process_example().
void end_pass | ( | bfgs & | b | ) |
Definition at line 897 of file bfgs.cc.
References bfgs::all, bfgs::current_pass, bfgs::early_stop_thres, bfgs::final_pass, vw::final_regressor_name, finalize_regressor(), vw::holdout_set_off, LEARN_OK, bfgs::no_win_counter, bfgs::output_regularizer, process_pass(), set_done(), summarize_holdout_set(), vw::trace_message, and zero_preconditioner().
void finalize_preconditioner | ( | vw & | , |
bfgs & | b, | ||
float | regularization, | ||
T & | weights | ||
) |
Definition at line 498 of file bfgs.cc.
References f, max_precond_ratio, bfgs::regularizers, and W_COND.
Referenced by finalize_preconditioner(), and process_pass().
Definition at line 529 of file bfgs.cc.
References parameters::dense_weights, finalize_preconditioner(), parameters::sparse, parameters::sparse_weights, and vw::weights.
void init_driver | ( | bfgs & | b | ) |
void learn | ( | bfgs & | b, |
base_learner & | base, | ||
example & | ec | ||
) |
Definition at line 965 of file bfgs.cc.
References bfgs::all, bfgs::current_pass, bfgs::final_pass, example::in_use, process_example(), and test_example().
Referenced by LEARNER::init_cost_sensitive_learner(), LEARNER::learner< CB_EXPLORE::cb_explore, example >::init_learner(), LEARNER::init_learner(), LEARNER::init_multiclass_learner(), MWT::predict_or_learn(), VW::cb_explore_adf::softmax::setup(), VW::cb_explore_adf::greedy::setup(), VW::cb_explore_adf::first::setup(), VW::cb_explore_adf::bag::setup(), VW::cb_explore_adf::cover::setup(), and VW::cb_explore_adf::regcb::setup().
void preconditioner_to_regularizer | ( | vw & | all, |
bfgs & | b, | ||
float | regularization, | ||
T & | weights | ||
) |
Definition at line 538 of file bfgs.cc.
References f, vw::num_bits, bfgs::regularizers, THROW, and W_COND.
Referenced by preconditioner_to_regularizer(), and save_load_regularizer().
Definition at line 567 of file bfgs.cc.
References parameters::dense_weights, preconditioner_to_regularizer(), parameters::sparse, parameters::sparse_weights, and vw::weights.
void predict | ( | bfgs & | b, |
base_learner & | , | ||
example & | ec | ||
) |
Definition at line 956 of file bfgs.cc.
References bfgs::all, bfgs_predict(), example::pred, GD::print_audit_features(), and polyprediction::scalar.
Referenced by Search::search::get_metatask_data(), LEARNER::init_cost_sensitive_learner(), LEARNER::learner< CB_EXPLORE::cb_explore, example >::init_learner(), LEARNER::init_learner(), LEARNER::init_multiclass_learner(), ezexample::operator()(), vw_slim::vw_predict< W >::predict(), SequenceTask::run(), SequenceTaskCostToGo::run(), SequenceTask_DemoLDF::run(), VW::cb_explore_adf::softmax::setup(), VW::cb_explore_adf::greedy::setup(), VW::cb_explore_adf::first::setup(), VW::cb_explore_adf::bag::setup(), VW::cb_explore_adf::cover::setup(), and VW::cb_explore_adf::regcb::setup().
Definition at line 157 of file bfgs.cc.
References bfgs_predict(), loss_function::first_derivative(), example::l, label_data::label, vw::loss, vw::sd, vw::set_minmax, polylabel::simple, and example::weight.
Referenced by process_example().
Definition at line 861 of file bfgs.cc.
References bfgs::curvature, dot_with_direction(), bfgs::example_number, bfgs::first_pass, loss_function::getLoss(), bfgs::gradient_pass, bfgs::importance_weight_sum, example::l, label_data::label, example::loss, vw::loss, bfgs::loss_sum, example::partial_prediction, bfgs::preconditioner_pass, example::pred, predict_and_gradient(), bfgs::predictions, v_array< T >::push_back(), polyprediction::scalar, vw::sd, loss_function::second_derivative(), polylabel::simple, v_array< T >::size(), update_preconditioner(), example::updated_prediction, and example::weight.
Referenced by learn().
Definition at line 639 of file bfgs.cc.
References accumulate(), accumulate_scalar(), add_regularization(), vw::all_reduce, bfgs::alpha, bfgs::backstep_on, bfgs_iter_middle(), bfgs_iter_start(), v_array< T >::clear(), bfgs::current_pass, curv_message, bfgs::curvature, derivative_in_direction(), direction_magnitude(), bfgs::example_number, f, vw::final_regressor_name, finalize_preconditioner(), bfgs::first_hessian_on, bfgs::first_pass, bfgs::gradient_pass, vw::hessian_on, vw::holdout_set_off, shared_data::holdout_sum_loss_since_last_pass, bfgs::importance_weight_sum, vw::l2_lambda, bfgs::lastj, LEARN_CONV, LEARN_CURV, LEARN_OK, bfgs::loss_sum, bfgs::mem, bfgs::net_time, bfgs::origin, bfgs::output_regularizer, bfgs::preconditioner_pass, bfgs::predictions, bfgs::previous_loss_sum, vw::quiet, regularizer_direction_magnitude(), bfgs::rel_threshold, bfgs::rho, vw::save_per_pass, save_predictor(), vw::sd, bfgs::step_size, bfgs::t_end_global, update_weight(), W_COND, shared_data::weighted_holdout_examples_since_last_pass, vw::weights, wolfe_eval(), and zero_derivative().
Referenced by end_pass().
double regularizer_direction_magnitude | ( | vw & | , |
bfgs & | b, | ||
double | regularizer, | ||
T & | weights | ||
) |
Definition at line 187 of file bfgs.cc.
References bfgs::regularizers, and W_DIR.
Referenced by process_pass(), and regularizer_direction_magnitude().
Definition at line 203 of file bfgs.cc.
References parameters::dense_weights, regularizer_direction_magnitude(), parameters::sparse, parameters::sparse_weights, and vw::weights.
Definition at line 576 of file bfgs.cc.
References bfgs::regularizers, and W_COND.
Referenced by regularizer_to_weight(), and save_load_regularizer().
Definition at line 589 of file bfgs.cc.
References parameters::dense_weights, regularizer_to_weight(), parameters::sparse, parameters::sparse_weights, and vw::weights.
Definition at line 126 of file bfgs.cc.
References bfgs::curvature, bfgs::first_pass, bfgs::gradient_pass, bfgs::importance_weight_sum, bfgs::lastj, bfgs::loss_sum, bfgs::origin, bfgs::preconditioner_pass, bfgs::previous_loss_sum, zero_derivative(), and zero_preconditioner().
Referenced by save_load().
Definition at line 1026 of file bfgs.cc.
References bfgs::all, bfgs::alpha, bin_text_read_write_fixed(), CG_EXTRA, io_buf::files, initialize_regressor(), vw::l2_lambda, vw::length(), bfgs::m, bfgs::mem, bfgs::mem_stride, bfgs::net_time, vw::num_bits, bfgs::output_regularizer, vw::per_feature_regularizer_input, vw::per_feature_regularizer_output, vw::per_feature_regularizer_text, vw::quiet, bfgs::regularizers, reset_state(), bfgs::rho, GD::save_load_regressor(), save_load_regularizer(), v_array< T >::size(), stride_shift(), parameters::stride_shift(), THROW, and vw::weights.
Referenced by bfgs_setup().
Definition at line 979 of file bfgs.cc.
References bfgs::all, io_buf::bin_read_fixed(), bin_text_write_fixed(), c, vw::l2_lambda, vw::num_bits, bfgs::output_regularizer, preconditioner_to_regularizer(), regularizer_to_weight(), and bfgs::regularizers.
Referenced by save_load().
|
noexcept |
Definition at line 171 of file bfgs.cc.
References example::l, label_data::label, vw::loss, example::pred, polyprediction::scalar, vw::sd, loss_function::second_derivative(), polylabel::simple, and example::weight.
Referenced by process_example().
void update_weight | ( | vw & | , |
float | step_size, | ||
T & | w | ||
) |
void update_weight | ( | vw & | all, |
float | step_size | ||
) |
Definition at line 631 of file bfgs.cc.
References parameters::dense_weights, parameters::sparse, parameters::sparse_weights, update_weight(), and vw::weights.
double wolfe_eval | ( | vw & | all, |
bfgs & | b, | ||
float * | mem, | ||
double | loss_sum, | ||
double | previous_loss_sum, | ||
double | step_size, | ||
double | importance_weight_sum, | ||
int & | origin, | ||
double & | wolfe1, | ||
T & | weights | ||
) |
Definition at line 409 of file bfgs.cc.
References MEM_GT, bfgs::mem_stride, vw::quiet, W_COND, W_DIR, and W_GT.
Referenced by process_pass(), and wolfe_eval().
double wolfe_eval | ( | vw & | all, |
bfgs & | b, | ||
float * | mem, | ||
double | loss_sum, | ||
double | previous_loss_sum, | ||
double | step_size, | ||
double | importance_weight_sum, | ||
int & | origin, | ||
double & | wolfe1 | ||
) |
Definition at line 436 of file bfgs.cc.
References parameters::dense_weights, parameters::sparse, parameters::sparse_weights, vw::weights, and wolfe_eval().
void zero_derivative | ( | vw & | all | ) |
Definition at line 122 of file bfgs.cc.
References parameters::set_zero(), W_GT, and vw::weights.
Referenced by process_pass(), and reset_state().
void zero_preconditioner | ( | vw & | all | ) |
Definition at line 124 of file bfgs.cc.
References parameters::set_zero(), W_COND, and vw::weights.
Referenced by end_pass(), and reset_state().
void zero_state | ( | vw & | all | ) |
Definition at line 597 of file bfgs.cc.
References parameters::set_zero(), W_COND, W_DIR, W_GT, and vw::weights.
curv_exception curv_ex |
Referenced by bfgs_iter_middle().
constexpr const char* curv_message |
Definition at line 116 of file bfgs.cc.
Referenced by process_pass().
constexpr float max_precond_ratio = 10000.f |
Definition at line 60 of file bfgs.cc.
Referenced by finalize_preconditioner().