28 CVowpalWabbit::CVowpalWabbit()
54 no_training = vw->no_training;
55 dump_interval = vw->dump_interval;
56 sum_loss_since_last_dump = 0.;
57 reg_name = vw->reg_name;
58 reg_dump_text = vw->reg_dump_text;
59 save_predictions = vw->save_predictions;
60 prediction_fd = vw->prediction_fd;
92 if (adaptive_learning)
124 reg_name = file_name;
125 reg_dump_text = is_text;
130 save_predictions =
true;
131 prediction_fd = open(file_name, O_CREAT|O_TRUNC|O_WRONLY, 0666);
132 if (prediction_fd < 0)
133 SG_SERROR(
"Unable to open prediction file %s for writing!\n", file_name)
155 const char* header_fmt =
"%-10s %-10s %8s %8s %10s %8s %8s\n";
160 "average",
"since",
"example",
"example",
161 "current",
"current",
"current");
163 "loss",
"last",
"counter",
"weight",
"label",
"predict",
"features");
177 if (example->
pass != current_pass)
180 current_pass = example->
pass;
188 output_example(example);
204 for (uint32_t i = 0; i < length; i++)
208 if (reg_name != NULL)
218 prediction = inline_l1_predict(ex);
220 prediction = inline_predict(ex);
235 update = (
env->
eta * exact_norm)/sum_abs_x;
267 dump_interval = exp(1.);
268 sum_loss_since_last_dump = 0.;
270 reg_dump_text =
true;
271 save_predictions =
false;
309 ex->
atomics[(int32_t)(i[1])], thread_mask,
347 if (ret < env->min_label)
353 void CVowpalWabbit::output_example(
VwExample* &example)
357 sum_loss_since_last_dump += example->
loss;
360 print_update(example);
365 if (save_predictions)
375 void CVowpalWabbit::print_update(
VwExample* &ex)
377 SG_SPRINT(
"%-10.6f %-10.6f %8lld %8.1f %8.4f %8.4f %8lu\n",
385 sum_loss_since_last_dump = 0.0;
395 int32_t num = sprintf(temp,
"%f", res);
397 t = write(f, temp, num);
404 t = write(f, temp, 1);
408 t = write(f, tag.
begin,
sizeof(
char)*tag.
index());
409 if (t != (ssize_t) (
sizeof(char)*tag.
index()))
414 t = write(f, temp, 1);
420 void CVowpalWabbit::set_verbose(
bool verbose)
422 quiet=verbose==
false;
433 if (g == 0)
return 0.;
442 float32_t* w_vec = &weights[f->weight_index & thread_mask];
445 sum_abs_x += fabsf(f->x);
468 float32_t update2 = g * page_feature.
x * page_feature.
x;
471 float32_t* w_vec = &weights[(halfhash + elem->weight_index) & mask];
474 sum_abs_x += fabsf(elem->x);
uint32_t weight_index
Hashed index in weight vector.
uint32_t vw_size_t
vw_size_t typedef to work across platforms
CVwRegressor * reg
Regressor.
Class OnlineLinearMachine is a generic interface for linear machines like classifiers which work thro...
void set_adaptive(bool adaptive_learning)
float64_t weighted_examples
Weighted examples.
T * end
Pointer to last set element in the array.
virtual void load_regressor(char *file_name)
virtual void release_example()
virtual void init(CVwEnvironment *env_to_use=NULL)
void set_prediction_out(char *file_name)
T * begin
Pointer to first element of the array.
Class CVwEnvironment is the environment used by VW.
int32_t get_num_elements() const
CLossFunction * loss
Loss function.
T get_element(int32_t index) const
void set_stride(vw_size_t new_stride)
vw_size_t num_features
Number of features.
float64_t min_label
Smallest label seen.
virtual VwExample * get_example()
Class v_array taken directly from JL's implementation.
float32_t one_pf_quad_predict_trunc(float32_t *weights, VwFeature &f, v_array< VwFeature > &cross_features, vw_size_t mask, float32_t gravity)
int64_t example_number
Example number.
float32_t total_sum_feat_sq
Total sum of square of features.
virtual void start_parser()
float32_t ** weight_vectors
Weight vectors, one array for each thread.
float32_t l1_regularization
Level of L1 regularization.
vw_size_t num_bits
log_2 of the number of features
VwAdaptiveLearner uses an adaptive subgradient technique to update weights.
float64_t get_loss(float64_t prediction, float64_t label)
const int32_t quadratic_constant
Constant used while hashing/accessing quadratic features.
float32_t eta
Learning rate.
float32_t real_weight(float32_t w, float32_t gravity)
CVwEnvironment * env
Environment for VW, i.e., globals.
float64_t max_label
Largest label seen.
float32_t label
Label value.
virtual void reset_stream()
float32_t compute_exact_norm_quad(float32_t *weights, VwFeature &page_feature, v_array< VwFeature > &offer_features, vw_size_t mask, float32_t g, float32_t &sum_abs_x)
void load_regressor(char *file_name)
v_array< vw_size_t > indices
Array of namespaces.
virtual void set_learner()
float32_t update_sum
Sum of updates.
bool exact_adaptive_norm
Whether exact norm is used for adaptive learning.
virtual float32_t dense_dot_truncated(const float32_t *vec2, VwExample *&ex, float32_t gravity)
static float32_t invsqrt(float32_t x)
x^0.5, x being a complex128_t
virtual CVwEnvironment * get_env()
float32_t power_t
t power value while updating
float32_t weight
Weight of example.
void push_back(T element)
VwNonAdaptiveLearner uses a standard gradient descent weight update rule.
float32_t eta_decay_rate
Decay rate of eta per pass.
static void clear_cancel()
float32_t compute_exact_norm(VwExample *&ex, float32_t &sum_abs_x)
DynArray< char * > pairs
Pairs of features to cross for quadratic updates.
vw_size_t num_passes
Number of passes.
float32_t final_prediction
Final prediction.
virtual void train(VwExample *&ex, float32_t update)=0
vw_size_t stride
Number of elements in weight vector per feature.
void set_exact_adaptive_norm(bool exact_adaptive)
virtual float32_t predict_and_finalize(VwExample *ex)
float32_t example_t
t value for this example
static bool cancel_computations()
This class implements streaming features for use with VW.
void set_regressor_out(char *file_name, bool is_text=true)
virtual bool get_next_example()
float32_t initial
Initial approximation.
float32_t global_weight
Global weight.
float32_t x
Feature value.
virtual bool train_machine(CFeatures *feat=NULL)
all of classes and functions are contained in the shogun namespace
CStreamingVwFeatures * features
Features.
virtual void end_parser()
The class Features is the base class of all feature objects.
VwLabel * ld
Label object.
float32_t eta_round
Learning rate for this round.
void add_quadratic_pair(char *pair)
void reinitialize_weights()
void(* update)(float *foo, float bar)
Class CVowpalWabbit is the implementation of the online learning algorithm used in Vowpal Wabbit...
vw_size_t thread_mask
Mask used by regressor for learning.
bool adaptive
Whether adaptive learning is used.
float32_t one_pf_quad_predict(float32_t *weights, VwFeature &f, v_array< VwFeature > &cross_features, vw_size_t mask)
virtual float32_t dense_dot(VwExample *&ex, const float32_t *vec2)
vw_size_t passes_complete
Number of passes complete.
virtual void dump_regressor(char *reg_name, bool as_text)
float64_t get_update(float64_t prediction, float64_t label, float64_t eta_t, float64_t norm)
CVwLearner * learner
Learner to use.
virtual float64_t get_square_grad(float64_t prediction, float64_t label)=0
float64_t sum_loss
Sum of losses.
v_array< VwFeature > atomics[256]
Array of features.