1 #ifndef LMERT_RANDOMLINESEARCH_HPP 2 #define LMERT_RANDOMLINESEARCH_HPP 4 #include <boost/math/constants/constants.hpp> 5 #include <boost/random/mersenne_twister.hpp> 6 #include <boost/random/uniform_on_sphere.hpp> 7 #include <boost/random/variate_generator.hpp> 22 lambda_ ( lambda ), fdim_ ( lambda.size() ),
27 rand_gen.seed ( seed_ );
28 if ( numRandDirs_ <= 0 )
29 numRandDirs_ = 2 * fdim_;
36 double optGamma = 0.0;
39 for (
int i = 0; i < directions_.size(); i++ ) {
41 bool smallGamma = ( fabs ( lopt.
OptimalGamma() ) < gammaMin_ );
44 if ( !smallBleuGain && !smallGamma ) {
50 ( smallBleuGain ?
" - too small; " :
"; " )
51 <<
"Gamma: " << lopt.
OptimalGamma() << ( smallGamma ?
" - too small" :
"" ));
53 FORCELINFO(
"Full random iteration completed. Opt Bleu: " << optBleu_ <<
54 "; Opt Gamma: " << optGamma << ( fabs(optGamma) < gammaMin_ ?
" - too small" :
"" ) );
56 FORCELINFO(
"Bleu gain less than threshold. Exiting.");
60 UpdateLambda ( directions_[optDirection], optGamma );
71 void GenerateDirections() {
73 for (
int i = 0; i < fdim_; i++ ) {
76 directions_.push_back ( dir );
78 boost::uniform_on_sphere<float> unif_sphere ( fdim_ );
79 FORCELINFO(
"Generating " << numRandDirs_ <<
" random directions");
80 for (
int i = 0; i < numRandDirs_; i++ ) {
81 boost::random::variate_generator<boost::random::mt19937&,
82 boost::random::uniform_on_sphere<float> >
83 sg ( rand_gen, unif_sphere );
84 directions_.push_back ( sg() );
88 void UpdateLambda (
PARAMS32 direction,
double gamma ) {
91 float rv = fabs(lambda_[0] + gamma * direction[0]);
94 for (
int i = 0; i < fdim_; i++ ) {
95 lambda_[i] = (lambda_[i] + gamma * direction[i])/rv;
99 boost::random::mt19937 rand_gen;
100 vector< ucam::fsttools::PARAMS32 > directions_;
T get(const std::string &key) const
Returns parsed value associated to key.
void WriteParamFile(const std::string &filename, std::vector< float > params_)
Write parameter vector to a file, with comma separators.
std::string const kLmertRandomSeed
RandomLineSearch(ucam::util::RegistryPO const &rg, ucam::fsttools::TuneSet< Arc > &ts, ucam::fsttools::BleuScorer &bs, ucam::fsttools::PARAMS32 const &lambda)
std::string const kLmertMinBleuGain
std::string const kLmertNumRandomDirections
ucam::fsttools::Bleu OptimalBleu()
std::string const kLmertMinGamma
ucam::fsttools::PARAMS32 PARAMS32
std::string const kLmertWriteParams
std::string printout(Container< T > const &container)