A new method FVector::inner_product.

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/branches/mira-mtm5@3456 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
smaj 2010-09-15 15:00:21 +00:00
parent 70c0ba90a7
commit 87037f9d5e
2 changed files with 19 additions and 0 deletions

View File

@ -25,6 +25,8 @@
#include <fstream>
#include <sstream>
#include <stdexcept>
#include "StaticData.h"
#include "FeatureVector.h"
@ -378,6 +380,22 @@ namespace Moses {
}
return product;
}
FValue FVector::inner_product(const std::vector<FValue>& rhs) const {
assert(size() == rhs.size());
const ScoreIndexManager &sim = StaticData::Instance().GetScoreIndexManager;
FValue product = 0;
if (get(DEFAULT_NAME) == 0) {
for (const_iterator i = cbegin(); i != cend(); i++)
FValue rv = rhs[ sim.GetFeatureIndex(i->first) ];
product += *i * rv;
} else {
for (size_t i = 0; i < rhs.size(); i++) {
product += rhs[i] * get(sim.GetFeatureName(i));
}
}
return product;
}
const FVector operator+(const FVector& lhs, const FVector& rhs) {

View File

@ -220,6 +220,7 @@ namespace Moses {
#endif
FValue inner_product(const std::vector<FValue>& rhs) const;
};
std::ostream& operator<<( std::ostream& out, const FVector& fv);