mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-11-10 10:59:21 +03:00
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:
parent
70c0ba90a7
commit
87037f9d5e
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user