diff options
author | Patrick Simianer <p@simianer.de> | 2011-07-31 19:24:02 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2011-09-23 19:13:57 +0200 |
commit | b7568a8dad2720d5ea0418171e9b85229adbbcc5 (patch) | |
tree | 06cc0f72e35e062fe0841f055f2d7f5e5626d407 /dtrain/dcommon.cc | |
parent | b732e625ffcf59da8440db577183110488f5c4b7 (diff) |
bugfixing, begin refactoring
Diffstat (limited to 'dtrain/dcommon.cc')
-rw-r--r-- | dtrain/dcommon.cc | 79 |
1 files changed, 49 insertions, 30 deletions
diff --git a/dtrain/dcommon.cc b/dtrain/dcommon.cc index a6bdc92c..6657bed6 100644 --- a/dtrain/dcommon.cc +++ b/dtrain/dcommon.cc @@ -2,7 +2,11 @@ -/* + +/****************************************************************************** + * NGRAMS + * + * * make_ngrams * */ @@ -23,9 +27,6 @@ make_ngrams( vector<WordID>& s, size_t N ) } - - - /* * ngram_matches * @@ -50,7 +51,12 @@ make_ngram_counts( vector<WordID> hyp, vector<WordID> ref, size_t N ) } -/* + + +/****************************************************************************** + * SCORES + * + * * brevity_penaly * */ @@ -156,7 +162,12 @@ approx_bleu( NgramCounts& counts, const size_t hyp_len, const size_t ref_len, } -/* + + +/****************************************************************************** + * UTILS + * + * * register_and_convert * */ @@ -170,11 +181,39 @@ register_and_convert(const vector<string>& strs, vector<WordID>& ids) } +/* + * approx_equal + * + */ +double +approx_equal( double x, double y ) +{ + const double EPSILON = 1E-5; + if ( x == 0 ) return fabs( y ) <= EPSILON; + if ( y == 0 ) return fabs( x ) <= EPSILON; + return fabs( x - y ) / max( fabs(x), fabs(y) ) <= EPSILON; +} /* + * print_FD + * + */ +void +print_FD() +{ + for ( size_t i = 0; i < FD::NumFeats(); i++ ) cout << FD::Convert(i)<< endl; +} + + + + +/****************************************************************************** + * TESTS * * + * test_ngrams + * */ void test_ngrams() @@ -207,21 +246,7 @@ test_ngrams() /* - * - * - */ -double -approx_equal( double x, double y ) -{ - const double EPSILON = 1E-5; - if ( x == 0 ) return fabs( y ) <= EPSILON; - if ( y == 0 ) return fabs( x ) <= EPSILON; - return fabs( x - y ) / max( fabs(x), fabs(y) ) <= EPSILON; -} - - -/* - * + * test_metrics * */ void @@ -263,8 +288,9 @@ test_metrics() cout << endl; } + /* - * + * test_SetWeights * */ void @@ -287,7 +313,7 @@ test_SetWeights() /* - * + * run_tests * */ void @@ -302,10 +328,3 @@ run_tests() exit(0); } - -void -print_FD() -{ - for ( size_t i = 0; i < FD::NumFeats(); i++ ) cout << FD::Convert(i)<< endl; -} - |