several bug fixing related to bfgs per-feature regulatization
several bug fixing related to bfgs per-feature regulatization

The following bugs have been fixed w.r.t. bfgs per-feature regularization functionality:

1.  Bug: The '--input_feature_regularizer’ command doesn’t read the input regularizer file (unless it is specified with –i command): 

Cause: parse_regressor_args() function in 'parse_regressor.cc' only looks for the “initial_regressor” or “i" input commands. 

Fix: The following code has been added to the parse_regressor_args() function to fix this bug:
if (vm.count("input_feature_regularizer"))
    regs.push_back(vm["input_feature_regularizer"].as<string>());

This makes the '--input_feature_regularizer’ command working correctly. 

2. Bug: Sometimes we may want to do develop a model using per-feature regularization and get a standard VW model file as the output. However, VW always outputs the per-feature regularization output file (which cannot be directly used for testing/prediction) whenever we specify the per-feature regularization input. 

Cause: bfgs.cc:912: 
bool reg_vector = b->output_regularizer || all->per_feature_regularizer_input.length() > 0;  

When the ‘--input_feature_regularizer’ command is specified, the above code makes the execution of save_load_regularizer(*all, *b, model_file, read, text) function [instead of GD::save_load_regressor()], which outputs per-feature regularizer output file, even though the ‘–f’ or ‘–-readab_model’ commands are specified. 

Fix: this bug has been fixed by changing the bfgs.cc:912 as follows:
bool reg_vector = (b->output_regularizer && !read) || (all->per_feature_regularizer_input.length() > 0 && read);
This would make VW only to output the per-feature regularizer output file when we only specify either          ‘--output_feature_regularizer_binary’ or  ‘--output_feature_regularizer_text’ commands.

3. Bug: The per-features regularization functionality doesn’t work correctly:

Cause: In bfgs.cc file, 'preconditioner_to_regularizer()' function is called at the end of each pass ('process_pass()') (bfgs.cc:715), in which following code get executed:
 ...
'b.regularizers[2*i+1] = weights[stride*i]' 
'b.regularizers[2*i] = weights[stride*i+W_COND] + b.regularizers[2*i]
...

The operation 'b.regularizers[2*i+1] = weights[stride*i]' incorrectly resets the input regularizer weights to the weights we learned from that pass, and this would make the magnitude of the total regularization term (calculated in the add_regularization()) zero in the next pass, which should NOT happen. Also, we should not change the values of b.regularizers[2*i] until BFGS terminates. 


Fix: 1. Commented out the call to preconditioner_to_regularizer() in the process_pass().
       2. The bfgs.end_pass() function has been modified.

These modifications in end_pass() function execute the per_feature regularization functionality correctly w.r.t. the following 3 different situations where the learning process can terminate. However, the generation of output regularizer file with both correct weights and regularizer values would be different w.r.t. each of these situation:

1.	Termination due to reaching the convergence (with --holdout_set_off): In the modified function, at the very next call to end_pass() after reaching the convergence, preconditioner_to_regularizer(*all, *b, (*all).l2_lambda) function is called. Before this execution of end_pass(), the curvature/preconditioner terms (w[3]) have been correctly updated w.r.t. the final weights on which the algorithm has converged. In this case, the generated output regularizer file would contain the correct weights and curvature values. 

2.	Termination due to teaching the max number of passes: As soon as the maximum number of passes reached before convergence, while(true) loop in learner.generic_driver() terminates due to parser.cc making the ‘all->p->done = true’. Therefore, in this case, the preconditioner terms are not updated w.r.t. the final weight vector (as there is no further execution of process_example() calls). Therefore, in this case, it is not correct to output the output regularizer file if the ‘--output_feature_regularizer_binary’ or  ‘--output_feature_regularizer_text’ commands is specified. Hence, in the modified version of the end_pass(), when the max number of iterations reached, we set the b->output_regularizer = false to make VW to output the standard VW model file.

