Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieu@hoang.co.uk>2013-05-30 22:20:54 +0400
committerHieu Hoang <hieu@hoang.co.uk>2013-05-30 22:20:54 +0400
commit47902053b53d1b1af545c25356f0271a70fc55c2 (patch)
tree885822551605190d5c48c2c2bf33acbced716e4e
parent117eb76b0a0eb9563028206a547f8bf3e6e43fb2 (diff)
function to merge feature scores. ie. not add them together.
-rw-r--r--moses/FeatureVector.cpp22
-rw-r--r--moses/FeatureVector.h2
-rw-r--r--moses/ScoreComponentCollection.h3
3 files changed, 27 insertions, 0 deletions
diff --git a/moses/FeatureVector.cpp b/moses/FeatureVector.cpp
index 96dd9a0ce..d56e00fe7 100644
--- a/moses/FeatureVector.cpp
+++ b/moses/FeatureVector.cpp
@@ -803,6 +803,28 @@ FValue FVector::inner_product(const FVector& rhs) const
return product;
}
+void FVector::merge(const FVector &other)
+{
+ // dense
+ for (size_t i = 0; i < m_coreFeatures.size(); ++i) {
+ FValue thisVal = m_coreFeatures[i];
+ FValue otherVal = other.m_coreFeatures[i];
+
+ if (otherVal) {
+ CHECK(thisVal == 0 || thisVal == otherVal);
+ thisVal = otherVal;
+ }
+ }
+
+ // sparse
+ FNVmap::const_iterator iter;
+ for (iter = other.m_features.begin(); iter != other.m_features.end(); ++iter) {
+ const FName &otherKey = iter->first;
+ const FValue otherVal = iter->second;
+ m_features[otherKey] = otherVal;
+ }
+}
+
const FVector operator+(const FVector& lhs, const FVector& rhs)
{
return FVector(lhs) += rhs;
diff --git a/moses/FeatureVector.h b/moses/FeatureVector.h
index f4261b520..65fd12081 100644
--- a/moses/FeatureVector.h
+++ b/moses/FeatureVector.h
@@ -257,6 +257,8 @@ public:
// divide each element by the number given in the rhs vector
FVector& divideEquals(const FVector& rhs);
+ void merge(const FVector &other);
+
#ifdef MPI_ENABLE
friend class boost::serialization::access;
#endif
diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h
index 70c2a05f1..260e8de57 100644
--- a/moses/ScoreComponentCollection.h
+++ b/moses/ScoreComponentCollection.h
@@ -376,6 +376,9 @@ public:
void UpdateLearningRates(float decay_core, float decay_sparse, ScoreComponentCollection &confidenceCounts, float core_r0, float sparse_r0) {
m_scores.updateLearningRates(decay_core, decay_sparse, confidenceCounts.m_scores, core_r0, sparse_r0);
}
+ void Merge(const ScoreComponentCollection &other) {
+ m_scores.merge(other.m_scores);
+ }
#ifdef MPI_ENABLE
public: