26 char* buf = (
char*)in;
33 recv(sock, buf, (
unsigned int)(count - done), 0)
35 read(sock, buf, (
unsigned int)(count - done))
41 THROWERRNO(
"read(" << sock <<
"," << count <<
"-" << done <<
")");
64 send(sock, reinterpret_cast<const char*>(&p),
sizeof(p), 0)
66 write(sock, &p,
sizeof(p))
69 THROWERRNO(
"send_prediction write(" << sock <<
")");
86 ss.write(tag.
begin(),
sizeof(char) * tag.
size());
96 auto saved_precision = ss.precision();
97 if (floorf(res) == res)
98 ss << std::setprecision(0);
99 ss << std::fixed << res << std::setprecision(saved_precision);
102 ssize_t len = ss.str().size();
106 std::cerr <<
"write error: " << strerror(errno) << std::endl;
116 std::stringstream ss;
120 ssize_t len = ss.str().size();
124 std::cerr <<
"write error: " << strerror(errno) << std::endl;
131 if (label != FLT_MAX)
140 THROW(
"This reduction does not support single-line examples.");
150 if (!l->is_multiline)
151 THROW(
"This reduction does not support multi-line example.");
162 THROW(
"This reduction does not support single-line examples.");
169 if (!l->is_multiline)
170 THROW(
"This reduction does not support multi-line example.");
178 THROW(
"This reduction does not support single-line examples.");
185 if (!l->is_multiline)
186 THROW(
"This reduction does not support multi-line example.");
192 std::vector<std::string> grams, std::array<uint32_t, NUM_NAMESPACES>& dest,
char* descriptor,
bool quiet)
194 for (
size_t i = 0; i < grams.size(); i++)
196 std::string ngram = grams[i];
197 if (isdigit(ngram[0]))
199 int n = atoi(ngram.c_str());
201 std::cerr <<
"Generating " << n <<
"-" << descriptor <<
" for all namespaces." << std::endl;
202 for (
size_t j = 0; j < 256; j++) dest[j] = n;
204 else if (ngram.size() == 1)
205 std::cout <<
"You must specify the namespace index before the n" << std::endl;
208 int n = atoi(ngram.c_str() + 1);
209 dest[(uint32_t)(
unsigned char)*ngram.c_str()] = n;
211 std::cerr <<
"Generating " << n <<
"-" << descriptor <<
" for " << ngram[0] <<
" namespaces." << std::endl;
216 void compile_limits(std::vector<std::string> limits, std::array<uint32_t, NUM_NAMESPACES>& dest,
bool quiet)
218 for (
size_t i = 0; i < limits.size(); i++)
220 std::string limit = limits[i];
221 if (isdigit(limit[0]))
223 int n = atoi(limit.c_str());
225 std::cerr <<
"limiting to " << n <<
"features for each namespace." << std::endl;
226 for (
size_t j = 0; j < 256; j++) dest[j] = n;
228 else if (limit.size() == 1)
229 std::cout <<
"You must specify the namespace index before the n" << std::endl;
232 int n = atoi(limit.c_str() + 1);
233 dest[(uint32_t)limit[0]] = n;
235 std::cerr <<
"limiting to " << n <<
" for namespaces " << limit[0] << std::endl;
242 std::cerr << message;
248 int ret = std::stringbuf::sync();
252 parent.trace_listener(parent.trace_context, str());
264 sd = &calloc_or_throw<shared_data>();
265 sd->dump_interval = 1.;
266 sd->contraction = 1.;
267 sd->first_observed_label = FLT_MAX;
268 sd->is_more_than_two_labels_observed =
false;
276 cost_sensitive =
nullptr;
284 delete_prediction =
nullptr;
295 preserve_performance_counters =
false;
297 random_positive_weights =
false;
299 weights.sparse =
false;
308 final_prediction_sink.begin() = final_prediction_sink.end() = final_prediction_sink.end_array =
nullptr;
314 random_weights =
false;
315 normal_weights =
false;
316 tnormal_weights =
false;
317 per_feature_regularizer_input =
"";
318 per_feature_regularizer_output =
"";
319 per_feature_regularizer_text =
"";
322 stdout_fileno = _fileno(stdout);
324 stdout_fileno = fileno(stdout);
333 eta_decay_rate = 1.0;
334 initial_weight = 0.0;
335 initial_constant = 0.0;
339 for (
size_t i = 0; i < 256; i++)
344 affix_features[i] = 0;
345 spelling_features[i] = 0;
348 invariant_updates =
true;
354 pass_length = std::numeric_limits<size_t>::max();
357 save_per_pass =
false;
360 do_reset_source =
false;
361 holdout_set_off =
true;
363 check_holdout_every_n_passes = 1;
364 early_terminate =
false;
366 max_examples = std::numeric_limits<size_t>::max();
369 print_invert =
false;
372 progress_add =
false;
375 sd->is_more_than_two_labels_observed =
false;
376 sd->first_observed_label = FLT_MAX;
377 sd->second_observed_label = FLT_MAX;
379 sd->report_multiclass_log_loss =
false;
380 sd->multiclass_log_loss = 0;
381 sd->holdout_multiclass_log_loss = 0;
void finish_example(vw &all, E &ec)
void predict(E &ec, size_t i=0)
void print_result(int f, float res, float, v_array< char > tag)
void get_prediction(int sock, float &res, float &weight)
static ssize_t write_file_or_socket(int f, const void *buf, size_t nbytes)
void trace_listener_cerr(void *, const std::string &message)
void compile_gram(std::vector< std::string > grams, std::array< uint32_t, NUM_NAMESPACES > &dest, char *descriptor, bool quiet)
void binary_print_result(int f, float res, float weight, v_array< char >)
int print_tag(std::stringstream &ss, v_array< char > tag)
float loss(cbify &data, uint32_t label, uint32_t final_prediction)
void finish_example(example &)
single_learner * as_singleline(learner< T, E > *l)
void noop_mm(shared_data *, float)
void compile_limits(std::vector< std::string > limits, std::array< uint32_t, NUM_NAMESPACES > &dest, bool quiet)
std::vector< example * > multi_ex
void send_prediction(int sock, global_prediction p)
void print_raw_text(int f, std::string s, v_array< char > tag)
void all_reduce(vw &all, T *buffer, const size_t n)
trace_message_t trace_listener
size_t really_read(int sock, void *in, size_t count)
void learn(E &ec, size_t i=0)
void set_mm(shared_data *sd, float label)
multi_learner * as_multiline(learner< T, E > *l)