3.	Reaching the early termination with the holdout set: When the holdout set is on, after each good pass (in which the holdout set error decreases), the output model file in created (overwritten) by calling finalize_regressor() function. Then the algorithm terminates when we continuously observe 3 bad passes, during which the output model file is not updated. Therefore, with the current execution flow of VW, it is impossible to generate an output regularizer file containing the weights obtained at the final good pass together with the preconditioner terms calculated w.r.t. those weights. Therefore, it is better to switch off the holdout set option, whenever the ‘--output_feature_regularizer_binary’ or  ‘--output_feature_regularizer_text’ commands are specified. The following code has been added to parser_args.cc to enable that:  

       if(!all->holdout_set_off && (vm.count("output_feature_regularizer_binary") ||            vm.count("output_feature_regularizer_text")))
  {
      all->holdout_set_off = true;
      cout<<"Making holdout_set_off=true since output regularizer specified\n";
  }
zermelozf/vw_tuto,deaktator/vowpal_wabbit-jmorra,zzzbit/vowpal_wabbit,stathwang/vowpal_wabbit,stathwang/vowpal_wabbit,robin-lai/vowpal_wabbit,digitalreasoning/vowpal_wabbit,zermelozf/vw_tuto,obrianjunior/vowpal_wabbit,martinpopel/vowpal_wabbit,hhexiy/vowpal_wabbit,danmelamed/vowpal_wabbit,robin-lai/vowpal_wabbit,lhoang29/vowpal_wabbit,tsourolampis/vowpal_wabbit,lmatthieu/myvw,hhexiy/vowpal_wabbit,lmatthieu/myvw,deaktator/vowpal_wabbit,robin-lai/vowpal_wabbit,elkingtonmcb/vowpal_wabbit,haipengl/vowpal_wabbit,jon-morra-zefr/vowpal_wabbit,swjo207/vowpal_wabbit,digitalreasoning/vowpal_wabbit,sandyice74/vowpal_wabbit,abimannans/vowpal_wabbit,haipengl/vowpal_wabbit,digitalreasoning/vowpal_wabbit,VerveWireless/vowpal_wabbit,digitalreasoning/vowpal_wabbit,raosudha89/vowpal_wabbit,multiworldtesting/explore,raosudha89/vowpal_wabbit,danmelamed/vowpal_wabbit,lmatthieu/myvw,haipengl/vowpal_wabbit,marko-asplund/vowpal_wabbit,jmorra/vowpal_wabbit,stathwang/vowpal_wabbit,zermelozf/vw_tuto,sandyice74/vowpal_wabbit,marcovzla/vowpal_wabbit,zachmayer/vowpal_wabbit,feynman0825/vowpal_wabbit,ffyu/vowpal_wabbit,elkingtonmcb/vowpal_wabbit,KaiWeiChang/vowpal_wabbit,swjo207/vowpal_wabbit,robin-lai/vowpal_wabbit,hal3/vowpal_wabbit,multiworldtesting/explore-cpp,pombredanne/vowpal_wabbit,printedheart/vowpal_wabbit,feynman0825/vowpal_wabbit,KaiWeiChang/vowpal_wabbit,danmelamed/vowpal_wabbit,abimannans/vowpal_wabbit,printedheart/vowpal_wabbit,tzukuoh/vowpal_wabbit,printedheart/vowpal_wabbit,haipengl/vowpal_wabbit,VerveWireless/vowpal_wabbit,ml-lab/vowpal_wabbit,swjo207/vowpal_wabbit,gregsharp/vowpal_wabbit,trufanov-nok/vowpal_wabbit,chrinide/vowpal_wabbit,zzzbit/vowpal_wabbit,deaktator/vowpal_wabbit-jmorra,raosudha89/vowpal_wabbit,followyourheart/vowpal_wabbit,followyourheart/vowpal_wabbit,printedheart/vowpal_wabbit,danmelamed/vowpal_wabbit,yonglehou/vowpal_wabbit,jmorra/vowpal_wabbit,trufanov-nok/vowpal_wabbit,virneo/explore-cpp,VerveWireless/vowpal_wabbit,marko-asplund/vowpal_wabbit,jon-morra-zefr/vowpal_wabbit,chrinide/vowpal_wabbit,martinbel/vowpal_wabbit,marcovzla/vowpal_wabbit,marko-asplund/vowpal_wabbit,zzzbit/vowpal_wabbit,zermelozf/vw_tuto,printedheart/vowpal_wabbit,marcovzla/vowpal_wabbit,KaiWeiChang/vowpal_wabbit,pombredanne/vowpal_wabbit,danmelamed/vowpal_wabbit,gregsharp/vowpal_wabbit,sandyice74/vowpal_wabbit,chrinide/vowpal_wabbit,pombredanne/vowpal_wabbit,deaktator/vowpal_wabbit-jmorra,zachmayer/vowpal_wabbit,tzukuoh/vowpal_wabbit,marcovzla/vowpal_wabbit,deaktator/vowpal_wabbit,gregsharp/vowpal_wabbit,jon-morra-zefr/vowpal_wabbit,trufanov-nok/vowpal_wabbit,byzhang/vowpal_wabbit,michaelbrundage/vowpal_wabbit,pombredanne/vowpal_wabbit,hhexiy/vowpal_wabbit,yonglehou/vowpal_wabbit,tzukuoh/vowpal_wabbit,yonglehou/vowpal_wabbit,hal3/vowpal_wabbit,zachmayer/vowpal_wabbit,VerveWireless/vowpal_wabbit,tsourolampis/vowpal_wabbit,virneo/explore,feynman0825/vowpal_wabbit,martinbel/vowpal_wabbit,lhoang29/vowpal_wabbit,obrianjunior/vowpal_wabbit,digitalreasoning/vowpal_wabbit,obrianjunior/vowpal_wabbit,chriszeng8/vowpal_wabbit,chrinide/vowpal_wabbit,tsourolampis/vowpal_wabbit,tzukuoh/vowpal_wabbit,VerveWireless/vowpal_wabbit,jmorra/vowpal_wabbit,gregsharp/vowpal_wabbit,hhexiy/vowpal_wabbit,robin-lai/vowpal_wabbit,jmorra/vowpal_wabbit,byzhang/vowpal_wabbit,raosudha89/vowpal_wabbit,michaelbrundage/vowpal_wabbit,martinbel/vowpal_wabbit,yonglehou/vowpal_wabbit,stathwang/vowpal_wabbit,KaiWeiChang/vowpal_wabbit,raosudha89/vowpal_wabbit,printedheart/vowpal_wabbit,emjotde/vowpal_wabbit,haipengl/vowpal_wabbit,martinbel/vowpal_wabbit,KaiWeiChang/vowpal_wabbit,ml-lab/vowpal_wabbit,followyourheart/vowpal_wabbit,ffyu/vowpal_wabbit,stathwang/vowpal_wabbit,raosudha89/vowpal_wabbit,abimannans/vowpal_wabbit,followyourheart/vowpal_wabbit,deaktator/vowpal_wabbit,obrianjunior/vowpal_wabbit,marko-asplund/vowpal_wabbit,zachmayer/vowpal_wabbit,tzukuoh/vowpal_wabbit,robin-lai/vowpal_wabbit,elkingtonmcb/vowpal_wabbit,zermelozf/vw_tuto,ffyu/vowpal_wabbit,chriszeng8/vowpal_wabbit,stathwang/vowpal_wabbit,jmorra/vowpal_wabbit,elevatedcareers/vowpal_wabbit,pombredanne/vowpal_wabbit,emjotde/vowpal_wabbit,feynman0825/vowpal_wabbit,michaelbrundage/vowpal_wabbit,feynman0825/vowpal_wabbit,trufanov-nok/vowpal_wabbit,martinpopel/vowpal_wabbit,yonglehou/vowpal_wabbit,trufanov-nok/vowpal_wabbit,followyourheart/vowpal_wabbit,martinpopel/vowpal_wabbit,eisber/mwt-ds,gregsharp/vowpal_wabbit,zachmayer/vowpal_wabbit,chrinide/vowpal_wabbit,hal3/vowpal_wabbit,elkingtonmcb/vowpal_wabbit,robin-lai/vowpal_wabbit,marcovzla/vowpal_wabbit,digitalreasoning/vowpal_wabbit,yonglehou/vowpal_wabbit,marko-asplund/vowpal_wabbit,martinbel/vowpal_wabbit,ffyu/vowpal_wabbit,lhoang29/vowpal_wabbit,marko-asplund/vowpal_wabbit,hal3/vowpal_wabbit,byzhang/vowpal_wabbit,danmelamed/vowpal_wabbit,lmatthieu/myvw,pombredanne/vowpal_wabbit,martinpopel/vowpal_wabbit,elkingtonmcb/vowpal_wabbit,hal3/vowpal_wabbit,swjo207/vowpal_wabbit,hhexiy/vowpal_wabbit,byzhang/vowpal_wabbit,obrianjunior/vowpal_wabbit,elevatedcareers/vowpal_wabbit,elkingtonmcb/vowpal_wabbit,zhoususheng/vowpal_wabbit,hal3/vowpal_wabbit,michaelbrundage/vowpal_wabbit,ffyu/vowpal_wabbit,chenmoshushi/vowpal_wabbit,hhexiy/vowpal_wabbit,marcovzla/vowpal_wabbit,abimannans/vowpal_wabbit,martinbel/vowpal_wabbit,swjo207/vowpal_wabbit,followyourheart/vowpal_wabbit,michaelbrundage/vowpal_wabbit,abimannans/vowpal_wabbit,zhoususheng/vowpal_wabbit,chenmoshushi/vowpal_wabbit,trufanov-nok/vowpal_wabbit,zachmayer/vowpal_wabbit,gregsharp/vowpal_wabbit,marcovzla/vowpal_wabbit,martinbel/vowpal_wabbit,ffyu/vowpal_wabbit,danmelamed/vowpal_wabbit,elevatedcareers/vowpal_wabbit,zachmayer/vowpal_wabbit,trufanov-nok/vowpal_wabbit,deaktator/vowpal_wabbit-jmorra,sandyice74/vowpal_wabbit,danmelamed/vowpal_wabbit,zhoususheng/vowpal_wabbit,lhoang29/vowpal_wabbit,chriszeng8/vowpal_wabbit,sandyice74/vowpal_wabbit,printedheart/vowpal_wabbit,byzhang/vowpal_wabbit,marcovzla/vowpal_wabbit,robin-lai/vowpal_wabbit,marcovzla/vowpal_wabbit,KaiWeiChang/vowpal_wabbit,hal3/vowpal_wabbit,raosudha89/vowpal_wabbit,lmatthieu/myvw,eisber/mwt-ds,elkingtonmcb/vowpal_wabbit,printedheart/vowpal_wabbit,chriszeng8/vowpal_wabbit,gregsharp/vowpal_wabbit,deaktator/vowpal_wabbit,haipengl/vowpal_wabbit,sandyice74/vowpal_wabbit,jmorra/vowpal_wabbit,ml-lab/vowpal_wabbit,obrianjunior/vowpal_wabbit,VerveWireless/vowpal_wabbit,deaktator/vowpal_wabbit-jmorra,emjotde/vowpal_wabbit,chrinide/vowpal_wabbit,tzukuoh/vowpal_wabbit,tsourolampis/vowpal_wabbit,trufanov-nok/vowpal_wabbit,ml-lab/vowpal_wabbit,deaktator/vowpal_wabbit-jmorra,gregsharp/vowpal_wabbit,abimannans/vowpal_wabbit,zzzbit/vowpal_wabbit,tzukuoh/vowpal_wabbit,marko-asplund/vowpal_wabbit,zachmayer/vowpal_wabbit,zhoususheng/vowpal_wabbit,sandyice74/vowpal_wabbit,zachmayer/vowpal_wabbit,multiworldtesting/explore,obrianjunior/vowpal_wabbit,lhoang29/vowpal_wabbit,yonglehou/vowpal_wabbit,chriszeng8/vowpal_wabbit,hal3/vowpal_wabbit,martinpopel/vowpal_wabbit,deaktator/vowpal_wabbit,zhoususheng/vowpal_wabbit,deaktator/vowpal_wabbit,zermelozf/vw_tuto,swjo207/vowpal_wabbit,zhoususheng/vowpal_wabbit,hal3/vowpal_wabbit,ffyu/vowpal_wabbit,marko-asplund/vowpal_wabbit,jon-morra-zefr/vowpal_wabbit,feynman0825/vowpal_wabbit,deaktator/vowpal_wabbit-jmorra,zhoususheng/vowpal_wabbit,ml-lab/vowpal_wabbit,robin-lai/vowpal_wabbit,deaktator/vowpal_wabbit,byzhang/vowpal_wabbit,hhexiy/vowpal_wabbit,chenmoshushi/vowpal_wabbit,zzzbit/vowpal_wabbit,chriszeng8/vowpal_wabbit,tzukuoh/vowpal_wabbit,yonglehou/vowpal_wabbit,tsourolampis/vowpal_wabbit,lmatthieu/myvw,deaktator/vowpal_wabbit-jmorra,VerveWireless/vowpal_wabbit,KaiWeiChang/vowpal_wabbit,deaktator/vowpal_wabbit,jon-morra-zefr/vowpal_wabbit,ffyu/vowpal_wabbit,elkingtonmcb/vowpal_wabbit,jon-morra-zefr/vowpal_wabbit,gregsharp/vowpal_wabbit,chriszeng8/vowpal_wabbit,feynman0825/vowpal_wabbit,elevatedcareers/vowpal_wabbit,chenmoshushi/vowpal_wabbit,zachmayer/vowpal_wabbit,marko-asplund/vowpal_wabbit,VerveWireless/vowpal_wabbit,zzzbit/vowpal_wabbit,zzzbit/vowpal_wabbit,deaktator/vowpal_wabbit,zzzbit/vowpal_wabbit,jon-morra-zefr/vowpal_wabbit,jon-morra-zefr/vowpal_wabbit,chriszeng8/vowpal_wabbit,elkingtonmcb/vowpal_wabbit,multiworldtesting/explore,raosudha89/vowpal_wabbit,pombredanne/vowpal_wabbit,chenmoshushi/vowpal_wabbit,jmorra/vowpal_wabbit,swjo207/vowpal_wabbit,zhoususheng/vowpal_wabbit,multiworldtesting/explore-cpp,marcovzla/vowpal_wabbit,deaktator/vowpal_wabbit,michaelbrundage/vowpal_wabbit,danmelamed/vowpal_wabbit,stathwang/vowpal_wabbit,michaelbrundage/vowpal_wabbit,byzhang/vowpal_wabbit,chrinide/vowpal_wabbit,swjo207/vowpal_wabbit,ml-lab/vowpal_wabbit,elevatedcareers/vowpal_wabbit,lmatthieu/myvw,hhexiy/vowpal_wabbit,emjotde/vowpal_wabbit,tsourolampis/vowpal_wabbit,hhexiy/vowpal_wabbit,ml-lab/vowpal_wabbit,jmorra/vowpal_wabbit,deaktator/vowpal_wabbit-jmorra,michaelbrundage/vowpal_wabbit,virneo/explore,sandyice74/vowpal_wabbit,emjotde/vowpal_wabbit,sandyice74/vowpal_wabbit,pombredanne/vowpal_wabbit,multiworldtesting/explore-csharp,elevatedcareers/vowpal_wabbit,lhoang29/vowpal_wabbit,tsourolampis/vowpal_wabbit,zermelozf/vw_tuto,lmatthieu/myvw,marko-asplund/vowpal_wabbit,abimannans/vowpal_wabbit,sidsen/mwt-ds-decision,ml-lab/vowpal_wabbit,michaelbrundage/vowpal_wabbit,elevatedcareers/vowpal_wabbit,hhexiy/vowpal_wabbit,chriszeng8/vowpal_wabbit,martinbel/vowpal_wabbit,lmatthieu/myvw,digitalreasoning/vowpal_wabbit,martinpopel/vowpal_wabbit,byzhang/vowpal_wabbit,abimannans/vowpal_wabbit,chriszeng8/vowpal_wabbit,printedheart/vowpal_wabbit,ffyu/vowpal_wabbit,emjotde/vowpal_wabbit,followyourheart/vowpal_wabbit,martinpopel/vowpal_wabbit,danmelamed/vowpal_wabbit,ffyu/vowpal_wabbit,yonglehou/vowpal_wabbit,digitalreasoning/vowpal_wabbit,zhoususheng/vowpal_wabbit,chrinide/vowpal_wabbit,abimannans/vowpal_wabbit,eisber/mwt-ds,KaiWeiChang/vowpal_wabbit,chenmoshushi/vowpal_wabbit,ml-lab/vowpal_wabbit,emjotde/vowpal_wabbit,multiworldtesting/decision,chenmoshushi/vowpal_wabbit,VerveWireless/vowpal_wabbit,zzzbit/vowpal_wabbit,jmorra/vowpal_wabbit,lhoang29/vowpal_wabbit,hal3/vowpal_wabbit,robin-lai/vowpal_wabbit,emjotde/vowpal_wabbit,yonglehou/vowpal_wabbit,martinpopel/vowpal_wabbit,virneo/explore-cpp,stathwang/vowpal_wabbit,sandyice74/vowpal_wabbit,martinpopel/vowpal_wabbit,printedheart/vowpal_wabbit,tzukuoh/vowpal_wabbit,raosudha89/vowpal_wabbit,followyourheart/vowpal_wabbit,KaiWeiChang/vowpal_wabbit,followyourheart/vowpal_wabbit,pombredanne/vowpal_wabbit,hal3/vowpal_wabbit,elevatedcareers/vowpal_wabbit,chrinide/vowpal_wabbit,tzukuoh/vowpal_wabbit,ml-lab/vowpal_wabbit,swjo207/vowpal_wabbit,pombredanne/vowpal_wabbit,haipengl/vowpal_wabbit,obrianjunior/vowpal_wabbit,zzzbit/vowpal_wabbit,digitalreasoning/vowpal_wabbit,stathwang/vowpal_wabbit,lhoang29/vowpal_wabbit,zermelozf/vw_tuto,gregsharp/vowpal_wabbit,elkingtonmcb/vowpal_wabbit,lhoang29/vowpal_wabbit,michaelbrundage/vowpal_wabbit,haipengl/vowpal_wabbit,virneo/explore,obrianjunior/vowpal_wabbit,zermelozf/vw_tuto,jon-morra-zefr/vowpal_wabbit,martinpopel/vowpal_wabbit,KaiWeiChang/vowpal_wabbit,deaktator/vowpal_wabbit-jmorra,jon-morra-zefr/vowpal_wabbit,feynman0825/vowpal_wabbit,followyourheart/vowpal_wabbit,VerveWireless/vowpal_wabbit,martinbel/vowpal_wabbit,chenmoshushi/vowpal_wabbit,haipengl/vowpal_wabbit,stathwang/vowpal_wabbit,raosudha89/vowpal_wabbit,zermelozf/vw_tuto,chenmoshushi/vowpal_wabbit,emjotde/vowpal_wabbit,jon-morra-zefr/vowpal_wabbit,martinbel/vowpal_wabbit,tsourolampis/vowpal_wabbit,jmorra/vowpal_wabbit,obrianjunior/vowpal_wabbit,trufanov-nok/vowpal_wabbit,tsourolampis/vowpal_wabbit,feynman0825/vowpal_wabbit,byzhang/vowpal_wabbit,zhoususheng/vowpal_wabbit,abimannans/vowpal_wabbit,deaktator/vowpal_wabbit,lhoang29/vowpal_wabbit,feynman0825/vowpal_wabbit,elevatedcareers/vowpal_wabbit,emjotde/vowpal_wabbit,digitalreasoning/vowpal_wabbit,elevatedcareers/vowpal_wabbit,haipengl/vowpal_wabbit,chenmoshushi/vowpal_wabbit,trufanov-nok/vowpal_wabbit,byzhang/vowpal_wabbit,swjo207/vowpal_wabbit