Vowpal Wabbit
Public Member Functions | Public Attributes | Private Attributes | List of all members
LabelObjectState< audit > Class Template Reference

#include <parse_example_json.h>

Inheritance diagram for LabelObjectState< audit >:
BaseState< audit >

Public Member Functions

 LabelObjectState ()
 
void init (vw *)
 
BaseState< audit > * StartObject (Context< audit > &ctx) override
 
BaseState< audit > * Key (Context< audit > &ctx, const char *str, rapidjson::SizeType len, bool) override
 
BaseState< audit > * Float (Context< audit > &ctx, float v) override
 
BaseState< audit > * Uint (Context< audit > &ctx, unsigned v) override
 
BaseState< audit > * EndObject (Context< audit > &ctx, rapidjson::SizeType) override
 
- Public Member Functions inherited from BaseState< audit >
 BaseState (const char *pname)
 
virtual BaseState< audit > * Null (Context< audit > &ctx)
 
virtual BaseState< audit > * Bool (Context< audit > &ctx, bool b)
 
virtual BaseState< audit > * String (Context< audit > &ctx, const char *str, rapidjson::SizeType len, bool)
 
virtual BaseState< audit > * StartArray (Context< audit > &ctx)
 
virtual BaseState< audit > * EndArray (Context< audit > &ctx, rapidjson::SizeType)
 

Public Attributes

CB::cb_class cb_label
 
bool found
 
bool found_cb
 
std::vector< unsigned int > actions
 
std::vector< float > probs
 
std::vector< unsigned int > inc
 
- Public Attributes inherited from BaseState< audit >
const char * name
 

Private Attributes

BaseState< audit > * return_state
 

Detailed Description

template<bool audit>
class LabelObjectState< audit >

Definition at line 155 of file parse_example_json.h.

Constructor & Destructor Documentation

◆ LabelObjectState()

template<bool audit>
LabelObjectState< audit >::LabelObjectState ( )
inline

Definition at line 168 of file parse_example_json.h.

168 : BaseState<audit>("LabelObject") {}

Member Function Documentation

◆ EndObject()

template<bool audit>
BaseState<audit>* LabelObjectState< audit >::EndObject ( Context< audit > &  ctx,
rapidjson::SizeType   
)
inlineoverridevirtual

Reimplemented from BaseState< audit >.

Definition at line 246 of file parse_example_json.h.

References Context< audit >::all, label_type::ccb, CB::cb_class::cost, CB::label::costs, count_label(), Context< audit >::ex, example::l, label_data::label, vw::label_type, vw::sd, polylabel::simple, and THROW.

247  {
248  if (ctx.all->label_type == label_type::ccb)
249  {
250  auto ld = (CCB::label*)&ctx.ex->l;
251 
252  for (auto id : inc)
253  {
254  ld->explicit_included_actions.push_back(id);
255  }
256  inc.clear();
257 
258  if ((actions.size() != 0) && (probs.size() != 0))
259  {
260  auto outcome = new CCB::conditional_contextual_bandit_outcome();
261  outcome->cost = cb_label.cost;
262  if (actions.size() != probs.size())
263  {
264  THROW("Actions and probabilties must be the same length.");
265  }
266 
267  for (size_t i = 0; i < this->actions.size(); i++)
268  {
269  outcome->probabilities.push_back({actions[i], probs[i]});
270  }
271  actions.clear();
272  probs.clear();
273 
274  ld->outcome = outcome;
275  cb_label = {0., 0, 0., 0.};
276  }
277  }
278  else if (found_cb)
279  {
280  CB::label* ld = (CB::label*)&ctx.ex->l;
281  ld->costs.push_back(cb_label);
282 
283  found_cb = false;
284  cb_label = {0., 0, 0., 0.};
285  }
286  else if (found)
287  {
288  count_label(ctx.all->sd, ctx.ex->l.simple.label);
289 
290  found = false;
291  }
292 
293  return return_state;
294  }
label_type::label_type_t label_type
Definition: global_data.h:550
void count_label(shared_data *sd, float l)
Definition: best_constant.h:5
example * ex
BaseState< audit > * return_state
v_array< cb_class > costs
Definition: cb.h:27
float label
Definition: simple_label.h:14
label_data simple
Definition: example.h:28
std::vector< unsigned int > inc
shared_data * sd
Definition: global_data.h:375
polylabel l
Definition: example.h:57
Definition: cb.h:25
float cost
Definition: cb.h:17
std::vector< unsigned int > actions
std::vector< float > probs
#define THROW(args)
Definition: vw_exception.h:181

◆ Float()

template<bool audit>
BaseState<audit>* LabelObjectState< audit >::Float ( Context< audit > &  ctx,
float  v 
)
inlineoverridevirtual

Reimplemented from BaseState< audit >.

Definition at line 201 of file parse_example_json.h.

References _stricmp, CB::cb_class::action, CB::cb_class::cost, Context< audit >::error(), Context< audit >::ex, label_data::initial, Context< audit >::key, Context< audit >::key_length, example::l, label_data::label, CB::cb_class::probability, polylabel::simple, and label_data::weight.

