54 float k = (float)all.
sd->
t;
57 bool result = (loss_delta <= threshold);
70 float avg_loss = sum_loss / t;
71 float threshold = std::sqrt(c0 * avg_loss / t) + fmax(2.
f * alpha, 4.
f) * c0 * log(t) / t;
84 float avg_loss = sum_loss / t;
85 float pmin = fmin(1.
f / (std::sqrt(t * avg_loss) + log(t)), 0.5
f);
106 float p, q2 = 4.f * pmin * pmin;
114 p = std::sqrt(q2) / (1 + std::sqrt(q2));
131 template <
bool is_learn>
141 float t = (float)a.
all->
sd->
t;
142 float ec_input_weight = ec.
weight;
147 bool in_dis =
dis_test(all, ec, base, prediction, threshold);
149 float importance =
query_decision(a, base, ec, prediction, pmin, in_dis);
155 ec.
weight = ec_input_weight;
158 else if (importance > 0)
161 ec.
weight = ec_input_weight * importance;
174 float q2 = 4.f * pmin * pmin;
175 float p, s, cost, cost_delta = 0;
177 float ec_output_weight = ec.
weight;
185 cost = r * (fmax(importance, 0.
f)) * ((
float)(
sign(prediction) !=
sign(ec_input_label)));
198 p = std::sqrt(q2) / (1.f + std::sqrt(q2));
200 cost_delta = 2.f * cost - r * (fmax(importance, 0.
f)) - s;
206 ec.
weight = ec_input_weight * fabs(cost_delta);
209 base.
learn(ec, i + 1);
224 ec.
weight = ec_output_weight;
232 auto data = scoped_calloc_or_throw<active_cover>();
235 bool active_cover_option =
false;
236 new_options.add(
make_option(
"active_cover", active_cover_option).keep().help(
"enable active learning with cover"))
239 .help(
"active learning mellowness parameter c_0. Default 8."))
242 .help(
"active learning variance upper bound parameter alpha. Default 1."))
244 .default_value(sqrtf(10.
f))
245 .help(
"active learning variance upper bound parameter beta_scale. Default std::sqrt(10)."))
246 .
add(
make_option(
"cover", data->cover_size).keep().default_value(12).help(
"cover size. Default 12."))
247 .
add(
make_option(
"oracular", data->oracular).help(
"Use Oracular-CAL style query or not. Default false."));
250 if (!active_cover_option)
255 data->beta_scale *= data->beta_scale;
258 data->cover_size = 0;
261 THROW(
"error: you can't combine lda and active learning");
264 THROW(
"error: you can't use --active_cover and --active at the same time");
268 data->lambda_n =
new float[data->cover_size];
269 data->lambda_d =
new float[data->cover_size];
271 for (
size_t i = 0; i < data->cover_size; i++)
273 data->lambda_n[i] = 0.f;
274 data->lambda_d[i] = 1.f / 8.f;
279 data, base, predict_or_learn_active_cover<true>, predict_or_learn_active_cover<false>, data->cover_size + 1);
void predict(E &ec, size_t i=0)
std::shared_ptr< rand_state > _random_state
base_learner * active_cover_setup(options_i &options, vw &all)
base_learner * make_base(learner< T, E > &base)
virtual void add_and_parse(const option_group_definition &group)=0
std::shared_ptr< rand_state > get_random_state()
single_learner * as_singleline(learner< T, E > *l)
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)
bool dis_test(vw &all, example &ec, single_learner &base, float, float threshold)
virtual bool was_supplied(const std::string &key)=0
LEARNER::base_learner * l
void predict_or_learn_active_cover(active_cover &a, single_learner &base, example &ec)
float query_decision(active_cover &a, single_learner &l, example &ec, float prediction, float pmin, bool in_dis)
float sensitivity(example &ec, size_t i=0)
float get_pmin(float sum_loss, float t)
int add(svm_params ¶ms, svm_example *fec)
typed_option< T > make_option(std::string name, T &location)
float get_threshold(float sum_loss, float t, float c0, float alpha)
LEARNER::base_learner * setup_base(options_i &options, vw &all)
void learn(E &ec, size_t i=0)