summaryrefslogtreecommitdiff
path: root/dtrain/score.h
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2011-09-23 22:02:45 +0200
committerPatrick Simianer <p@simianer.de>2011-09-23 22:02:45 +0200
commit0a47dda0e980d1fb6222a1f548649914427555b2 (patch)
treeed163959983dd503699c752964c5178208c61235 /dtrain/score.h
parentdc9fd7a3adc863510d79a718e919b6833a86729c (diff)
more renaming, random pair sampler uses boost rng
Diffstat (limited to 'dtrain/score.h')
-rw-r--r--dtrain/score.h53
1 files changed, 23 insertions, 30 deletions
diff --git a/dtrain/score.h b/dtrain/score.h
index e88387c5..0afb6237 100644
--- a/dtrain/score.h
+++ b/dtrain/score.h
@@ -1,29 +1,23 @@
#ifndef _DTRAIN_SCORE_H_
#define _DTRAIN_SCORE_H_
-
#include <iostream>
#include <vector>
#include <map>
#include <cassert>
#include <cmath>
-#include "wordid.h"
+#include "wordid.h" // cdec
using namespace std;
-
namespace dtrain
{
-/*
- * NgramCounts
- *
- */
struct NgramCounts
{
- NgramCounts( const size_t N ) : N_( N ) {
+ NgramCounts(const size_t N) : N_(N) {
reset();
}
size_t N_;
@@ -31,17 +25,17 @@ struct NgramCounts
map<size_t, size_t> sum;
void
- operator+=( const NgramCounts& rhs )
+ operator+=(const NgramCounts& rhs)
{
- assert( N_ == rhs.N_ );
- for ( size_t i = 0; i < N_; i++ ) {
+ assert(N_ == rhs.N_);
+ for (size_t i = 0; i < N_; i++) {
this->clipped[i] += rhs.clipped.find(i)->second;
this->sum[i] += rhs.sum.find(i)->second;
}
}
const NgramCounts
- operator+( const NgramCounts &other ) const
+ operator+(const NgramCounts &other) const
{
NgramCounts result = *this;
result += other;
@@ -49,10 +43,10 @@ struct NgramCounts
}
void
- add( size_t count, size_t ref_count, size_t i )
+ add(size_t count, size_t ref_count, size_t i)
{
- assert( i < N_ );
- if ( count > ref_count ) {
+ assert(i < N_);
+ if (count > ref_count) {
clipped[i] += ref_count;
sum[i] += count;
} else {
@@ -65,7 +59,7 @@ struct NgramCounts
reset()
{
size_t i;
- for ( i = 0; i < N_; i++ ) {
+ for (i = 0; i < N_; i++) {
clipped[i] = 0;
sum[i] = 0;
}
@@ -74,27 +68,26 @@ struct NgramCounts
void
print()
{
- for ( size_t i = 0; i < N_; i++ ) {
+ for (size_t i = 0; i < N_; i++) {
cout << i+1 << "grams (clipped):\t" << clipped[i] << endl;
cout << i+1 << "grams:\t\t\t" << sum[i] << endl;
}
}
};
-
typedef map<vector<WordID>, size_t> Ngrams;
-Ngrams make_ngrams( vector<WordID>& s, size_t N );
-NgramCounts make_ngram_counts( vector<WordID> hyp, vector<WordID> ref, size_t N );
-
-double brevity_penaly( const size_t hyp_len, const size_t ref_len );
-double bleu( NgramCounts& counts, const size_t hyp_len, const size_t ref_len, const size_t N,
- vector<float> weights = vector<float>() );
-double stupid_bleu( NgramCounts& counts, const size_t hyp_len, const size_t ref_len, size_t N,
- vector<float> weights = vector<float>() );
-double smooth_bleu( NgramCounts& counts, const size_t hyp_len, const size_t ref_len, const size_t N,
- vector<float> weights = vector<float>() );
-double approx_bleu( NgramCounts& counts, const size_t hyp_len, const size_t ref_len, const size_t N,
- vector<float> weights = vector<float>() );
+Ngrams make_ngrams(vector<WordID>& s, size_t N);
+NgramCounts make_ngram_counts(vector<WordID> hyp, vector<WordID> ref, size_t N);
+
+double brevity_penaly(const size_t hyp_len, const size_t ref_len);
+double bleu(NgramCounts& counts, const size_t hyp_len, const size_t ref_len, const size_t N,
+ vector<float> weights = vector<float>());
+double stupid_bleu(NgramCounts& counts, const size_t hyp_len, const size_t ref_len, size_t N,
+ vector<float> weights = vector<float>());
+double smooth_bleu(NgramCounts& counts, const size_t hyp_len, const size_t ref_len, const size_t N,
+ vector<float> weights = vector<float>());
+double approx_bleu(NgramCounts& counts, const size_t hyp_len, const size_t ref_len, const size_t N,
+ vector<float> weights = vector<float>());
} // namespace