/usr/include/vowpalwabbit/example.h is in libvw-dev 8.5.0.dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | /*
Copyright (c) by respective owners including Yahoo!, Microsoft, and
individual contributors. All rights reserved. Released under a BSD
license as described in the file LICENSE.
*/
#pragma once
#include <stdint.h>
#include "v_array.h"
#include "simple_label.h"
#include "multiclass.h"
#include "multilabel.h"
#include "cost_sensitive.h"
#include "cb.h"
#include "constant.h"
#include "feature_group.h"
#include "action_score.h"
const unsigned char wap_ldf_namespace = 126;
const unsigned char history_namespace = 127;
const unsigned char constant_namespace = 128;
const unsigned char nn_output_namespace = 129;
const unsigned char autolink_namespace = 130;
const unsigned char neighbor_namespace = 131; // this is \x83 -- to do quadratic, say "-q a`printf "\x83"` on the command line
const unsigned char affix_namespace = 132; // this is \x84
const unsigned char spelling_namespace = 133; // this is \x85
const unsigned char conditioning_namespace = 134;// this is \x86
const unsigned char dictionary_namespace = 135; // this is \x87
const unsigned char node_id_namespace = 136; // this is \x88
const unsigned char message_namespace = 137; // this is \x89
typedef union
{ label_data simple;
MULTICLASS::label_t multi;
COST_SENSITIVE::label cs;
CB::label cb;
CB_EVAL::label cb_eval;
MULTILABEL::labels multilabels;
} polylabel;
inline void delete_scalars(void* v)
{ v_array<float>* preds = (v_array<float>*)v;
preds->delete_v();
}
typedef union
{ float scalar;
v_array<float> scalars;//a sequence of scalar predictions
ACTION_SCORE::action_scores a_s;//a sequence of classes with scores. Also used for probabilities.
uint32_t multiclass;
MULTILABEL::labels multilabels;
float prob; // for --probabilities --csoaa_ldf=mc
} polyprediction;
typedef unsigned char namespace_index;
struct example // core example datatype.
{ class iterator
{ features* _feature_space;
namespace_index* _index;
public:
iterator(features* feature_space, namespace_index* index)
: _feature_space(feature_space), _index(index)
{ }
features& operator*()
{ return _feature_space[*_index];
}
iterator& operator++()
{ _index++;
return *this;
}
namespace_index index() { return *_index; }
bool operator==(const iterator& rhs) { return _index == rhs._index; }
bool operator!=(const iterator& rhs) { return _index != rhs._index; }
};
//output prediction
polyprediction pred;
// input fields
polylabel l;
float weight;//a relative importance weight for the example, default = 1
v_array<char> tag;//An identifier for the example.
size_t example_counter;
v_array<namespace_index> indices;
features feature_space[256]; //Groups of feature values.
uint64_t ft_offset;//An offset for all feature values.
//helpers
size_t num_features;//precomputed, cause it's fast&easy.
float partial_prediction;//shared data for prediction.
float updated_prediction;//estimated post-update prediction.
float loss;
float total_sum_feat_sq;//precomputed, cause it's kind of fast & easy.
float confidence;
features* passthrough; // if a higher-up reduction wants access to internal state of lower-down reductions, they go here
bool test_only;
bool end_pass;//special example indicating end of pass.
bool sorted;//Are the features sorted or not?
bool in_use; //in use or not (for the parser)
iterator begin() { return iterator(feature_space, indices.begin()); }
iterator end() { return iterator(feature_space, indices.end()); }
};
struct vw;
struct flat_example
{ polylabel l;
size_t tag_len;
char* tag;//An identifier for the example.
size_t example_counter;
uint64_t ft_offset;
float global_weight;
size_t num_features;//precomputed, cause it's fast&easy.
float total_sum_feat_sq;//precomputed, cause it's kind of fast & easy.
features fs;//all the features
};
flat_example* flatten_example(vw& all, example *ec);
flat_example* flatten_sort_example(vw& all, example *ec);
void free_flatten_example(flat_example* fec);
inline int example_is_newline(example& ec)
{ // if only index is constant namespace or no index
if (ec.tag.size() > 0) return false;
return ((ec.indices.size() == 0) ||
((ec.indices.size() == 1) &&
(ec.indices.last() == constant_namespace)));
}
inline bool valid_ns(char c)
{ return !(c == '|' || c == ':');
}
inline void add_passthrough_feature_magic(example& ec, uint64_t magic, uint64_t i, float x)
{ if (ec.passthrough)
ec.passthrough->push_back( x, (FNV_prime * magic) ^ i);
}
#define add_passthrough_feature(ec, i, x) add_passthrough_feature_magic(ec, __FILE__[0]*483901+__FILE__[1]*3417+__FILE__[2]*8490177, i, x);
|