2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
2010-09-17 18:25:08 +04:00
|
|
|
#include <vector>
|
2008-06-11 14:52:57 +04:00
|
|
|
#include "ScoreComponentCollection.h"
|
|
|
|
#include "StaticData.h"
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2008-06-11 14:52:57 +04:00
|
|
|
ScoreComponentCollection::ScoreComponentCollection()
|
2010-09-15 21:27:37 +04:00
|
|
|
: m_scores(StaticData::Instance().GetTotalScoreComponents(), 0.0f)
|
2008-06-11 14:52:57 +04:00
|
|
|
, m_sim(&StaticData::Instance().GetScoreIndexManager())
|
|
|
|
{}
|
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
float ScoreComponentCollection::GetWeightedScore() const
|
|
|
|
{
|
|
|
|
float ret = InnerProduct(StaticData::Instance().GetAllWeights());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-10 17:12:00 +04:00
|
|
|
void ScoreComponentCollection::ZeroAllLM(const LMList& lmList)
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t ind = lmList.GetMinIndex(); ind <= lmList.GetMaxIndex(); ++ind)
|
|
|
|
{
|
2010-09-15 20:30:52 +04:00
|
|
|
m_scores[m_sim->GetFeatureName(ind)] = 0;
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-10 17:12:00 +04:00
|
|
|
void ScoreComponentCollection::PlusEqualsAllLM(const LMList& lmList, const ScoreComponentCollection& rhs)
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t ind = lmList.GetMinIndex(); ind <= lmList.GetMaxIndex(); ++ind)
|
|
|
|
{
|
2010-09-15 20:30:52 +04:00
|
|
|
m_scores[m_sim->GetFeatureName(ind)] += rhs.m_scores[m_sim->GetFeatureName(ind)];
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-09-16 13:54:13 +04:00
|
|
|
|
|
|
|
void ScoreComponentCollection::PlusEquals(const ScoreProducer* sp, const std::vector<float>& scores)
|
|
|
|
{
|
|
|
|
assert(scores.size() == sp->GetNumScoreComponents());
|
|
|
|
size_t i = m_sim->GetBeginIndex(sp->GetScoreBookkeepingID());
|
|
|
|
for (std::vector<float>::const_iterator vi = scores.begin();
|
|
|
|
vi != scores.end(); ++vi)
|
|
|
|
{
|
|
|
|
const std::string &name = m_sim->GetFeatureName(i++);
|
|
|
|
m_scores[name] += *vi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 19:20:55 +04:00
|
|
|
|
|
|
|
void ScoreComponentCollection::MultiplyEquals(float scalar)
|
|
|
|
{
|
|
|
|
m_scores *= scalar;
|
|
|
|
}
|
|
|
|
|
2010-09-16 11:06:42 +04:00
|
|
|
std::ostream& operator<<(std::ostream& os, const ScoreComponentCollection& rhs)
|
|
|
|
{
|
|
|
|
os << "<<" << rhs.m_scores[rhs.m_sim->GetFeatureName(0)];
|
|
|
|
for (size_t i=1; i<rhs.m_scores.size(); i++)
|
|
|
|
os << ", " << rhs.m_scores[rhs.m_sim->GetFeatureName(i)];
|
|
|
|
return os << ">>";
|
|
|
|
}
|
|
|
|
|
2010-09-17 18:25:08 +04:00
|
|
|
ScoreComponentCollection StaticData::GetAllWeightsScoreComponentCollection() const
|
|
|
|
{
|
|
|
|
Moses::ScoreComponentCollection ret;
|
|
|
|
|
|
|
|
const std::vector<const ScoreProducer*> &producers = m_scoreIndexManager.GetProducers();
|
|
|
|
std::vector<const ScoreProducer*>::const_iterator iter;
|
|
|
|
|
|
|
|
for (iter = producers.begin(); iter != producers.end(); ++iter)
|
|
|
|
{
|
|
|
|
const ScoreProducer *producer = *iter;
|
|
|
|
unsigned int bookId = producer->GetScoreBookkeepingID();
|
|
|
|
size_t startInd = m_scoreIndexManager.GetBeginIndex(bookId);
|
|
|
|
size_t endInd = m_scoreIndexManager.GetEndIndex(bookId);
|
|
|
|
|
|
|
|
std::cerr << producer->GetScoreProducerDescription();
|
|
|
|
|
|
|
|
std::vector<float> weights;
|
|
|
|
copy(m_allWeights.begin() + startInd, m_allWeights.begin() + endInd, inserter(weights,weights.end()));
|
|
|
|
|
|
|
|
ret.Assign(producer, weights);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-17 18:46:00 +04:00
|
|
|
void StaticData::SetAllWeightsScoreComponentCollection(const ScoreComponentCollection &weightsScoreComponentCollection)
|
|
|
|
{
|
|
|
|
const std::vector<const ScoreProducer*> &producers = m_scoreIndexManager.GetProducers();
|
|
|
|
std::vector<const ScoreProducer*>::const_iterator iter;
|
|
|
|
|
|
|
|
for (iter = producers.begin(); iter != producers.end(); ++iter)
|
|
|
|
{
|
|
|
|
const ScoreProducer *producer = *iter;
|
|
|
|
unsigned int bookId = producer->GetScoreBookkeepingID();
|
|
|
|
size_t startInd = m_scoreIndexManager.GetBeginIndex(bookId);
|
|
|
|
size_t endInd = m_scoreIndexManager.GetEndIndex(bookId);
|
|
|
|
|
|
|
|
std::cerr << producer->GetScoreProducerDescription();
|
|
|
|
|
|
|
|
std::vector<float> weights = weightsScoreComponentCollection.GetScoresForProducer(producer);
|
|
|
|
|
|
|
|
size_t allInd = startInd;
|
|
|
|
for (size_t ind = 0; ind < weights.size(); ++ind)
|
|
|
|
{
|
|
|
|
m_allWeights[allInd] = weights[ind];
|
|
|
|
allInd++;
|
|
|
|
}
|
|
|
|
assert(allInd == endInd);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|