Vowpal Wabbit
Functions | Variables
simple_label.cc File Reference
#include <cstring>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include "cache.h"
#include "accumulate.h"
#include "best_constant.h"

Go to the source code of this file.

Functions

char * bufread_simple_label (shared_data *sd, label_data *ld, char *c)
 
size_t read_cached_simple_label (shared_data *sd, void *v, io_buf &cache)
 
float get_weight (void *v)
 
char * bufcache_simple_label (label_data *ld, char *c)
 
void cache_simple_label (void *v, io_buf &cache)
 
void default_simple_label (void *v)
 
bool test_label (void *v)
 
void delete_simple_label (void *)
 
void parse_simple_label (parser *, shared_data *sd, void *v, v_array< substring > &words)
 
void print_update (vw &all, example &ec)
 
void output_and_account_example (vw &all, example &ec)
 
void return_simple_example (vw &all, void *, example &ec)
 
bool summarize_holdout_set (vw &all, size_t &no_win_counter)
 

Variables

label_parser simple_label
 

Function Documentation

◆ bufcache_simple_label()

char* bufcache_simple_label ( label_data ld,
char *  c 
)

Definition at line 43 of file simple_label.cc.

References c, label_data::initial, label_data::label, and label_data::weight.

Referenced by cache_simple_label().

44 {
45  memcpy(c, &ld->label, sizeof(ld->label));
46  c += sizeof(ld->label);
47  memcpy(c, &ld->weight, sizeof(ld->weight));
48  c += sizeof(ld->weight);
49  memcpy(c, &ld->initial, sizeof(ld->initial));
50  c += sizeof(ld->initial);
51  return c;
52 }
float weight
Definition: simple_label.h:15
float label
Definition: simple_label.h:14
float initial
Definition: simple_label.h:16
constexpr uint64_t c
Definition: rand48.cc:12

◆ bufread_simple_label()

char* bufread_simple_label ( shared_data sd,
label_data ld,
char *  c 
)

Definition at line 10 of file simple_label.cc.

References c, count_label(), label_data::initial, label_data::label, and label_data::weight.

Referenced by read_cached_simple_label().

11 {
12  memcpy(&ld->label, c, sizeof(ld->label));
13  // std::cout << ld->label << " " << sd->is_more_than_two_labels_observed << " " << sd->first_observed_label <<
14  // std::endl;
15  c += sizeof(ld->label);
16  memcpy(&ld->weight, c, sizeof(ld->weight));
17  c += sizeof(ld->weight);
18  memcpy(&ld->initial, c, sizeof(ld->initial));
19  c += sizeof(ld->initial);
20 
21  count_label(sd, ld->label);
22  return c;
23 }
void count_label(shared_data *sd, float l)
Definition: best_constant.h:5
float weight
Definition: simple_label.h:15
float label
Definition: simple_label.h:14
float initial
Definition: simple_label.h:16
constexpr uint64_t c
Definition: rand48.cc:12

◆ cache_simple_label()

void cache_simple_label ( void *  v,
io_buf cache 
)

Definition at line 54 of file simple_label.cc.

References io_buf::buf_write(), bufcache_simple_label(), c, label_data::initial, label_data::label, and label_data::weight.

55 {
56  char* c;
57  label_data* ld = (label_data*)v;
58  cache.buf_write(c, sizeof(ld->label) + sizeof(ld->weight) + sizeof(ld->initial));
59  bufcache_simple_label(ld, c);
60 }
float weight
Definition: simple_label.h:15
float label
Definition: simple_label.h:14
char * bufcache_simple_label(label_data *ld, char *c)
Definition: simple_label.cc:43
float initial
Definition: simple_label.h:16
void buf_write(char *&pointer, size_t n)
Definition: io_buf.cc:94
constexpr uint64_t c
Definition: rand48.cc:12

◆ default_simple_label()

void default_simple_label ( void *  v)

Definition at line 62 of file simple_label.cc.

References label_data::initial, label_data::label, and label_data::weight.

63 {
64  label_data* ld = (label_data*)v;
65  ld->label = FLT_MAX;
66  ld->weight = 1.;
67  ld->initial = 0.;
68 }
float weight
Definition: simple_label.h:15
float label
Definition: simple_label.h:14
float initial
Definition: simple_label.h:16

◆ delete_simple_label()

void delete_simple_label ( void *  )

Definition at line 76 of file simple_label.cc.

76 {}

◆ get_weight()

float get_weight ( void *  v)

Definition at line 37 of file simple_label.cc.

References label_data::weight.

38 {
39  label_data* ld = (label_data*)v;
40  return ld->weight;
41 }
float weight
Definition: simple_label.h:15

◆ output_and_account_example()

void output_and_account_example ( vw all,
example ec 
)

