2015-10-24 16:36:30 +03:00
|
|
|
/*
|
|
|
|
* Weights.cpp
|
|
|
|
*
|
|
|
|
* Created on: 24 Oct 2015
|
|
|
|
* Author: hieu
|
|
|
|
*/
|
2015-10-27 20:35:42 +03:00
|
|
|
#include <cassert>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-11-03 16:24:39 +03:00
|
|
|
#include "FF/FeatureFunction.h"
|
|
|
|
#include "FF/FeatureFunctions.h"
|
2015-10-24 16:36:30 +03:00
|
|
|
#include "Weights.h"
|
2016-06-11 03:51:26 +03:00
|
|
|
#include "System.h"
|
2015-11-11 19:23:49 +03:00
|
|
|
#include "legacy/Util2.h"
|
2015-10-27 20:35:42 +03:00
|
|
|
|
|
|
|
using namespace std;
|
2015-10-24 16:36:30 +03:00
|
|
|
|
2015-12-10 23:49:30 +03:00
|
|
|
namespace Moses2
|
|
|
|
{
|
|
|
|
|
2015-10-29 21:15:12 +03:00
|
|
|
Weights::Weights()
|
|
|
|
{
|
2016-03-31 23:00:16 +03:00
|
|
|
// TODO Auto-generated constructor stub
|
2015-10-24 16:36:30 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-31 23:00:16 +03:00
|
|
|
Weights::~Weights()
|
|
|
|
{
|
|
|
|
// TODO Auto-generated destructor stub
|
2015-10-24 16:36:30 +03:00
|
|
|
}
|
|
|
|
|
2015-10-29 21:15:12 +03:00
|
|
|
void Weights::Init(const FeatureFunctions &ffs)
|
|
|
|
{
|
2016-03-31 23:00:16 +03:00
|
|
|
size_t totalNumScores = ffs.GetNumScores();
|
|
|
|
//cerr << "totalNumScores=" << totalNumScores << endl;
|
|
|
|
m_weights.resize(totalNumScores, 1);
|
2015-10-29 21:15:12 +03:00
|
|
|
}
|
|
|
|
|
2016-08-19 00:23:21 +03:00
|
|
|
std::vector<SCORE> Weights::GetWeights(const FeatureFunction &ff) const
|
2015-10-27 20:35:42 +03:00
|
|
|
{
|
2016-08-19 00:23:21 +03:00
|
|
|
std::vector<SCORE> ret(m_weights.begin() + ff.GetStartInd(), m_weights.begin() + ff.GetStartInd() + ff.GetNumScores());
|
|
|
|
return ret;
|
|
|
|
}
|
2015-10-27 20:35:42 +03:00
|
|
|
|
2016-08-19 00:23:21 +03:00
|
|
|
void Weights::SetWeights(const FeatureFunctions &ffs, const std::string &ffName, const std::vector<float> &weights)
|
|
|
|
{
|
2016-03-31 23:00:16 +03:00
|
|
|
const FeatureFunction *ff = ffs.FindFeatureFunction(ffName);
|
2016-08-19 00:23:21 +03:00
|
|
|
UTIL_THROW_IF2(ff == NULL, "Feature function not found:" << ffName);
|
|
|
|
|
2016-03-31 23:00:16 +03:00
|
|
|
size_t startInd = ff->GetStartInd();
|
|
|
|
size_t numScores = ff->GetNumScores();
|
2016-08-19 00:23:21 +03:00
|
|
|
UTIL_THROW_IF2(weights.size() != numScores, "Wrong number of weights. " << weights.size() << "!=" << numScores);
|
2015-10-27 20:35:42 +03:00
|
|
|
|
2016-03-31 23:00:16 +03:00
|
|
|
for (size_t i = 0; i < numScores; ++i) {
|
2017-02-01 03:27:14 +03:00
|
|
|
SCORE weight = weights[i];
|
|
|
|
m_weights[startInd + i] = weight;
|
2016-03-31 23:00:16 +03:00
|
|
|
}
|
2015-10-27 20:35:42 +03:00
|
|
|
}
|
2015-12-10 23:49:30 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|