Vowpal Wabbit
Namespaces | Macros | Functions
bs.h File Reference
#include <memory>

Go to the source code of this file.

Namespaces

 BS
 

Macros

#define BS_TYPE_MEAN   0
 
#define BS_TYPE_VOTE   1
 

Functions

LEARNER::base_learnerbs_setup (VW::config::options_i &options, vw &all)
 
uint32_t BS::weight_gen (std::shared_ptr< rand_state > &state)
 

Macro Definition Documentation

◆ BS_TYPE_MEAN

#define BS_TYPE_MEAN   0

Definition at line 8 of file bs.h.

Referenced by bs_setup(), and predict_or_learn().

◆ BS_TYPE_VOTE

#define BS_TYPE_VOTE   1

Definition at line 9 of file bs.h.

Referenced by bs_setup(), and predict_or_learn().

Function Documentation

◆ bs_setup()

LEARNER::base_learner* bs_setup ( VW::config::options_i options,
vw all 
)

Definition at line 231 of file bs.cc.

References VW::config::option_group_definition::add(), add(), VW::config::options_i::add_and_parse(), LEARNER::as_singleline(), BS_TYPE_MEAN, BS_TYPE_VOTE, finish_example(), vw::get_random_state(), LEARNER::init_learner(), LEARNER::make_base(), VW::config::make_option(), LEARNER::learner< T, E >::set_finish_example(), setup_base(), and VW::config::options_i::was_supplied().

Referenced by parse_reductions().

232 {
233  auto data = scoped_calloc_or_throw<bs>();
234  std::string type_string("mean");
235  option_group_definition new_options("Bootstrap");
236  new_options.add(make_option("bootstrap", data->B).keep().help("k-way bootstrap by online importance resampling"))
237  .add(make_option("bs_type", type_string).keep().help("prediction type {mean,vote}"));
238  options.add_and_parse(new_options);
239 
240  if (!options.was_supplied("bootstrap"))
241  return nullptr;
242 
243  data->ub = FLT_MAX;
244  data->lb = -FLT_MAX;
245 
246  if (options.was_supplied("bs_type"))
247  {
248  if (type_string == "mean")
249  data->bs_type = BS_TYPE_MEAN;
250  else if (type_string == "vote")
251  data->bs_type = BS_TYPE_VOTE;
252  else
253  {
254  std::cerr << "warning: bs_type must be in {'mean','vote'}; resetting to mean." << std::endl;
255  data->bs_type = BS_TYPE_MEAN;
256  }
257  }
258  else // by default use mean
259  data->bs_type = BS_TYPE_MEAN;
260 
261  data->pred_vec = new std::vector<double>();
262  data->pred_vec->reserve(data->B);
263  data->all = &all;
264  data->_random_state = all.get_random_state();
265 
267  data, as_singleline(setup_base(options, all)), predict_or_learn<true>, predict_or_learn<false>, data->B);
269 
270  return make_base(l);
271 }
base_learner * make_base(learner< T, E > &base)
Definition: learner.h:462
virtual void add_and_parse(const option_group_definition &group)=0
std::shared_ptr< rand_state > get_random_state()
Definition: global_data.h:553
single_learner * as_singleline(learner< T, E > *l)
Definition: learner.h:476
void set_finish_example(void(*f)(vw &all, T &, E &))
Definition: learner.h:307
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)
Definition: learner.h:369
virtual bool was_supplied(const std::string &key)=0
#define BS_TYPE_VOTE
Definition: bs.h:9
int add(svm_params &params, svm_example *fec)
Definition: kernel_svm.cc:546
typed_option< T > make_option(std::string name, T &location)
Definition: options.h:80
void finish_example(vw &all, bs &d, example &ec)
Definition: bs.cc:225
#define BS_TYPE_MEAN
Definition: bs.h:8
LEARNER::base_learner * setup_base(options_i &options, vw &all)
Definition: parse_args.cc:1222