Definition at line 119 of file simple_label.cc.

References f, vw::final_prediction_sink, example::l, label_data::label, example::loss, example::num_features, example::partial_prediction, example::pred, vw::print, print_update(), vw::raw_prediction, polyprediction::scalar, vw::sd, polylabel::simple, v_array< T >::size(), example::tag, example::test_only, shared_data::update(), example::weight, and shared_data::weighted_labels.

Referenced by return_simple_example().

120 {
121  label_data ld = ec.l.simple;
122 
123  all.sd->update(ec.test_only, ld.label != FLT_MAX, ec.loss, ec.weight, ec.num_features);
124  if (ld.label != FLT_MAX && !ec.test_only)
125  all.sd->weighted_labels += ((double)ld.label) * ec.weight;
126 
127  all.print(all.raw_prediction, ec.partial_prediction, -1, ec.tag);
128  for (size_t i = 0; i < all.final_prediction_sink.size(); i++)
129  {
130  int f = (int)all.final_prediction_sink[i];
131  all.print(f, ec.pred.scalar, 0, ec.tag);
132  }
133 
134  print_update(all, ec);
135 }
v_array< char > tag
Definition: example.h:63
int raw_prediction
Definition: global_data.h:519
float scalar
Definition: example.h:45
v_array< int > final_prediction_sink
Definition: global_data.h:518
float partial_prediction
Definition: example.h:68
float label
Definition: simple_label.h:14
label_data simple
Definition: example.h:28
size_t size() const
Definition: v_array.h:68
shared_data * sd
Definition: global_data.h:375
size_t num_features
Definition: example.h:67
double weighted_labels
Definition: global_data.h:144
void print_update(vw &all, example &ec)
void update(bool test_example, bool labeled_example, float loss, float weight, size_t num_features)
Definition: global_data.h:190
float loss
Definition: example.h:70
polylabel l
Definition: example.h:57
polyprediction pred
Definition: example.h:60
float weight
Definition: example.h:62
void(* print)(int, float, float, v_array< char >)
Definition: global_data.h:521
float f
Definition: cache.cc:40
bool test_only
Definition: example.h:76

◆ parse_simple_label()

void parse_simple_label ( parser ,
shared_data sd,
void *  v,
v_array< substring > &  words 
)

Definition at line 78 of file simple_label.cc.

References count_label(), float_of_substring(), label_data::initial, label_data::label, print_substring(), v_array< T >::size(), and label_data::weight.

79 {
80  label_data* ld = (label_data*)v;
81 
82  switch (words.size())
83  {
84  case 0:
85  break;
86  case 1:
87  ld->label = float_of_substring(words[0]);
88  break;
89  case 2:
90  ld->label = float_of_substring(words[0]);
91  ld->weight = float_of_substring(words[1]);
92  break;
93  case 3:
94  ld->label = float_of_substring(words[0]);
95  ld->weight = float_of_substring(words[1]);
96  ld->initial = float_of_substring(words[2]);
97  break;
98  default:
99  std::cout << "Error: " << words.size() << " is too many tokens for a simple label: ";
100  for (unsigned int i = 0; i < words.size(); ++i) print_substring(words[i]);
101  std::cout << std::endl;
102  }
103  count_label(sd, ld->label);
104 }
void count_label(shared_data *sd, float l)
Definition: best_constant.h:5
float weight
Definition: simple_label.h:15
float label
Definition: simple_label.h:14
size_t size() const
Definition: v_array.h:68
float float_of_substring(substring s)
float initial
Definition: simple_label.h:16
void print_substring(substring s)

◆ print_update()

void print_update ( vw all,
example ec 
)

Definition at line 109 of file simple_label.cc.

References vw::bfgs, vw::current_pass, shared_data::dump_interval, vw::holdout_set_off, example::l, label_data::label, example::num_features, example::pred, shared_data::print_update(), vw::progress_add, vw::progress_arg, vw::quiet, polyprediction::scalar, vw::sd, polylabel::simple, shared_data::weighted_labeled_examples, and shared_data::weighted_unlabeled_examples.

Referenced by output_and_account_example().

110 {
112  !all.bfgs)
113  {
115  all.progress_add, all.progress_arg);
116  }
117 }
float scalar
Definition: example.h:45
double weighted_unlabeled_examples
Definition: global_data.h:143
bool quiet
Definition: global_data.h:487
float label
Definition: simple_label.h:14
label_data simple
Definition: example.h:28
bool holdout_set_off
Definition: global_data.h:499
bool progress_add
Definition: global_data.h:545
shared_data * sd
Definition: global_data.h:375
float progress_arg
Definition: global_data.h:546
void print_update(bool holdout_set_off, size_t current_pass, float label, float prediction, size_t num_features, bool progress_add, float progress_arg)
Definition: global_data.h:225
bool bfgs
Definition: global_data.h:412
size_t num_features
Definition: example.h:67
uint64_t current_pass
Definition: global_data.h:396
polylabel l
Definition: example.h:57
double weighted_labeled_examples
Definition: global_data.h:141
polyprediction pred
Definition: example.h:60
float dump_interval
Definition: global_data.h:147

