1 #ifndef LMERT_LINEOPTIMIZE_HPP 2 #define LMERT_LINEOPTIMIZE_HPP 31 template<
typename IntervalBoundary>
47 direction_ ( direction ),
50 envelopes_.resize ( ts.
sidMax );
52 #ifdef NO_MULTI_THREADING 54 for (
Sid sidx = 0; sidx < ts.
sidMax; sidx++ ) {
62 for (
Sid sidx = 0; sidx < ts.
sidMax; sidx++ ) {
70 prev.resize ( envelopes_.size() );
71 initials.resize ( envelopes_.size() );
72 for (
Sid sidx = 0; sidx < envelopes_.size(); sidx++ ) {
75 typename std::vector<MertLine<Arc> >::size_type i = 0;
77 int offset = ( env.
lines[i].t.size() < 2 ? 0 : 1 );
79 env.
lines[i].t.end() - offset );
85 for ( i = 1; i < env.
lines.size(); ++i ) {
86 offset = ( env.
lines[i].t.size() < 2 ? 0 : 1 );
87 h.assign ( env.
lines[i].t.begin() + offset, env.
lines[i].t.end() - offset );
91 boundaries.push_back ( bd );
100 std::vector<IntervalBoundary> currentIBs ( initials );
104 for (
typename std::vector<IntervalBoundary>::const_iterator it =
105 initials.begin(); it != initials.end(); ++it ) {
106 aggregateBleuStats = aggregateBleuStats + it->bleuStats_;
108 optimalGamma = -std::numeric_limits<double>::infinity();
109 if ( boundaries.size() == 0 ) {
110 LINFO(
"no boundaries - returning");
113 sort ( boundaries.begin(), boundaries.end(),
114 IntervalBoundarySortPredicate<IntervalBoundary> );
116 optimalGamma = boundaries.front().gamma_ - 1;
117 optimalBleu = bs.
ComputeBleu ( aggregateBleuStats );
119 typename std::vector<IntervalBoundary>::iterator itNext = ++( boundaries.begin() );
120 for (
typename std::vector<IntervalBoundary>::iterator it = boundaries.begin();
121 it != boundaries.end(); ++it ) {
122 aggregateBleuStats = aggregateBleuStats + it->bleuStats_;
125 if ( current > optimalBleu && current.
m_brev >= optimalBleu.m_brev ) {
126 optimalBleu = current;
127 unbounded = ( itNext == boundaries.end() );
128 optimalGamma = ( itNext == boundaries.end() ) ? it->gamma_ + 1.0 :
129 0.5 * ( it->gamma_ + itNext->gamma_ );
147 std::vector< MertEnvelope<Arc> > envelopes_;
148 std::vector<ucam::fsttools::BleuStats> prev;
149 std::vector<IntervalBoundary> initials;
150 std::vector<IntervalBoundary> boundaries;
bool IntervalBoundarySortPredicate(const IntervalBoundary &b1, const IntervalBoundary &b2)
MertEnvelope< Arc > finalEnvelope
ucam::fsttools::BleuStats bleuStats_
Trivial implementation of a threadpool based on boost::asio methods When initiated, creates a threadpool of n threads (n <= number of cpus). Jobs should be submitted with the templated operator(). When the object is deleted it will wait for all threads to finish.
void Surface(ucam::fsttools::BleuScorer &bs)
const std::string kNThreads
ucam::fsttools::SentenceIdx SentenceIdx
ucam::fsttools::Bleu OptimalBleu()
LineOptimize(ucam::util::RegistryPO const &rg, ucam::fsttools::TuneSet< Arc > const &ts, ucam::fsttools::BleuScorer &bs, PARAMS32 const &lambda, PARAMS32 const &direction)
IntervalBoundary(Sid sentence, const double gamma, ucam::fsttools::BleuStats const &bleuStats)
ucam::fsttools::PARAMS32 PARAMS32
std::vector< MertLine< Arc > > lines
std::ostream & operator<<(std::ostream &os, const IntervalBoundary &b)