2008-05-14 11:57:45 +04:00
|
|
|
/*
|
|
|
|
* FeatureArray.h
|
|
|
|
* met - Minimum Error Training
|
|
|
|
*
|
|
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FEATURE_ARRAY_H
|
|
|
|
#define FEATURE_ARRAY_H
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include "Util.h"
|
|
|
|
#include "FeatureStats.h"
|
|
|
|
|
|
|
|
class FeatureArray
|
|
|
|
{
|
|
|
|
protected:
|
2011-02-24 15:42:19 +03:00
|
|
|
featarray_t array_;
|
|
|
|
size_t number_of_features;
|
|
|
|
std::string features;
|
2011-09-07 20:37:33 +04:00
|
|
|
bool _sparse_flag;
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2008-05-14 11:57:45 +04:00
|
|
|
private:
|
2011-11-12 03:58:23 +04:00
|
|
|
// idx to identify the utterance. It can differ from
|
|
|
|
// the index inside the vector.
|
|
|
|
std::string idx;
|
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 04:40:01 +04:00
|
|
|
~FeatureArray() {}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
inline void clear() {
|
|
|
|
array_.clear();
|
|
|
|
}
|
|
|
|
|
2011-09-07 20:37:33 +04:00
|
|
|
inline bool hasSparseFeatures() const {
|
|
|
|
return _sparse_flag;
|
|
|
|
}
|
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
inline std::string getIndex() const {
|
2011-02-24 15:42:19 +03:00
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
inline void setIndex(const std::string & value) {
|
|
|
|
idx=value;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline FeatureStats& get(size_t i) {
|
|
|
|
return array_.at(i);
|
|
|
|
}
|
|
|
|
inline const FeatureStats& get(size_t i)const {
|
|
|
|
return array_.at(i);
|
|
|
|
}
|
|
|
|
void add(FeatureStats e) {
|
|
|
|
array_.push_back(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void merge(FeatureArray& e);
|
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
inline size_t size() const {
|
2011-02-24 15:42:19 +03:00
|
|
|
return array_.size();
|
|
|
|
}
|
|
|
|
inline size_t NumberOfFeatures() const {
|
|
|
|
return number_of_features;
|
|
|
|
}
|
|
|
|
inline void NumberOfFeatures(size_t v) {
|
|
|
|
number_of_features = v;
|
|
|
|
}
|
|
|
|
inline std::string Features() const {
|
|
|
|
return features;
|
|
|
|
}
|
|
|
|
inline void Features(const std::string f) {
|
|
|
|
features = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void savetxt(ofstream& outFile);
|
|
|
|
void savebin(ofstream& outFile);
|
|
|
|
void save(ofstream& outFile, bool bin=false);
|
|
|
|
void save(const std::string &file, bool bin=false);
|
|
|
|
inline void save(bool bin=false) {
|
|
|
|
save("/dev/stdout",bin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadtxt(ifstream& inFile, size_t n);
|
|
|
|
void loadbin(ifstream& inFile, size_t n);
|
|
|
|
void load(ifstream& inFile);
|
|
|
|
void load(const std::string &file);
|
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
bool check_consistency() const;
|
2008-05-14 11:57:45 +04:00
|
|
|
};
|
|
|
|
|
2011-11-12 02:59:50 +04:00
|
|
|
#endif // FEATURE_ARRAY_H
|