function to merge feature scores. ie. not add them together.

This commit is contained in:
Hieu Hoang 2013-05-30 19:20:54 +01:00
parent 117eb76b0a
commit 47902053b5
3 changed files with 27 additions and 0 deletions

View File

@ -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;

View File

@ -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

View File

@ -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: