blob: e31a0fd3ba56a871cbbfd2fb606f881b096dcc45 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/*
* Weights.cpp
*
* Created on: 24 Oct 2015
* Author: hieu
*/
#include <cassert>
#include <string>
#include <vector>
#include "FF/FeatureFunction.h"
#include "FF/FeatureFunctions.h"
#include "Weights.h"
#include "System.h"
#include "legacy/Util2.h"
using namespace std;
namespace Moses2
{
Weights::Weights()
{
// TODO Auto-generated constructor stub
}
Weights::~Weights()
{
// TODO Auto-generated destructor stub
}
void Weights::Init(const FeatureFunctions &ffs)
{
size_t totalNumScores = ffs.GetNumScores();
//cerr << "totalNumScores=" << totalNumScores << endl;
m_weights.resize(totalNumScores, 1);
}
std::vector<SCORE> Weights::GetWeights(const FeatureFunction &ff) const
{
std::vector<SCORE> ret(m_weights.begin() + ff.GetStartInd(), m_weights.begin() + ff.GetStartInd() + ff.GetNumScores());
return ret;
}
void Weights::SetWeights(const FeatureFunctions &ffs, const std::string &ffName, const std::vector<float> &weights)
{
const FeatureFunction *ff = ffs.FindFeatureFunction(ffName);
UTIL_THROW_IF2(ff == NULL, "Feature function not found:" << ffName);
size_t startInd = ff->GetStartInd();
size_t numScores = ff->GetNumScores();
UTIL_THROW_IF2(weights.size() != numScores, "Wrong number of weights. " << weights.size() << "!=" << numScores);
for (size_t i = 0; i < numScores; ++i) {
SCORE weight = weights[i];
m_weights[startInd + i] = weight;
}
}
}
|