15 size_t orig_size[256];
27 template <
bool is_learn>
36 float first_prediction = 0;
39 unsigned int k = lrq.
k;
40 float sqrtk = (float)std::sqrt(k);
44 for (
unsigned int iter = 0; iter < maxiter; ++iter, ++which)
51 for (std::string::const_iterator i2 = i1 + 1; i2 != lrq.
field_name.end(); ++i2)
53 unsigned char left = (which % 2) ? *i1 : *i2;
54 unsigned char right = ((which + 1) % 2) ? *i1 : *i2;
55 unsigned int lfd_id = lrq.
field_id[left];
56 unsigned int rfd_id = lrq.
field_id[right];
57 for (
unsigned int lfn = 0; lfn < lrq.
orig_size[left]; ++lfn)
60 float lfx = fs.
values[lfn];
62 for (
unsigned int n = 1; n <= k; ++n)
66 float* lw = &all.
weights[lwindex & weight_mask];
71 for (
unsigned int rfn = 0; rfn < lrq.
orig_size[right]; ++rfn)
76 float rfx = rfs.
values[rfn];
78 uint64_t rwindex = (rindex + ((uint64_t)(lfd_id * k + n) <<
stride_shift));
83 std::stringstream new_feature_buffer;
84 new_feature_buffer << right <<
'^' << rfs.
space_names[rfn].get()->second <<
'^' << n;
86 char* new_space = _strdup(
"lrqfa");
87 char* new_feature = _strdup(new_feature_buffer.str().c_str());
89 char* new_space = strdup(
"lrqfa");
90 char* new_feature = strdup(new_feature_buffer.str().c_str());
109 first_loss = ec.
loss;
114 ec.
loss = first_loss;
137 new_options.
add(
make_option(
"lrqfa", lrqfa).keep().help(
"use low rank quadratic features with field aware weights"));
143 auto lrq = scoped_calloc_or_throw<LRQFAstate>();
147 size_t last_index = lrqopt.find_last_not_of(
"0123456789");
148 new (&lrq->field_name) std::string(lrqopt.substr(0, last_index + 1));
149 lrq->k = atoi(lrqopt.substr(last_index + 1).c_str());
152 for (
char i : lrq->field_name) lrq->field_id[(int)i] = fd_id++;
154 all.
wpp = all.
wpp * (uint64_t)(1 + lrq->k);
156 predict_or_learn<false>, 1 + lrq->field_name.size() * lrq->k);
v_array< namespace_index > indices
void predict(E &ec, size_t i=0)
uint64_t stride_shift(const stagewise_poly &poly, uint64_t idx)
void push_back(feature_value v, feature_index i)
std::shared_ptr< audit_strings > audit_strings_ptr
v_array< feature_index > indicies
void predict_or_learn(LRQFAstate &lrq, single_learner &base, example &ec)
LEARNER::base_learner * lrqfa_setup(options_i &options, vw &all)
the core definition of a set of features.
base_learner * make_base(learner< T, E > &base)
constexpr bool example_is_test(example &ec)
v_array< feature_value > values
virtual void add_and_parse(const option_group_definition &group)=0
std::string spoof_hex_encoded_namespaces(const std::string &arg)
float merand48(uint64_t &initial)
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 push_back(const T &new_ele)
virtual bool was_supplied(const std::string &key)=0
unsigned char namespace_index
option_group_definition & add(T &&op)
v_array< audit_strings_ptr > space_names
typed_option< T > make_option(std::string name, T &location)
float cheesyrand(uint64_t x)
LEARNER::base_learner * setup_base(options_i &options, vw &all)
void learn(E &ec, size_t i=0)
std::pair< std::string, std::string > audit_strings