Vowpal Wabbit
Public Member Functions | Public Attributes | List of all members
CLASSWEIGHTS::classweights Struct Reference

Public Member Functions

void load_string (std::string const &source)
 
float get_class_weight (uint32_t klass)
 

Public Attributes

std::unordered_map< uint32_t, float > weights
 

Detailed Description

Definition at line 8 of file classweight.cc.

Member Function Documentation

◆ get_class_weight()

float CLASSWEIGHTS::classweights::get_class_weight ( uint32_t  klass)
inline

Definition at line 36 of file classweight.cc.

References f.

Referenced by CLASSWEIGHTS::predict_or_learn().

37  {
38  auto got = weights.find(klass);
39  if (got == weights.end())
40  return 1.0f;
41  else
42  return got->second;
43  }
std::unordered_map< uint32_t, float > weights
Definition: classweight.cc:10
float f
Definition: cache.cc:40

◆ load_string()

void CLASSWEIGHTS::classweights::load_string ( std::string const &  source)
inline

Definition at line 12 of file classweight.cc.

References THROW.

13  {
14  std::stringstream ss(source);
15  std::string item;
16  while (std::getline(ss, item, ','))
17  {
18  std::stringstream inner_ss(item);
19  std::string klass;
20  std::string weight;
21  std::getline(inner_ss, klass, ':');
22  std::getline(inner_ss, weight, ':');
23 
24  if (!klass.size() || !weight.size())
25  {
26  THROW("error: while parsing --classweight " << item);
27  }
28 
29  int klass_int = std::stoi(klass);
30  float weight_double = std::stof(weight);
31 
32  weights[klass_int] = weight_double;
33  }
34  }
std::unordered_map< uint32_t, float > weights
Definition: classweight.cc:10
float weight
#define THROW(args)
Definition: vw_exception.h:181

Member Data Documentation

◆ weights

std::unordered_map<uint32_t, float> CLASSWEIGHTS::classweights::weights

Definition at line 10 of file classweight.cc.


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