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

learner.cc « vowpalwabbit - github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0376a00c4039b3e6014139e0b25a2483413ac8e7 (plain)
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
#include "global_data.h"
#include "parser.h"
#include "learner.h"
#include "vw.h"
#include "parse_regressor.h"

void dispatch_example(vw& all, example& ec)
{
  if (ec.test_only || !all.training)
    all.l->predict(ec);
  else
    all.l->learn(ec);
  all.l->finish_example(all, ec);
}

namespace LEARNER
{
  void generic_driver(vw& all)
  {
    example* ec = NULL;

    all.l->init_driver();
    while ( all.early_terminate == false )
      {
	if ((ec = VW::get_example(all.p)) != NULL)//semiblocking operation.
	  {
	    if (ec->indices.size() > 1) // 1+ nonconstant feature. (most common case first)
	      dispatch_example(all, *ec);
	    else if (ec->end_pass)
	      {
		all.l->end_pass();
		VW::finish_example(all, ec);
	      }
	    else if (ec->tag.size() >= 4 && !strncmp((const char*) ec->tag.begin, "save", 4))
	      {// save state command

		string final_regressor_name = all.final_regressor_name;
		
		if ((ec->tag).size() >= 6 && (ec->tag)[4] == '_')
		  final_regressor_name = string(ec->tag.begin+5, (ec->tag).size()-5);
		
		if (!all.quiet)
		  cerr << "saving regressor to " << final_regressor_name << endl;
		save_predictor(all, final_regressor_name, 0);
		
		VW::finish_example(all,ec);
	      }
	    else // empty example
	      dispatch_example(all, *ec);
	  }
	else if (parser_done(all.p))
	  {
	    all.l->end_examples();
	    return;
	  }
      }
    if (all.early_terminate) //drain any extra examples from parser and call end_examples
      while ( all.early_terminate == false )
	{
	  if ((ec = VW::get_example(all.p)) != NULL)//semiblocking operation.
	    VW::finish_example(all, ec);
	  else if (parser_done(all.p))
	    {
	      all.l->end_examples();
	      return;
	    }
	}
  }
}