40 uint64_t mask = weights.
mask();
43 bool audit = !fs.space_names.empty();
44 for (
auto&
f : fs.values_indices_audit())
48 std::cout <<
f.audit().get()->first <<
'^' <<
f.audit().get()->second <<
':';
49 std::cout <<
f.index() <<
"(" << ((
f.index() + offset) & mask) <<
")" <<
':' <<
f.value();
50 std::cout <<
':' << (&weights[
f.index()])[offset];
53 for (std::string& i : all.
pairs)
54 if (ec.feature_space[(
unsigned char)i[0]].size() > 0 && ec.feature_space[(
unsigned char)i[1]].size() > 0)
57 for (
size_t k = 1; k <= d.
rank; k++)
62 std::cout <<
'\t' << f1.audit().get()->first << k <<
'^' << f1.audit().get()->second <<
':' 63 << ((f1.index() + k) & mask) <<
"(" << ((f1.index() + offset + k) & mask) <<
")" <<
':' 65 std::cout <<
':' << (&weights[f1.index()])[offset + k];
67 std::cout <<
':' << f2.audit().get()->first << k <<
'^' << f2.audit().get()->second <<
':' 68 << ((f2.index() + k + d.
rank) & mask) <<
"(" << ((f2.index() + offset + k + d.
rank) & mask) <<
")" 70 std::cout <<
':' << (&weights[f2.index()])[offset + k + d.
rank];
72 std::cout <<
':' << (&weights[f1.index()])[offset + k] * (&weights[f2.index()])[offset + k + d.
rank];
77 THROW(
"cannot use triples in matrix factorization");
78 std::cout << std::endl;
112 float linear_prediction = 0.;
115 for (
features& fs : ec) GD::foreach_feature<float, GD::vec_add, T>(weights, fs, linear_prediction);
121 prediction += linear_prediction;
125 if (ec.feature_space[(
int)i[0]].size() > 0 && ec.feature_space[(int)i[1]].size() > 0)
127 for (uint64_t k = 1; k <= d.
rank; k++)
133 GD::foreach_feature<pred_offset, offset_add, T>(weights, ec.feature_space[(int)i[0]], x_dot_l);
139 GD::foreach_feature<pred_offset, offset_add, T>(weights, ec.feature_space[(int)i[1]], x_dot_r);
141 prediction += x_dot_l.
p * x_dot_r.
p;
151 THROW(
"cannot use triples in matrix factorization");
155 ec.partial_prediction = prediction;
161 if (ld.
label != FLT_MAX)
167 return ec.pred.scalar;
182 for (
size_t i = 0; i < fs.
size(); i++)
183 (&weights[fs.
indicies[i]])[offset] += update * fs.
values[i] - regularization * (&weights[fs.
indicies[i]])[offset];
197 float regularization = eta_t * all.
l2_lambda;
200 for (
features& fs : ec) sd_offset_update<T>(weights, fs, 0,
update, regularization);
203 for (std::string& i : all.
pairs)
205 if (ec.feature_space[(
int)i[0]].size() > 0 && ec.feature_space[(int)i[1]].size() > 0)
208 for (
size_t k = 1; k <= d.
rank; k++)
211 float r_dot_x = d.
scalars[2 * k];
213 sd_offset_update<T>(weights, ec.feature_space[(int)i[0]], k, update * r_dot_x, regularization);
216 for (
size_t k = 1; k <= d.
rank; k++)
219 float l_dot_x = d.
scalars[2 * k - 1];
221 sd_offset_update<T>(weights, ec.feature_space[(int)i[1]], k + d.
rank, update * l_dot_x, regularization);
226 THROW(
"cannot use triples in matrix factorization");
241 static void func(
weight& w, uint32_t& stride, uint64_t index)
244 for (
size_t i = 0; i != stride; ++i, ++index) pw[i] = (
float)(0.1 *
merand48(index));
251 uint64_t length = (uint64_t)1 << all.
num_bits;
272 size_t K = d.
rank * 2 + 1;
273 std::stringstream msg;
279 for (uint64_t k = 0; k < K; k++)
294 }
while ((!read && i < length) || (read && brw > 0));
329 auto data = scoped_calloc_or_throw<gdmf>();
332 bool conjugate_gradient =
false;
334 gf_md_options.
add(
make_option(
"rank", data->rank).keep().help(
"rank for matrix factorization."));
337 gf_md_options.
add(
make_option(
"bfgs", bfgs).help(
"Option not supported by this reduction"));
339 make_option(
"conjugate_gradient", conjugate_gradient).help(
"Option not supported by this reduction"));
346 THROW(
"adaptive is not implemented for matrix factorization");
348 THROW(
"normalized is not implemented for matrix factorization");
350 THROW(
"normalized adaptive updates is not implemented for matrix factorization");
352 if (bfgs || conjugate_gradient)
353 THROW(
"bfgs is not implemented for matrix factorization");
356 data->no_win_counter = 0;
359 float temp = ceilf(logf((
float)(data->rank * 2 + 1)) / logf(2.
f));
366 data->early_stop_thres = options.
get_typed_option<
size_t>(
"early_terminate").value();
float finalize_prediction(shared_data *sd, float ret)
virtual float getUpdate(float prediction, float label, float update_scale, float pred_per_update)=0
void offset_add(pred_offset &res, const float fx, float &fw)
void initialize_regressor(vw &all, T &weights)
std::vector< std::string > pairs
void mf_print_offset_features(gdmf &d, example &ec, size_t offset)
v_array< feature_index > indicies
the core definition of a set of features.
void set_default(R &info)
base_learner * make_base(learner< T, E > &base)
v_array< feature_value > values
void finalize_regressor(vw &all, std::string reg_name)
virtual void add_and_parse(const option_group_definition &group)=0
void set_save_load(void(*sl)(T &, io_buf &, bool, bool))
void set_default(R &info)
float merand48(uint64_t &initial)
size_t check_holdout_every_n_passes
bool summarize_holdout_set(vw &all, size_t &no_win_counter)
uint64_t early_stop_thres
void save_predictor(vw &all, std::string reg_name, size_t current_pass)
std::array< features, NUM_NAMESPACES > feature_space
void(* set_minmax)(shared_data *sd, float label)
static void func(weight &w, uint32_t &stride, uint64_t index)
virtual float getLoss(shared_data *, float prediction, float label)=0
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)
typed_option< T > & get_typed_option(const std::string &key)
void end_pass(example &ec, vw &all)
iterator over values, indicies and audit space names
virtual bool was_supplied(const std::string &key)=0
base_learner * gd_mf_setup(options_i &options, vw &all)
void sd_offset_update(T &weights, features &fs, uint64_t offset, float update, float regularization)
dense_parameters dense_weights
void save_load(gdmf &d, io_buf &model_file, bool read, bool text)
weight & strided_index(size_t index)
std::vector< std::string > triples
void predict(gdmf &d, single_learner &, example &ec)
option_group_definition & add(T &&op)
typed_option< T > make_option(std::string name, T &location)
void print_result(int f, float res, v_array< char > tag, float lb, float ub)
constexpr uint64_t UINT64_ONE
void set_end_pass(void(*f)(T &))
sparse_parameters sparse_weights
float mf_predict(gdmf &d, example &ec, T &weights)
void update(gd &g, base_learner &, example &ec)
void mf_print_audit_features(gdmf &d, example &ec, size_t offset)
void learn(gdmf &d, single_learner &, example &ec)
std::string final_regressor_name
size_t bin_text_read_write_fixed(io_buf &io, char *data, size_t len, const char *read_message, bool read, std::stringstream &msg, bool text)
void mf_train(gdmf &d, example &ec, T &weights)