14 #define W_INNER 0 // working "inner-loop" weights, updated per example 15 #define W_STABLE 1 // stable weights, updated per stage 16 #define W_STABLEGRAD 2 // gradient corresponding to stable weights 34 inline void vec_add(
float& p,
const float x,
float& w)
44 GD::foreach_feature<float, vec_add<offset> >(all, ec, acc);
96 GD::foreach_feature<update, update_inner_feature>(*s.
all, ec, u);
102 GD::foreach_feature<float, update_stable_feature>(*s.
all, ec, g);
117 std::cout <<
"svrg pass " << pass <<
": committing stable point" << std::endl;
125 std::cout <<
"svrg pass " << pass <<
": computing exact gradient" << std::endl;
134 std::cout <<
"svrg pass " << pass <<
": taking steps" << std::endl;
152 std::stringstream msg;
153 msg <<
":" << resume <<
"\n";
166 using namespace SVRG;
170 auto s = scoped_calloc_or_throw<svrg>();
172 bool svrg_option =
false;
174 new_options.
add(
make_option(
"svrg", svrg_option).keep().help(
"Streaming Stochastic Variance Reduced Gradient"))
175 .
add(
make_option(
"stage_size", s->stage_size).default_value(1).help(
"Number of passes per SVRG stage"));
185 s->stable_grad_count = 0;
float finalize_prediction(shared_data *sd, float ret)
void initialize_regressor(vw &all, T &weights)
base_learner * svrg_setup(options_i &options, vw &all)
float predict_stable(const svrg &s, example &ec)
void update_stable(const svrg &s, example &ec)
base_learner * make_base(learner< T, E > &base)
virtual void add_and_parse(const option_group_definition &group)=0
void set_save_load(void(*sl)(T &, io_buf &, bool, bool))
void update_stable_feature(float &g_scalar, float x, float &w)
virtual float first_derivative(shared_data *, float prediction, float label)=0
void save_load_online_state(vw &all, io_buf &model_file, bool read, bool text, gd *g, std::stringstream &msg, uint32_t ftrl_size, T &weights)
float inline_predict(vw &all, example &ec)
learner< T, E > & init_learner(free_ptr< T > &dat, L *base, void(*learn)(T &, L &, E &), void(*predict)(T &, L &, E &), size_t ws, prediction_type::prediction_type_t pred_type)
float get_weight(vw &all, uint32_t index, uint32_t offset)
void update_inner_feature(update &u, float x, float &w)
void set_weight(vw &all, uint32_t index, uint32_t offset, float value)
float gradient_scalar(const svrg &s, const example &ec, float pred)
option_group_definition & add(T &&op)
void predict(svrg &s, single_learner &, example &ec)
typed_option< T > make_option(std::string name, T &location)
void learn(svrg &s, single_learner &base, example &ec)
constexpr uint64_t UINT64_ONE
void update_inner(const svrg &s, example &ec)
void save_load(svrg &s, io_buf &model_file, bool read, bool text)
void vec_add(float &p, const float x, float &w)
uint32_t num_weights(vw &all)
void save_load_regressor(vw &all, io_buf &model_file, bool read, bool text, T &weights)
size_t bin_text_read_write_fixed(io_buf &io, char *data, size_t len, const char *read_message, bool read, std::stringstream &msg, bool text)