Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'vowpalwabbit/bs.cc')
-rw-r--r--vowpalwabbit/bs.cc90
1 files changed, 45 insertions, 45 deletions
diff --git a/vowpalwabbit/bs.cc b/vowpalwabbit/bs.cc
index 482dbdf5..035a5e28 100644
--- a/vowpalwabbit/bs.cc
+++ b/vowpalwabbit/bs.cc
@@ -62,13 +62,13 @@ namespace BS {
return 20.;
}
- void bs_predict_mean(vw& all, example* ec, vector<double> &pred_vec)
+ void bs_predict_mean(vw& all, example& ec, vector<double> &pred_vec)
{
- ec->final_prediction = (float)accumulate(pred_vec.begin(), pred_vec.end(), 0.0)/pred_vec.size();
- ec->loss = all.loss->getLoss(all.sd, ec->final_prediction, ((label_data*)ec->ld)->label) * ((label_data*)ec->ld)->weight;
+ ec.final_prediction = (float)accumulate(pred_vec.begin(), pred_vec.end(), 0.0)/pred_vec.size();
+ ec.loss = all.loss->getLoss(all.sd, ec.final_prediction, ((label_data*)ec.ld)->label) * ((label_data*)ec.ld)->weight;
}
- void bs_predict_vote(vw& all, example* ec, vector<double> &pred_vec)
+ void bs_predict_vote(vw& all, example& ec, vector<double> &pred_vec)
{ //majority vote in linear time
unsigned int counter = 0;
float current_label = 1.;
@@ -92,16 +92,16 @@ namespace BS {
}
if(counter == 0)//no majority exists
{
- ec->final_prediction = -1;
- ec->loss = 1.;
+ ec.final_prediction = -1;
+ ec.loss = 1.;
return;
}
//will output majority if it exists
- ec->final_prediction = current_label;
- if (ec->final_prediction == ((label_data*)ec->ld)->label)
- ec->loss = 0.;
+ ec.final_prediction = current_label;
+ if (ec.final_prediction == ((label_data*)ec.ld)->label)
+ ec.loss = 0.;
else
- ec->loss = 1.;
+ ec.loss = 1.;
}
void print_result(int f, float res, float weight, v_array<char> tag, float lb, float ub)
@@ -127,105 +127,105 @@ namespace BS {
}
}
- void output_example(vw& all, bs* d, example* ec)
+ void output_example(vw& all, bs& d, example& ec)
{
- label_data* ld = (label_data*)ec->ld;
+ label_data* ld = (label_data*)ec.ld;
- if(ec->test_only)
+ if(ec.test_only)
{
all.sd->weighted_holdout_examples += ld->weight;//test weight seen
all.sd->weighted_holdout_examples_since_last_dump += ld->weight;
all.sd->weighted_holdout_examples_since_last_pass += ld->weight;
- all.sd->holdout_sum_loss += ec->loss;
- all.sd->holdout_sum_loss_since_last_dump += ec->loss;
- all.sd->holdout_sum_loss_since_last_pass += ec->loss;//since last pass
+ all.sd->holdout_sum_loss += ec.loss;
+ all.sd->holdout_sum_loss_since_last_dump += ec.loss;
+ all.sd->holdout_sum_loss_since_last_pass += ec.loss;//since last pass
}
else
{
all.sd->weighted_examples += ld->weight;
- all.sd->sum_loss += ec->loss;
- all.sd->sum_loss_since_last_dump += ec->loss;
- all.sd->total_features += ec->num_features;
+ all.sd->sum_loss += ec.loss;
+ all.sd->sum_loss_since_last_dump += ec.loss;
+ all.sd->total_features += ec.num_features;
all.sd->example_number++;
}
if(all.final_prediction_sink.size() != 0)//get confidence interval only when printing out predictions
{
- d->lb = FLT_MAX;
- d->ub = -FLT_MAX;
- for (unsigned i = 0; i < d->pred_vec.size(); i++)
+ d.lb = FLT_MAX;
+ d.ub = -FLT_MAX;
+ for (unsigned i = 0; i < d.pred_vec.size(); i++)
{
- if(d->pred_vec[i] > d->ub)
- d->ub = (float)d->pred_vec[i];
- if(d->pred_vec[i] < d->lb)
- d->lb = (float)d->pred_vec[i];
+ if(d.pred_vec[i] > d.ub)
+ d.ub = (float)d.pred_vec[i];
+ if(d.pred_vec[i] < d.lb)
+ d.lb = (float)d.pred_vec[i];
}
}
for (int* sink = all.final_prediction_sink.begin; sink != all.final_prediction_sink.end; sink++)
- BS::print_result(*sink, ec->final_prediction, 0, ec->tag, d->lb, d->ub);
+ BS::print_result(*sink, ec.final_prediction, 0, ec.tag, d.lb, d.ub);
print_update(all, ec);
}
template <bool is_learn>
- void predict_or_learn(bs* d, learner& base, example* ec)
+ void predict_or_learn(bs& d, learner& base, example& ec)
{
- vw* all = d->all;
+ vw* all = d.all;
bool shouldOutput = all->raw_prediction > 0;
- float weight_temp = ((label_data*)ec->ld)->weight;
+ float weight_temp = ((label_data*)ec.ld)->weight;
string outputString;
stringstream outputStringStream(outputString);
- d->pred_vec.clear();
+ d.pred_vec.clear();
- for (size_t i = 1; i <= d->B; i++)
+ for (size_t i = 1; i <= d.B; i++)
{
- ((label_data*)ec->ld)->weight = weight_temp * weight_gen();
+ ((label_data*)ec.ld)->weight = weight_temp * weight_gen();
if (is_learn)
base.learn(ec, i-1);
else
base.predict(ec, i-1);
- d->pred_vec.push_back(ec->final_prediction);
+ d.pred_vec.push_back(ec.final_prediction);
if (shouldOutput) {
if (i > 1) outputStringStream << ' ';
- outputStringStream << i << ':' << ec->partial_prediction;
+ outputStringStream << i << ':' << ec.partial_prediction;
}
}
- ((label_data*)ec->ld)->weight = weight_temp;
+ ((label_data*)ec.ld)->weight = weight_temp;
- switch(d->bs_type)
+ switch(d.bs_type)
{
case BS_TYPE_MEAN:
- bs_predict_mean(*all, ec, d->pred_vec);
+ bs_predict_mean(*all, ec, d.pred_vec);
break;
case BS_TYPE_VOTE:
- bs_predict_vote(*all, ec, d->pred_vec);
+ bs_predict_vote(*all, ec, d.pred_vec);
break;
default:
- std::cerr << "Unknown bs_type specified: " << d->bs_type << ". Exiting." << endl;
+ std::cerr << "Unknown bs_type specified: " << d.bs_type << ". Exiting." << endl;
throw exception();
}
if (shouldOutput)
- all->print_text(all->raw_prediction, outputStringStream.str(), ec->tag);
+ all->print_text(all->raw_prediction, outputStringStream.str(), ec.tag);
}
- void finish_example(vw& all, bs* d, example* ec)
+ void finish_example(vw& all, bs& d, example& ec)
{
BS::output_example(all, d, ec);
- VW::finish_example(all, ec);
+ VW::finish_example(all, &ec);
}
- void finish(bs* d)
+ void finish(bs& d)
{
- d->pred_vec.~vector();
+ d.pred_vec.~vector();
}
learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm, po::variables_map& vm_file)