2008-05-14 11:57:45 +04:00
|
|
|
/*
|
|
|
|
* FeatureArray.h
|
2012-02-20 03:29:53 +04:00
|
|
|
* mert - Minimum Error Rate Training
|
2008-05-14 11:57:45 +04:00
|
|
|
*
|
|
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-02-20 04:46:08 +04:00
|
|
|
#ifndef MERT_FEATURE_ARRAY_H_
|
|
|
|
#define MERT_FEATURE_ARRAY_H_
|
2008-05-14 11:57:45 +04:00
|
|
|
|
|
|
|
#include <vector>
|
2012-05-10 02:51:05 +04:00
|
|
|
#include <iosfwd>
|
2008-05-14 11:57:45 +04:00
|
|
|
#include "FeatureStats.h"
|
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
namespace MosesTuning
|
|
|
|
{
|
2012-12-06 20:39:22 +04:00
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
|
2011-11-17 19:58:56 +04:00
|
|
|
const char FEATURES_TXT_BEGIN[] = "FEATURES_TXT_BEGIN_0";
|
|
|
|
const char FEATURES_TXT_END[] = "FEATURES_TXT_END_0";
|
|
|
|
const char FEATURES_BIN_BEGIN[] = "FEATURES_BIN_BEGIN_0";
|
|
|
|
const char FEATURES_BIN_END[] = "FEATURES_BIN_END_0";
|
|
|
|
|
2008-05-14 11:57:45 +04:00
|
|
|
class FeatureArray
|
|
|
|
{
|
2011-11-12 13:17:31 +04:00
|
|
|
private:
|
|
|
|
// idx to identify the utterance. It can differ from
|
|
|
|
// the index inside the vector.
|
2012-12-06 20:39:22 +04:00
|
|
|
int m_index;
|
2012-03-10 12:12:34 +04:00
|
|
|
featarray_t m_array;
|
2012-05-10 02:51:05 +04:00
|
|
|
std::size_t m_num_features;
|
2012-03-10 12:12:34 +04:00
|
|
|
std::string m_features;
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2008-05-14 11:57:45 +04:00
|
|
|
public:
|
2011-02-24 15:42:19 +03:00
|
|
|
FeatureArray();
|
2011-11-12 13:17:31 +04:00
|
|
|
~FeatureArray();
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
void clear() {
|
|
|
|
m_array.clear();
|
|
|
|
}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
int getIndex() const {
|
|
|
|
return m_index;
|
|
|
|
}
|
|
|
|
void setIndex(const int value) {
|
|
|
|
m_index = value;
|
|
|
|
}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
FeatureStats& get(std::size_t i) {
|
|
|
|
return m_array.at(i);
|
|
|
|
}
|
|
|
|
const FeatureStats& get(std::size_t i) const {
|
|
|
|
return m_array.at(i);
|
|
|
|
}
|
2012-03-10 14:27:52 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
void add(FeatureStats& e) {
|
|
|
|
m_array.push_back(e);
|
|
|
|
}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2011-12-12 17:48:42 +04:00
|
|
|
//ADDED BY TS
|
2012-05-10 02:51:05 +04:00
|
|
|
void swap(std::size_t i, std::size_t j) {
|
2012-03-10 12:12:34 +04:00
|
|
|
std::swap(m_array[i], m_array[j]);
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
2012-03-10 12:12:34 +04:00
|
|
|
|
2012-05-10 02:51:05 +04:00
|
|
|
void resize(std::size_t new_size) {
|
2012-03-10 12:12:34 +04:00
|
|
|
m_array.resize(std::min(new_size, m_array.size()));
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
2011-12-12 17:48:42 +04:00
|
|
|
//END_ADDED
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
void merge(FeatureArray& e);
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
std::size_t size() const {
|
|
|
|
return m_array.size();
|
|
|
|
}
|
2012-03-10 14:27:52 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
std::size_t NumberOfFeatures() const {
|
|
|
|
return m_num_features;
|
|
|
|
}
|
|
|
|
void NumberOfFeatures(std::size_t v) {
|
|
|
|
m_num_features = v;
|
|
|
|
}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
std::string Features() const {
|
|
|
|
return m_features;
|
|
|
|
}
|
|
|
|
void Features(const std::string& f) {
|
|
|
|
m_features = f;
|
|
|
|
}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2012-03-10 14:04:43 +04:00
|
|
|
void savetxt(std::ostream* os);
|
|
|
|
void savebin(std::ostream* os);
|
|
|
|
void save(std::ostream* os, bool bin=false);
|
2011-02-24 15:42:19 +03:00
|
|
|
void save(const std::string &file, bool bin=false);
|
2012-03-10 14:04:43 +04:00
|
|
|
void save(bool bin=false);
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2012-05-25 00:11:35 +04:00
|
|
|
void loadtxt(std::istream* is, const SparseVector& sparseWeights, std::size_t n);
|
2012-05-10 02:51:05 +04:00
|
|
|
void loadbin(std::istream* is, std::size_t n);
|
2012-05-25 00:11:35 +04:00
|
|
|
void load(std::istream* is, const SparseVector& sparseWeights);
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
bool check_consistency() const;
|
2008-05-14 11:57:45 +04:00
|
|
|
};
|
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
}
|
|
|
|
|
2012-02-20 04:46:08 +04:00
|
|
|
#endif // MERT_FEATURE_ARRAY_H_
|