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:
authorBarry Haddow <barry.haddow@gmail.com>2014-07-21 14:04:43 +0400
committerBarry Haddow <barry.haddow@gmail.com>2014-07-21 14:04:43 +0400
commitefee2695c31e1086af783c1b092fc842fb7bb1a4 (patch)
treee8324ea35cc92f0737c93f6b8fa8e23898e4d78a /mert/FeatureStats.cpp
parentc83c5a3ee6f3ef7480e7a782d2023af9e99c1711 (diff)
Merge 08811deb17337356cd8dae9c59c0160590679a35 from joshua
Diffstat (limited to 'mert/FeatureStats.cpp')
-rw-r--r--mert/FeatureStats.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/mert/FeatureStats.cpp b/mert/FeatureStats.cpp
index 5a12be70a..a0c6a6ebc 100644
--- a/mert/FeatureStats.cpp
+++ b/mert/FeatureStats.cpp
@@ -14,6 +14,8 @@
#include <boost/functional/hash.hpp>
+#include "util/murmur_hash.hh"
+
#include "Util.h"
using namespace std;
@@ -59,6 +61,11 @@ void SparseVector::set(const string& name, FeatureStatsType value)
m_fvector[id] = value;
}
+void SparseVector::set(size_t id, FeatureStatsType value) {
+ assert(m_id_to_name.size() > id);
+ m_fvector[id] = value;
+}
+
void SparseVector::write(ostream& out, const string& sep) const
{
for (fvector_t::const_iterator i = m_fvector.begin(); i != m_fvector.end(); ++i) {
@@ -91,6 +98,16 @@ void SparseVector::load(const string& file)
}
}
+SparseVector& SparseVector::operator+=(const SparseVector& rhs)
+{
+
+ for (fvector_t::const_iterator i = rhs.m_fvector.begin();
+ i != rhs.m_fvector.end(); ++i) {
+ m_fvector[i->first] = get(i->first) + (i->second);
+ }
+ return *this;
+}
+
SparseVector& SparseVector::operator-=(const SparseVector& rhs)
{
@@ -162,12 +179,18 @@ bool operator==(SparseVector const& item1, SparseVector const& item2)
return item1.m_fvector==item2.m_fvector;
}
+
std::size_t hash_value(SparseVector const& item)
{
- boost::hash<SparseVector::fvector_t> hasher;
- return hasher(item.m_fvector);
+ size_t seed = 0;
+ for (SparseVector::fvector_t::const_iterator i = item.m_fvector.begin(); i != item.m_fvector.end(); ++i) {
+ seed = util::MurmurHashNative(&(i->first), sizeof(i->first), seed);
+ seed = util::MurmurHashNative(&(i->second), sizeof(i->second), seed);
+ }
+ return seed;
}
+
FeatureStats::FeatureStats()
: m_available_size(kAvailableSize), m_entries(0),
m_array(new FeatureStatsType[m_available_size]) {}
@@ -181,8 +204,7 @@ FeatureStats::FeatureStats(const size_t size)
FeatureStats::~FeatureStats()
{
- delete [] m_array;
- m_array = NULL;
+ delete [] m_array;
}
void FeatureStats::Copy(const FeatureStats &stats)