2008-05-14 11:57:45 +04:00
|
|
|
/*
|
|
|
|
* FeatureStats.h
|
|
|
|
* met - Minimum Error Training
|
|
|
|
*
|
|
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FEATURE_STATS_H
|
|
|
|
#define FEATURE_STATS_H
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "Util.h"
|
|
|
|
|
|
|
|
#define FEATURE_STATS_MIN (numeric_limits<FeatureStatsType>::min())
|
|
|
|
#define ATOFST(str) ((FeatureStatsType) atof(str))
|
|
|
|
|
2008-06-05 21:03:54 +04:00
|
|
|
#define featbytes_ (entries_*sizeof(FeatureStatsType))
|
2008-06-05 11:23:34 +04:00
|
|
|
|
2008-05-14 11:57:45 +04:00
|
|
|
class FeatureStats
|
|
|
|
{
|
|
|
|
private:
|
2011-02-24 15:42:19 +03:00
|
|
|
featstats_t array_;
|
2011-09-07 20:37:33 +04:00
|
|
|
sparse_featstats_t map_;
|
2011-02-24 15:42:19 +03:00
|
|
|
size_t entries_;
|
|
|
|
size_t available_;
|
|
|
|
|
2008-05-14 11:57:45 +04:00
|
|
|
public:
|
2011-02-24 15:42:19 +03:00
|
|
|
FeatureStats();
|
|
|
|
FeatureStats(const size_t size);
|
|
|
|
FeatureStats(const FeatureStats &stats);
|
|
|
|
FeatureStats(std::string &theString);
|
|
|
|
FeatureStats& operator=(const FeatureStats &stats);
|
|
|
|
|
|
|
|
~FeatureStats();
|
|
|
|
|
|
|
|
bool isfull() {
|
|
|
|
return (entries_ < available_)?0:1;
|
|
|
|
}
|
|
|
|
void expand();
|
|
|
|
void add(FeatureStatsType v);
|
2011-09-07 20:37:33 +04:00
|
|
|
void addSparse(string name, FeatureStatsType v);
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
inline void clear() {
|
|
|
|
memset((void*) array_,0,featbytes_);
|
2011-09-07 20:37:33 +04:00
|
|
|
map_.clear();
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline FeatureStatsType get(size_t i) {
|
|
|
|
return array_[i];
|
|
|
|
}
|
|
|
|
inline FeatureStatsType get(size_t i)const {
|
|
|
|
return array_[i];
|
|
|
|
}
|
|
|
|
inline featstats_t getArray() const {
|
|
|
|
return array_;
|
|
|
|
}
|
2011-09-07 20:37:33 +04:00
|
|
|
inline sparse_featstats_t getSparse() const {
|
|
|
|
return map_;
|
|
|
|
}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
void set(std::string &theString);
|
|
|
|
|
|
|
|
inline size_t bytes() const {
|
|
|
|
return featbytes_;
|
|
|
|
}
|
|
|
|
inline size_t size() const {
|
|
|
|
return entries_;
|
|
|
|
}
|
|
|
|
inline size_t available() const {
|
|
|
|
return available_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void savetxt(const std::string &file);
|
|
|
|
void savetxt(ofstream& outFile);
|
|
|
|
void savebin(ofstream& outFile);
|
|
|
|
inline void savetxt() {
|
|
|
|
savetxt("/dev/stdout");
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadtxt(const std::string &file);
|
|
|
|
void loadtxt(ifstream& inFile);
|
|
|
|
void loadbin(ifstream& inFile);
|
|
|
|
|
|
|
|
inline void reset() {
|
|
|
|
entries_ = 0;
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2008-05-27 20:50:52 +04:00
|
|
|
/**write the whole object to a stream*/
|
|
|
|
friend ostream& operator<<(ostream& o, const FeatureStats& e);
|
|
|
|
};
|
2008-05-14 11:57:45 +04:00
|
|
|
|
2008-05-15 10:44:36 +04:00
|
|
|
#endif
|
|
|
|
|
2008-05-15 14:57:20 +04:00
|
|
|
|