537 auto ON = scoped_calloc_or_throw<OjaNewton>();
546 std::string normalize =
"true";
547 std::string random_init =
"true";
549 new_options.add(
make_option(
"OjaNewton", oja_newton).keep().help(
"Online Newton with Oja's Sketch"))
550 .add(
make_option(
"sketch_size", ON->m).default_value(10).help(
"size of sketch"))
551 .
add(
make_option(
"epoch_size", ON->epoch_size).default_value(1).help(
"size of epoch"))
552 .
add(
make_option(
"alpha", ON->alpha).default_value(1.
f).help(
"mutiplicative constant for indentiy"))
553 .
add(
make_option(
"alpha_inverse", alpha_inverse).help(
"one over alpha, similar to learning rate"))
556 .help(
"constant for the learning rate 1/t"))
557 .
add(
make_option(
"normalize", normalize).help(
"normalize the features or not"))
558 .
add(
make_option(
"random_init", random_init).help(
"randomize initialization of Oja or not"));
567 ON->normalize = normalize ==
"true";
568 ON->random_init = random_init ==
"true";
571 ON->alpha = 1.f / alpha_inverse;
575 ON->ev = calloc_or_throw<float>(ON->m + 1);
576 ON->b = calloc_or_throw<float>(ON->m + 1);
577 ON->D = calloc_or_throw<float>(ON->m + 1);
578 ON->A = calloc_or_throw<float*>(ON->m + 1);
579 ON->K = calloc_or_throw<float*>(ON->m + 1);
580 for (
int i = 1; i <= ON->m; i++)
582 ON->A[i] = calloc_or_throw<float>(ON->m + 1);
583 ON->K[i] = calloc_or_throw<float>(ON->m + 1);
589 ON->buffer = calloc_or_throw<example*>(ON->epoch_size);
590 ON->weight_buffer = calloc_or_throw<float>(ON->epoch_size);
592 ON->zv = calloc_or_throw<float>(ON->m + 1);
593 ON->vv = calloc_or_throw<float>(ON->m + 1);
594 ON->tmp = calloc_or_throw<float>(ON->m + 1);
596 ON->data.ON = ON.get();
597 ON->data.Zx = calloc_or_throw<float>(ON->m + 1);
598 ON->data.AZx = calloc_or_throw<float>(ON->m + 1);
599 ON->data.delta = calloc_or_throw<float>(ON->m + 1);
void save_load(OjaNewton &ON, io_buf &model_file, bool read, bool text)
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))
std::shared_ptr< rand_state > get_random_state()
void set_finish_example(void(*f)(vw &all, T &, E &))
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)
void keep_example(vw &all, OjaNewton &, example &ec)
virtual bool was_supplied(const std::string &key)=0
int add(svm_params ¶ms, svm_example *fec)
void predict(OjaNewton &ON, base_learner &, example &ec)
typed_option< T > make_option(std::string name, T &location)
void learn(OjaNewton &ON, base_learner &base, example &ec)