diff options
author | Colin Cherry <colin.a.cherry@gmail.com> | 2012-05-30 20:39:53 +0400 |
---|---|---|
committer | Colin Cherry <colin.a.cherry@gmail.com> | 2012-05-30 20:39:53 +0400 |
commit | 3c44d04baf6f4cdb938ac4e4e318b0591d3f553a (patch) | |
tree | 7a14d19983b81e0a981c1bdeda4062a456fc83b5 /mert/FeatureStats.cpp | |
parent | d4a2414bf039db67b21689f3cc8ef8447fac5ff9 (diff) | |
parent | beb2256dbaf420ed525cc8354617ead0db315060 (diff) |
Merge branch 'master' into miramerge
Conflicts:
Jamroot
mert/FeatureStats.cpp
moses-cmd/src/IOWrapper.h
scripts/training/mert-moses.pl
scripts/training/train-model.perl.missing_bin_dir
Diffstat (limited to 'mert/FeatureStats.cpp')
-rw-r--r-- | mert/FeatureStats.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/mert/FeatureStats.cpp b/mert/FeatureStats.cpp index 6b86ac304..834b63b4c 100644 --- a/mert/FeatureStats.cpp +++ b/mert/FeatureStats.cpp @@ -11,6 +11,9 @@ #include <fstream> #include <cmath> #include <stdexcept> + +#include <boost/functional/hash.hpp> + #include "Util.h" using namespace std; @@ -109,6 +112,42 @@ FeatureStatsType inner_product(const SparseVector& lhs, const SparseVector& rhs) } } +std::vector<std::size_t> SparseVector::feats() const { + std::vector<std::size_t> toRet; + for(fvector_t::const_iterator iter = m_fvector.begin(); + iter!=m_fvector.end(); + iter++) { + toRet.push_back(iter->first); + } + return toRet; +} + +std::size_t SparseVector::encode(const std::string& name) { + name2id_t::const_iterator name2id_iter = m_name_to_id.find(name); + size_t id = 0; + if (name2id_iter == m_name_to_id.end()) { + id = m_id_to_name.size(); + m_id_to_name.push_back(name); + m_name_to_id[name] = id; + } else { + id = name2id_iter->second; + } + return id; +} + +std::string SparseVector::decode(std::size_t id) { + return m_id_to_name[id]; +} + +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); +} + FeatureStats::FeatureStats() : m_available_size(kAvailableSize), m_entries(0), m_array(new FeatureStatsType[m_available_size]) {} |