◆ read_cached_simple_label()

size_t read_cached_simple_label ( shared_data sd,
void *  v,
io_buf cache 
)

Definition at line 25 of file simple_label.cc.

References io_buf::buf_read(), bufread_simple_label(), c, label_data::initial, label_data::label, and label_data::weight.

26 {
27  label_data* ld = (label_data*)v;
28  char* c;
29  size_t total = sizeof(ld->label) + sizeof(ld->weight) + sizeof(ld->initial);
30  if (cache.buf_read(c, total) < total)
31  return 0;
32  bufread_simple_label(sd, ld, c);
33 
34  return total;
35 }
float weight
Definition: simple_label.h:15
float label
Definition: simple_label.h:14
char * bufread_simple_label(shared_data *sd, label_data *ld, char *c)
Definition: simple_label.cc:10
float initial
Definition: simple_label.h:16
constexpr uint64_t c
Definition: rand48.cc:12
size_t buf_read(char *&pointer, size_t n)
Definition: io_buf.cc:12

◆ return_simple_example()

void return_simple_example ( vw all,
void *  ,
example ec 
)

Definition at line 137 of file simple_label.cc.

References VW::finish_example(), and output_and_account_example().

Referenced by finish_example(), LEARNER::learner< CB_EXPLORE::cb_explore, example >::init_learner(), and receive_result().

138 {
140  VW::finish_example(all, ec);
141 }
void output_and_account_example(vw &all, example &ec)
void finish_example(vw &, example &)
Definition: parser.cc:881

◆ summarize_holdout_set()

bool summarize_holdout_set ( vw all,
size_t &  no_win_counter 
)

Definition at line 143 of file simple_label.cc.

References accumulate_scalar(), vw::all_reduce, vw::current_pass, f, shared_data::holdout_best_loss, shared_data::holdout_best_pass, shared_data::holdout_sum_loss_since_last_pass, vw::sd, and shared_data::weighted_holdout_examples_since_last_pass.

Referenced by GD::end_pass(), and end_pass().

144 {
145  float thisLoss = (all.sd->weighted_holdout_examples_since_last_pass > 0)
147  : FLT_MAX * 0.5f;
148  if (all.all_reduce != nullptr)
149  thisLoss = accumulate_scalar(all, thisLoss);
150 
153 
154  if (thisLoss < all.sd->holdout_best_loss)
155  {
156  all.sd->holdout_best_loss = thisLoss;
157  all.sd->holdout_best_pass = all.current_pass;
158  no_win_counter = 0;
159  return true;
160  }
161 
162  if ((thisLoss != FLT_MAX) ||
163  (std::isfinite(
164  all.sd->holdout_best_loss))) // it's only a loss if we're not infinite when the previous one wasn't infinite
165  no_win_counter++;
166  return false;
167 }
double holdout_sum_loss_since_last_pass
Definition: global_data.h:163
double holdout_best_loss
Definition: global_data.h:161
AllReduce * all_reduce
Definition: global_data.h:381
shared_data * sd
Definition: global_data.h:375
double weighted_holdout_examples_since_last_pass
Definition: global_data.h:162
uint64_t current_pass
Definition: global_data.h:396
float accumulate_scalar(vw &all, float local_sum)
Definition: accumulate.cc:44
size_t holdout_best_pass
Definition: global_data.h:164
float f
Definition: cache.cc:40

◆ test_label()

bool test_label ( void *  v)

Variable Documentation

◆ simple_label

label_parser simple_label
Initial value:
float get_weight(void *v)
Definition: simple_label.cc:37
void default_simple_label(void *v)
Definition: simple_label.cc:62
void parse_simple_label(parser *, shared_data *sd, void *v, v_array< substring > &words)
Definition: simple_label.cc:78
void delete_simple_label(void *)
Definition: simple_label.cc:76
bool test_label(void *v)
Definition: simple_label.cc:70
size_t read_cached_simple_label(shared_data *sd, void *v, io_buf &cache)
Definition: simple_label.cc:25
void cache_simple_label(void *v, io_buf &cache)
Definition: simple_label.cc:54

Definition at line 106 of file simple_label.cc.

Referenced by baseline_setup(), CSOAA::do_actual_learning_oaa(), CSOAA::do_actual_learning_wap(), CSOAA::make_single_prediction(), parser::parser(), and baseline::~baseline().