Vowpal Wabbit
Classes | Typedefs | Functions
ACTION_SCORE Namespace Reference

Classes

struct  action_score
 
class  score_iterator
 

Typedefs

typedef v_array< action_scoreaction_scores
 

Functions

void print_action_score (int f, v_array< action_score > &a_s, v_array< char > &tag)
 
void delete_action_scores (void *v)
 
score_iterator begin_scores (action_scores &a_s)
 
score_iterator end_scores (action_scores &a_s)
 
int cmp (size_t a, size_t b)
 
int score_comp (const void *p1, const void *p2)
 
int reverse_order (const void *p1, const void *p2)
 

Typedef Documentation

◆ action_scores

Definition at line 10 of file action_score.h.

Function Documentation

◆ begin_scores()

score_iterator ACTION_SCORE::begin_scores ( action_scores a_s)
inline

◆ cmp()

int ACTION_SCORE::cmp ( size_t  a,
size_t  b 
)
inline

Definition at line 47 of file action_score.h.

Referenced by compute_coherence_metrics(), get_top_weights(), and score_comp().

48 {
49  if (a == b)
50  return 0;
51  if (a > b)
52  return 1;
53  return -1;
54 }
constexpr uint64_t a
Definition: rand48.cc:11

◆ delete_action_scores()

void ACTION_SCORE::delete_action_scores ( void *  v)

◆ end_scores()

score_iterator ACTION_SCORE::end_scores ( action_scores a_s)
inline

◆ print_action_score()

void ACTION_SCORE::print_action_score ( int  f,
v_array< action_score > &  a_s,
v_array< char > &  tag 
)

Definition at line 8 of file action_score.cc.

References print_tag(), v_array< T >::size(), and io_buf::write_file_or_socket().

Referenced by EXPLORE_EVAL::output_example(), VW::cb_explore_adf::cb_explore_adf_base< ExploreType >::output_example(), CB_ADF::output_rank_example(), CSOAA::output_rank_example(), and reverse_order().

9 {
10  if (f >= 0)
11  {
12  std::stringstream ss;
13 
14  for (size_t i = 0; i < a_s.size(); i++)
15  {
16  if (i > 0)
17  ss << ',';
18  ss << a_s[i].action << ':' << a_s[i].score;
19  }
20  print_tag(ss, tag);
21  ss << '\n';
22  ssize_t len = ss.str().size();
23  ssize_t t = io_buf::write_file_or_socket(f, ss.str().c_str(), (unsigned int)len);
24  if (t != len)
25  std::cerr << "write error: " << strerror(errno) << std::endl;
26  }
27 }
static ssize_t write_file_or_socket(int f, const void *buf, size_t nbytes)
Definition: io_buf.cc:140
int print_tag(std::stringstream &ss, v_array< char > tag)
Definition: global_data.cc:81
size_t size() const
Definition: v_array.h:68
float f
Definition: cache.cc:40

◆ reverse_order()

int ACTION_SCORE::reverse_order ( const void *  p1,
const void *  p2 
)
inline

Definition at line 71 of file action_score.h.

References delete_action_scores(), f, print_action_score(), and score_comp().

71 { return score_comp(p2, p1); }
int score_comp(const void *p1, const void *p2)
Definition: action_score.h:56

◆ score_comp()

int ACTION_SCORE::score_comp ( const void *  p1,
const void *  p2 
)
inline

Definition at line 56 of file action_score.h.

References ACTION_SCORE::action_score::action, cmp(), and ACTION_SCORE::action_score::score.

Referenced by CSOAA::do_actual_learning(), and reverse_order().

57 {
58  action_score* s1 = (action_score*)p1;
59  action_score* s2 = (action_score*)p2;
60  // Most sorting algos do not guarantee the output order of elements that compare equal.
61  // Tie-breaking on the index ensures that the result is deterministic across platforms.
62  // However, this forces a strict ordering, rather than a weak ordering, which carries a performance cost.
63  if (s2->score == s1->score)
64  return cmp(s1->action, s2->action);
65  else if (s2->score >= s1->score)
66  return -1;
67  else
68  return 1;
69 }
int cmp(size_t a, size_t b)
Definition: action_score.h:47