mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
replace CHECK with UTIL_THROW_IF in mert
This commit is contained in:
parent
c8f19220e9
commit
d9be81596e
@ -9,7 +9,7 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "util/check.hh"
|
||||
#include "util/exception.hh"
|
||||
#include "Ngram.h"
|
||||
#include "Reference.h"
|
||||
#include "Util.h"
|
||||
@ -165,7 +165,7 @@ std::vector<std::string> BleuDocScorer::splitDoc(const std::string& text)
|
||||
|
||||
statscore_t BleuDocScorer::calculateScore(const vector<int>& comps) const
|
||||
{
|
||||
CHECK(comps.size() == kBleuNgramOrder * 2 + 1);
|
||||
UTIL_THROW_IF(comps.size() != kBleuNgramOrder * 2 + 1, util::Exception, "Error");
|
||||
|
||||
float logbleu = 0.0;
|
||||
for (int i = 0; i < kBleuNgramOrder; ++i) {
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "util/check.hh"
|
||||
#include "util/exception.hh"
|
||||
#include "Ngram.h"
|
||||
#include "Reference.h"
|
||||
#include "Util.h"
|
||||
@ -188,7 +188,7 @@ void BleuScorer::prepareStats(size_t sid, const string& text, ScoreStats& entry)
|
||||
|
||||
statscore_t BleuScorer::calculateScore(const vector<int>& comps) const
|
||||
{
|
||||
CHECK(comps.size() == kBleuNgramOrder * 2 + 1);
|
||||
UTIL_THROW_IF(comps.size() != kBleuNgramOrder * 2 + 1, util::Exception, "Error");
|
||||
|
||||
float logbleu = 0.0;
|
||||
for (int i = 0; i < kBleuNgramOrder; ++i) {
|
||||
@ -246,8 +246,7 @@ void BleuScorer::DumpCounts(ostream* os,
|
||||
float smoothedSentenceBleu
|
||||
(const std::vector<float>& stats, float smoothing, bool smoothBP)
|
||||
{
|
||||
|
||||
CHECK(stats.size() == kBleuNgramOrder * 2 + 1);
|
||||
UTIL_THROW_IF(stats.size() != kBleuNgramOrder * 2 + 1, util::Exception, "Error");
|
||||
|
||||
float logbleu = 0.0;
|
||||
for (int j = 0; j < kBleuNgramOrder; j++) {
|
||||
@ -268,8 +267,9 @@ float sentenceLevelBackgroundBleu(const std::vector<float>& sent, const std::vec
|
||||
{
|
||||
// Sum sent and background
|
||||
std::vector<float> stats;
|
||||
CHECK(sent.size()==bg.size());
|
||||
CHECK(sent.size()==kBleuNgramOrder*2+1);
|
||||
UTIL_THROW_IF(sent.size()!=bg.size(), util::Exception, "Error");
|
||||
UTIL_THROW_IF(sent.size() != kBleuNgramOrder * 2 + 1, util::Exception, "Error");
|
||||
|
||||
for(size_t i=0; i<sent.size(); i++)
|
||||
stats.push_back(sent[i]+bg[i]);
|
||||
|
||||
@ -291,7 +291,7 @@ float sentenceLevelBackgroundBleu(const std::vector<float>& sent, const std::vec
|
||||
|
||||
float unsmoothedBleu(const std::vector<float>& stats)
|
||||
{
|
||||
CHECK(stats.size() == kBleuNgramOrder * 2 + 1);
|
||||
UTIL_THROW_IF(stats.size() != kBleuNgramOrder * 2 + 1, util::Exception, "Error");
|
||||
|
||||
float logbleu = 0.0;
|
||||
for (int j = 0; j < kBleuNgramOrder; j++) {
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "Scorer.h"
|
||||
#include "ScorerFactory.h"
|
||||
#include "Util.h"
|
||||
#include "util/check.hh"
|
||||
#include "util/exception.hh"
|
||||
|
||||
#include "util/file_piece.hh"
|
||||
#include "util/tokenize_piece.hh"
|
||||
@ -261,12 +261,15 @@ void Data::AddFeatures(const string& str,
|
||||
void Data::createShards(size_t shard_count, float shard_size, const string& scorerconfig,
|
||||
vector<Data>& shards)
|
||||
{
|
||||
CHECK(shard_count);
|
||||
CHECK(shard_size >= 0);
|
||||
CHECK(shard_size <= 1);
|
||||
UTIL_THROW_IF(shard_count == 0, util::Exception, "Must have at least 1 shard");
|
||||
UTIL_THROW_IF(shard_size < 0 || shard_size > 1,
|
||||
util::Exception,
|
||||
"Shard size must be between 0 and 1, inclusive. Currently " << shard_size);
|
||||
|
||||
size_t data_size = m_score_data->size();
|
||||
CHECK(data_size == m_feature_data->size());
|
||||
UTIL_THROW_IF(data_size != m_feature_data->size(),
|
||||
util::Exception,
|
||||
"Error");
|
||||
|
||||
shard_size *= data_size;
|
||||
const float coeff = static_cast<float>(data_size) / shard_count;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "Optimizer.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "util/check.hh"
|
||||
#include "util/exception.hh"
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
@ -44,7 +44,7 @@ Optimizer::Optimizer(unsigned Pd, const vector<unsigned>& i2O, const vector<bool
|
||||
// Warning: the init vector is a full set of parameters, of dimension m_pdim!
|
||||
Point::m_pdim = Pd;
|
||||
|
||||
CHECK(start.size() == Pd);
|
||||
UTIL_THROW_IF(start.size() != Pd, util::Exception, "Error");
|
||||
Point::m_dim = i2O.size();
|
||||
Point::m_opt_indices = i2O;
|
||||
if (Point::m_pdim > Point::m_dim) {
|
||||
@ -84,7 +84,7 @@ map<float,diff_t >::iterator AddThreshold(map<float,diff_t >& thresholdmap, floa
|
||||
} else {
|
||||
// normal case
|
||||
pair<map<float,diff_t>::iterator, bool> ins = thresholdmap.insert(threshold(newt, diff_t(1, newdiff)));
|
||||
CHECK(ins.second); // we really inserted something
|
||||
UTIL_THROW_IF(!ins.second, util::Exception, "Error"); // we really inserted something
|
||||
it = ins.first;
|
||||
}
|
||||
return it;
|
||||
@ -168,7 +168,8 @@ statscore_t Optimizer::LineOptimize(const Point& origin, const Point& direction,
|
||||
// The rightmost bestindex is the one with the highest slope.
|
||||
|
||||
// They should be equal but there might be.
|
||||
CHECK(abs(leftmost->first-gradient.rbegin()->first) < 0.0001);
|
||||
UTIL_THROW_IF(abs(leftmost->first-gradient.rbegin()->first) >= 0.0001,
|
||||
util::Exception, "Error");
|
||||
// A small difference due to rounding error
|
||||
break;
|
||||
}
|
||||
@ -189,7 +190,9 @@ statscore_t Optimizer::LineOptimize(const Point& origin, const Point& direction,
|
||||
map<float,diff_t>::iterator tit = thresholdmap.find(leftmostx);
|
||||
if (tit == previnserted) {
|
||||
// The threshold is the same as before can happen if 2 candidates are the same for example.
|
||||
CHECK(previnserted->second.back().first == newd.first);
|
||||
UTIL_THROW_IF(previnserted->second.back().first != newd.first,
|
||||
util::Exception,
|
||||
"Error");
|
||||
previnserted->second.back()=newd; // just replace the 1 best for sentence S
|
||||
// previnsert doesn't change
|
||||
} else {
|
||||
@ -203,14 +206,18 @@ statscore_t Optimizer::LineOptimize(const Point& origin, const Point& direction,
|
||||
} else {
|
||||
// We append the diffs in previnsert to tit before destroying previnsert.
|
||||
tit->second.insert(tit->second.end(),previnserted->second.begin(),previnserted->second.end());
|
||||
CHECK(tit->second.back().first == newd.first);
|
||||
UTIL_THROW_IF(tit->second.back().first != newd.first,
|
||||
util::Exception,
|
||||
"Error");
|
||||
tit->second.back()=newd; // change diff for sentence S
|
||||
thresholdmap.erase(previnserted); // erase old previnsert
|
||||
previnserted = tit; // point previnsert to the new threshold
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(previnserted != thresholdmap.end());
|
||||
UTIL_THROW_IF(previnserted == thresholdmap.end(),
|
||||
util::Exception,
|
||||
"Error");
|
||||
} else { //normal insertion process
|
||||
previnserted = AddThreshold(thresholdmap, leftmostx, newd);
|
||||
}
|
||||
@ -246,7 +253,9 @@ statscore_t Optimizer::LineOptimize(const Point& origin, const Point& direction,
|
||||
float bestx = MIN_FLOAT;
|
||||
|
||||
// We skipped the first el of thresholdlist but GetIncStatScore return 1 more for first1best.
|
||||
CHECK(scores.size() == thresholdmap.size());
|
||||
UTIL_THROW_IF(scores.size() != thresholdmap.size(),
|
||||
util::Exception,
|
||||
"Error");
|
||||
for (unsigned int sc = 0; sc != scores.size(); sc++) {
|
||||
//cerr << "x=" << thrit->first << " => " << scores[sc] << endl;
|
||||
|
||||
@ -312,7 +321,7 @@ statscore_t Optimizer::LineOptimize(const Point& origin, const Point& direction,
|
||||
|
||||
void Optimizer::Get1bests(const Point& P, vector<unsigned>& bests) const
|
||||
{
|
||||
CHECK(m_feature_data);
|
||||
UTIL_THROW_IF(m_feature_data == NULL, util::Exception, "Error");
|
||||
bests.clear();
|
||||
bests.resize(size());
|
||||
|
||||
@ -365,7 +374,7 @@ statscore_t Optimizer::Run(Point& P) const
|
||||
|
||||
vector<statscore_t> Optimizer::GetIncStatScore(const vector<unsigned>& thefirst, const vector<vector <pair<unsigned,unsigned> > >& thediffs) const
|
||||
{
|
||||
CHECK(m_scorer);
|
||||
UTIL_THROW_IF(m_scorer == NULL, util::Exception, "Error");
|
||||
|
||||
vector<statscore_t> theres;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include "util/check.hh"
|
||||
#include "util/exception.hh"
|
||||
#include "FeatureStats.h"
|
||||
#include "Optimizer.h"
|
||||
|
||||
@ -40,8 +40,8 @@ Point::Point(const vector<parameter_t>& init,
|
||||
m_max[i] = max[i];
|
||||
}
|
||||
} else {
|
||||
CHECK(init.size() == m_pdim);
|
||||
CHECK(m_opt_indices.size() == Point::m_dim);
|
||||
UTIL_THROW_IF(init.size() != m_pdim, util::Exception, "Error");
|
||||
UTIL_THROW_IF(m_opt_indices.size() != Point::m_dim, util::Exception, "Error");
|
||||
for (unsigned int i = 0; i < Point::m_dim; i++) {
|
||||
operator[](i) = init[m_opt_indices[i]];
|
||||
m_min[i] = min[m_opt_indices[i]];
|
||||
@ -54,8 +54,9 @@ Point::~Point() {}
|
||||
|
||||
void Point::Randomize()
|
||||
{
|
||||
CHECK(m_min.size() == Point::m_dim);
|
||||
CHECK(m_max.size() == Point::m_dim);
|
||||
UTIL_THROW_IF(m_min.size() != Point::m_dim, util::Exception, "Error");
|
||||
UTIL_THROW_IF(m_max.size() != Point::m_dim, util::Exception, "Error");
|
||||
|
||||
for (unsigned int i = 0; i < size(); i++) {
|
||||
operator[](i) = m_min[i] +
|
||||
static_cast<float>(random()) / static_cast<float>(RAND_MAX) * (m_max[i] - m_min[i]);
|
||||
@ -81,7 +82,8 @@ double Point::operator*(const FeatureStats& F) const
|
||||
|
||||
const Point Point::operator+(const Point& p2) const
|
||||
{
|
||||
CHECK(p2.size() == size());
|
||||
UTIL_THROW_IF(p2.size() != size(), util::Exception, "Error");
|
||||
|
||||
Point Res(*this);
|
||||
for (unsigned i = 0; i < size(); i++) {
|
||||
Res[i] += p2[i];
|
||||
@ -93,7 +95,7 @@ const Point Point::operator+(const Point& p2) const
|
||||
|
||||
void Point::operator+=(const Point& p2)
|
||||
{
|
||||
CHECK(p2.size() == size());
|
||||
UTIL_THROW_IF(p2.size() != size(), util::Exception, "Error");
|
||||
for (unsigned i = 0; i < size(); i++) {
|
||||
operator[](i) += p2[i];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user