2008-05-14 12:14:13 +04:00
|
|
|
/*
|
|
|
|
* ScoreStats.h
|
2012-02-20 03:29:53 +04:00
|
|
|
* mert - Minimum Error Rate Training
|
2008-05-14 12:14:13 +04:00
|
|
|
*
|
|
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-02-20 04:46:08 +04:00
|
|
|
#ifndef MERT_SCORE_STATS_H_
|
|
|
|
#define MERT_SCORE_STATS_H_
|
2008-05-14 12:14:13 +04:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
2011-11-14 10:15:30 +04:00
|
|
|
#include <fstream>
|
2008-10-17 01:14:38 +04:00
|
|
|
#include <cstdlib>
|
2011-11-14 10:15:30 +04:00
|
|
|
#include <cstring>
|
2008-05-14 12:14:13 +04:00
|
|
|
|
2011-11-14 10:15:30 +04:00
|
|
|
#include "Types.h"
|
|
|
|
|
|
|
|
using namespace std;
|
2008-05-14 12:14:13 +04:00
|
|
|
|
|
|
|
class ScoreStats
|
|
|
|
{
|
|
|
|
private:
|
2012-03-10 12:12:34 +04:00
|
|
|
size_t m_available_size;
|
|
|
|
size_t m_entries;
|
2011-11-12 17:04:22 +04:00
|
|
|
|
|
|
|
// TODO: Use smart pointer for exceptional-safety.
|
2012-03-10 12:12:34 +04:00
|
|
|
scorestats_t m_array;
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2008-05-14 12:14:13 +04:00
|
|
|
public:
|
2011-02-24 15:42:19 +03:00
|
|
|
ScoreStats();
|
2011-11-12 04:51:27 +04:00
|
|
|
explicit ScoreStats(const size_t size);
|
2012-02-26 08:44:47 +04:00
|
|
|
|
2011-11-12 04:51:27 +04:00
|
|
|
~ScoreStats();
|
|
|
|
|
|
|
|
// We intentionally allow copying.
|
2011-02-24 15:42:19 +03:00
|
|
|
ScoreStats(const ScoreStats &stats);
|
|
|
|
ScoreStats& operator=(const ScoreStats &stats);
|
|
|
|
|
2011-11-12 13:12:07 +04:00
|
|
|
void Copy(const ScoreStats &stats);
|
|
|
|
|
2012-03-10 14:27:52 +04:00
|
|
|
bool isfull() const { return (m_entries < m_available_size) ? 0 : 1; }
|
2011-11-12 06:26:13 +04:00
|
|
|
|
2011-02-24 15:42:19 +03:00
|
|
|
void expand();
|
|
|
|
void add(ScoreStatsType v);
|
|
|
|
|
2011-11-12 17:04:22 +04:00
|
|
|
void clear() {
|
2012-03-10 12:12:34 +04:00
|
|
|
memset((void*)m_array, 0, GetArraySizeWithBytes());
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
|
2011-11-12 17:04:22 +04:00
|
|
|
void reset() {
|
2012-03-10 12:12:34 +04:00
|
|
|
m_entries = 0;
|
2011-11-12 17:04:22 +04:00
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2012-03-10 14:27:52 +04:00
|
|
|
ScoreStatsType get(size_t i) { return m_array[i]; }
|
|
|
|
ScoreStatsType get(size_t i) const { return m_array[i]; }
|
|
|
|
scorestats_t getArray() const { return m_array; }
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2012-02-26 08:44:47 +04:00
|
|
|
void set(const std::string& str);
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2012-02-25 20:41:17 +04:00
|
|
|
// Much more efficient than the above.
|
|
|
|
void set(const std::vector<ScoreStatsType>& stats) {
|
|
|
|
reset();
|
|
|
|
for (size_t i = 0; i < stats.size(); ++i) {
|
|
|
|
add(stats[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 14:27:52 +04:00
|
|
|
size_t bytes() const { return GetArraySizeWithBytes(); }
|
2011-11-12 12:30:33 +04:00
|
|
|
|
|
|
|
size_t GetArraySizeWithBytes() const {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_entries * sizeof(ScoreStatsType);
|
2011-11-12 12:30:33 +04:00
|
|
|
}
|
|
|
|
|
2012-03-10 14:27:52 +04:00
|
|
|
size_t size() const { return m_entries; }
|
2012-03-10 12:12:34 +04:00
|
|
|
|
2012-03-10 14:27:52 +04:00
|
|
|
size_t available() const { return m_available_size; }
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
void savetxt(const std::string &file);
|
2012-03-10 14:04:43 +04:00
|
|
|
void savetxt(ostream* os);
|
|
|
|
void savebin(ostream* os);
|
|
|
|
void savetxt();
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
void loadtxt(const std::string &file);
|
2012-03-10 14:04:43 +04:00
|
|
|
void loadtxt(istream* is);
|
|
|
|
void loadbin(istream* is);
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2011-11-12 03:58:23 +04:00
|
|
|
/**
|
|
|
|
* Write the whole object to a stream.
|
|
|
|
*/
|
2011-02-24 15:42:19 +03:00
|
|
|
friend ostream& operator<<(ostream& o, const ScoreStats& e);
|
2008-05-14 12:14:13 +04:00
|
|
|
};
|
|
|
|
|
2011-12-12 17:48:42 +04:00
|
|
|
//ADDED_BY_TS
|
2012-02-20 04:46:08 +04:00
|
|
|
bool operator==(const ScoreStats& s1, const ScoreStats& s2);
|
2011-12-12 17:48:42 +04:00
|
|
|
//END_ADDED
|
|
|
|
|
2012-02-20 04:46:08 +04:00
|
|
|
#endif // MERT_SCORE_STATS_H_
|