JohnLangford/vowpal_wabbit — pull request #451 by trufanov-nok (2014-11-22 11:06:00+00:00)
Title: Best constant for multilabel squared loss

This Pull Request contains improved best constant function. There are 3 commits:
1. I fond out that for some VW modes best constant is calculated incorrectly bcs of wrong values in shared_data. That happened for --topk and --bootstrap. Although these modes rely on simple_label functionality and call my count_label() function, both overrides a call to return_simple_example() in simple_label with own implementations. (by calling set_finish_example() in learner.h). Unfortunately their implementations of that function are missing code lines which sums up weights and labels in weighted_labels variable. So weighted_labels value is always 0 for topk >0 and --bootstrap > 0. Apparently no one needs weighted_labels value except me :). Now this is fixed.
I suppose, many other modes which are set up in parse_score_users() override default finish_example() too and all of them lack such code for weighted_labels. But they are multiclass based and override all simple_label functions. In other words - best constant can't be calculated for them anyway. So I didn't touch these classes code as currently irrelevant for best constant calculation. Feel free to fix them if it has sense.
2. Second commit adds ability to print only best constant value without best constant loss to main.cc . Loss value is ignored if == FLT_MIN. I've chosen MIN instead of widely used FLT_MAX as loss can't be < 0.
3. There are few changes in best_constant.cc itself.
a). Squared loss constant calculation was replaced with generic formula. It gives same results for 2-label cases as old one, so i've just replaced previous code line.
b). Loss value set to FLT_MIN if it can't be calculated.
c). Instead of sd->Min_Label and sd->Max_Label I've started to use labels which were really encountered in dataset and stored in global variables. I found out that min and max don't represent real data in case all label values in dataset were inside (min,max), for example {0.1, 0.9} in case of squared loss. That allows to improve best constant estimations in at least one test case: test/train-sets/ref/rcv1_small.stderr