28 if (f_src1.
size() == 0 || f_src2.
size() == 0)
33 all.
trace_message <<
"Namespace '" << (char)in.
n1 <<
"' misses anchor feature with value 1";
39 all.
trace_message <<
"Namespace '" << (char)in.
n2 <<
"' misses anchor feature with value 1";
52 uint64_t base_id1 = f_src1.
indicies[0] & weight_mask;
53 uint64_t base_id2 = f_src2.
indicies[0] & weight_mask;
57 uint64_t prev_id1 = 0;
58 uint64_t prev_id2 = 0;
60 for (
size_t i1 = 1, i2 = 1; i1 < f_src1.
size() && i2 < f_src2.
size();)
63 uint64_t cur_id1 = (uint64_t)(((f_src1.
indicies[i1] & weight_mask) - base_id1) & weight_mask);
64 uint64_t cur_id2 = (uint64_t)(((f_src2.
indicies[i2] & weight_mask) - base_id2) & weight_mask);
67 if (cur_id1 < prev_id1)
69 std::cout <<
"interact features are out of order: " << cur_id1 <<
" < " << prev_id1 <<
". Skipping features." 74 if (cur_id2 < prev_id2)
76 std::cout <<
"interact features are out of order: " << cur_id2 <<
" < " << prev_id2 <<
". Skipping features." 81 if (cur_id1 == cur_id2)
87 else if (cur_id1 < cur_id2)
96 template <
bool is_learn,
bool pr
int_all>
161 make_option(
"interact", s).keep().help(
"Put weights on feature products from namespaces <n1> and <n2>"));
169 std::cerr <<
"Need two namespace arguments to interact: " << s <<
" won't do EXITING\n";
173 auto data = scoped_calloc_or_throw<interact>();
175 data->n1 = (
unsigned char)s[0];
176 data->n2 = (
unsigned char)s[1];
178 std::cerr <<
"Interacting namespaces " << data->n1 <<
" and " << data->n2 << std::endl;
183 data,
as_singleline(
setup_base(options, all)), predict_or_learn<true, true>, predict_or_learn<false, true>, 1);
bool contains_valid_namespaces(vw &all, features &f_src1, features &f_src2, interact &in)
v_array< namespace_index > indices
void predict(E &ec, size_t i=0)
void deep_copy_from(const features &src)
void push_back(feature_value v, feature_index i)
v_array< feature_index > indicies
the core definition of a set of features.
base_learner * make_base(learner< T, E > &base)
v_array< feature_value > values
virtual void add_and_parse(const option_group_definition &group)=0
std::array< features, NUM_NAMESPACES > feature_space
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)
void multiply(features &f_dest, features &f_src2, interact &in)
virtual bool was_supplied(const std::string &key)=0
LEARNER::base_learner * interact_setup(options_i &options, vw &all)
void predict_or_learn(interact &in, LEARNER::single_learner &base, example &ec)
option_group_definition & add(T &&op)
typed_option< T > make_option(std::string name, T &location)
LEARNER::base_learner * setup_base(options_i &options, vw &all)
void learn(E &ec, size_t i=0)