15 size_t orig_size[256];
26 int v = strtoul(s, &endptr, 0);
29 return (*s !=
'\0' && *endptr ==
'\0');
49 template <
bool is_learn>
64 float first_prediction = 0;
66 float first_uncertainty = 0;
70 float scale = (!lrq.
dropout || do_dropout) ? 1.
f : 0.5
f;
73 for (
unsigned int iter = 0; iter < maxiter; ++iter, ++which)
80 for (std::string
const& i : lrq.
lrpairs)
82 unsigned char left = i[which % 2];
83 unsigned char right = i[(which + 1) % 2];
84 unsigned int k = atoi(i.c_str() + 2);
87 for (
unsigned int lfn = 0; lfn < lrq.
orig_size[left]; ++lfn)
89 float lfx = left_fs.values[lfn];
90 uint64_t lindex = left_fs.indicies[lfn] + ec.
ft_offset;
91 for (
unsigned int n = 1; n <= k; ++n)
95 uint64_t lwindex = (lindex + ((uint64_t)n << stride_shift));
103 for (
unsigned int rfn = 0; rfn < lrq.
orig_size[right]; ++rfn)
106 float rfx = right_fs.
values[rfn];
107 uint64_t rindex = right_fs.
indicies[rfn];
108 uint64_t rwindex = (rindex + ((uint64_t)n << stride_shift));
110 right_fs.
push_back(scale * *lw * lfx * rfx, rwindex);
114 std::stringstream new_feature_buffer;
115 new_feature_buffer << right <<
'^' << right_fs.
space_names[rfn].get()->second <<
'^' << n;
118 char* new_space = _strdup(
"lrq");
119 char* new_feature = _strdup(new_feature_buffer.str().c_str());
121 char* new_space = strdup(
"lrq");
122 char* new_feature = strdup(new_feature_buffer.str().c_str());
141 first_loss = ec.
loss;
147 ec.
loss = first_loss;
151 for (std::string
const& i : lrq.
lrpairs)
153 unsigned char right = i[(which + 1) % 2];
161 auto lrq = scoped_calloc_or_throw<LRQstate>();
162 std::vector<std::string> lrq_names;
164 new_options.
add(
make_option(
"lrq", lrq_names).keep().help(
"use low rank quadratic features"))
165 .
add(
make_option(
"lrqdropout", lrq->dropout).keep().help(
"use dropout training for low rank quadratic features"));
176 new (&lrq->lrpairs) std::set<std::string>(lrq_names.begin(), lrq_names.end());
178 lrq->initial_seed = lrq->seed = all.
random_seed | 8675309;
182 all.
trace_message <<
"creating low rank quadratic features for pairs: ";
187 for (std::string
const& i : lrq->lrpairs)
191 if ((i.length() < 3) || !
valid_int(i.c_str() + 2))
192 THROW(
"error, low-rank quadratic features must involve two sets and a rank.");
198 unsigned int k = atoi(i.c_str() + 2);
200 lrq->lrindices[(int)i[0]] =
true;
201 lrq->lrindices[(int)i[1]] =
true;
203 maxk = std::max(k, k);
209 all.
wpp = all.
wpp * (uint64_t)(1 + maxk);
void predict_or_learn(LRQstate &lrq, single_learner &base, example &ec)
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
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::string spoof_hex_encoded_namespaces(const std::string &arg)
float merand48(uint64_t &initial)
base_learner * lrq_setup(options_i &options, vw &all)
constexpr bool example_is_test(example &ec)
bool valid_int(const char *s)
std::set< std::string > lrpairs
float cheesyrand(uint64_t x)
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
bool cheesyrbit(uint64_t &seed)
void reset_seed(LRQstate &lrq)
option_group_definition & add(T &&op)
v_array< audit_strings_ptr > space_names
typed_option< T > make_option(std::string name, T &location)
void set_end_pass(void(*f)(T &))
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