diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-30 22:20:54 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-30 22:20:54 +0400 |
commit | 47902053b53d1b1af545c25356f0271a70fc55c2 (patch) | |
tree | 885822551605190d5c48c2c2bf33acbced716e4e /moses/FeatureVector.cpp | |
parent | 117eb76b0a0eb9563028206a547f8bf3e6e43fb2 (diff) |
function to merge feature scores. ie. not add them together.
Diffstat (limited to 'moses/FeatureVector.cpp')
-rw-r--r-- | moses/FeatureVector.cpp | 22 |
1 files changed, 22 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; |