202  {
203  // simple
204  if (!_stricmp(ctx.key, "Label"))
205  {
206  ctx.ex->l.simple.label = v;
207  found = true;
208  }
209  else if (!_stricmp(ctx.key, "Initial"))
210  {
211  ctx.ex->l.simple.initial = v;
212  found = true;
213  }
214  else if (!_stricmp(ctx.key, "Weight"))
215  {
216  ctx.ex->l.simple.weight = v;
217  found = true;
218  }
219  // CB
220  else if (!_stricmp(ctx.key, "Action"))
221  {
222  cb_label.action = (uint32_t)v;
223  found_cb = true;
224  }
225  else if (!_stricmp(ctx.key, "Cost"))
226  {
227  cb_label.cost = v;
228  found_cb = true;
229  }
230  else if (!_stricmp(ctx.key, "Probability"))
231  {
232  cb_label.probability = v;
233  found_cb = true;
234  }
235  else
236  {
237  ctx.error() << "Unsupported label property: '" << ctx.key << "' len: " << ctx.key_length;
238  return nullptr;
239  }
240 
241  return this;
242  }
const char * key
rapidjson::SizeType key_length
example * ex
std::stringstream & error()
float weight
Definition: simple_label.h:15
float label
Definition: simple_label.h:14
label_data simple
Definition: example.h:28
#define _stricmp
uint32_t action
Definition: cb.h:18
float probability
Definition: cb.h:19
float initial
Definition: simple_label.h:16
polylabel l
Definition: example.h:57
float cost
Definition: cb.h:17

◆ init()

template<bool audit>
void LabelObjectState< audit >::init ( vw )
inline

Definition at line 170 of file parse_example_json.h.

Referenced by Context< audit >::init().

171  {
172  found = found_cb = false;
173 
174  cb_label = {0., 0, 0., 0.};
175  }

◆ Key()

template<bool audit>
BaseState<audit>* LabelObjectState< audit >::Key ( Context< audit > &  ctx,
const char *  str,
rapidjson::SizeType  len,
bool   
)
inlineoverridevirtual

Reimplemented from BaseState< audit >.

Definition at line 194 of file parse_example_json.h.

References Context< audit >::key, and Context< audit >::key_length.

195  {
196  ctx.key = str;
197  ctx.key_length = len;
198  return this;
199  }
const char * key
rapidjson::SizeType key_length

◆ StartObject()

template<bool audit>
BaseState<audit>* LabelObjectState< audit >::StartObject ( Context< audit > &  ctx)
inlineoverridevirtual

Reimplemented from BaseState< audit >.

Definition at line 177 of file parse_example_json.h.

References Context< audit >::all, label_parser::default_label, Context< audit >::error(), Context< audit >::ex, example::l, parser::lp, vw::p, and Context< audit >::previous_state.

178  {
179  ctx.all->p->lp.default_label(&ctx.ex->l);
180 
181  // don't allow { { { } } }
182  if (ctx.previous_state == this)
183  {
184  ctx.error() << "invalid label object. nested objected.";
185  return nullptr;
186  }
187 
188  // keep previous state
190 
191  return this;
192  }
void(* default_label)(void *)
Definition: label_parser.h:12
example * ex
BaseState< audit > * return_state
std::stringstream & error()
parser * p
Definition: global_data.h:377
polylabel l
Definition: example.h:57
BaseState< audit > * previous_state
label_parser lp
Definition: parser.h:102

◆ Uint()

template<bool audit>
BaseState<audit>* LabelObjectState< audit >::Uint ( Context< audit > &  ctx,
unsigned  v 
)
inlineoverridevirtual

Reimplemented from BaseState< audit >.

Definition at line 244 of file parse_example_json.h.

244 { return Float(ctx, (float)v); }
BaseState< audit > * Float(Context< audit > &ctx, float v) override

Member Data Documentation

◆ actions

template<bool audit>
std::vector<unsigned int> LabelObjectState< audit >::actions

Definition at line 164 of file parse_example_json.h.

◆ cb_label

template<bool audit>
CB::cb_class LabelObjectState< audit >::cb_label

Definition at line 161 of file parse_example_json.h.

◆ found

template<bool audit>
bool LabelObjectState< audit >::found

Definition at line 162 of file parse_example_json.h.

◆ found_cb

template<bool audit>
bool LabelObjectState< audit >::found_cb

Definition at line 163 of file parse_example_json.h.

◆ inc

template<bool audit>
std::vector<unsigned int> LabelObjectState< audit >::inc

Definition at line 166 of file parse_example_json.h.

◆ probs

template<bool audit>
std::vector<float> LabelObjectState< audit >::probs

Definition at line 165 of file parse_example_json.h.

◆ return_state

template<bool audit>
BaseState<audit>* LabelObjectState< audit >::return_state
private

Definition at line 158 of file parse_example_json.h.


The documentation for this class was generated from the following file: