コード例 #1
0
void LogLinearModel::ComputeNegativeFeatureExpectation (LogProbability& _rLogProb,
														Features_vec_t& _rvecFeatures, 
														double _dReward,
														double_Vec_t& _rvecExpectedFeatures)
{
	size_t iProbs = _rLogProb.Size ();
	if (0 == iProbs)
		return;

	Probability oProb (_rLogProb);
	for (size_t i = 0; i < iProbs; ++ i)
	{
		Features* pFeatures = _rvecFeatures [i];
		double dProb = oProb [i] * _dReward;

		for (int f = 0; f < pFeatures->Size (); ++ f)
		{
			size_t iIndex = pFeatures->Index (f);
			if (iIndex >= _rvecExpectedFeatures.Size ())
				cerr << "[ERROR] out-of-bounds " << iIndex
					 << " >= " << _rvecExpectedFeatures.Size () 
					 << endl;
			_rvecExpectedFeatures [pFeatures->Index (f)] -= dProb * pFeatures->Feature (f);
		}
	}
}
コード例 #2
0
double LogLinearModel::ComputeLogProb (Features& _rFeatures)
{
	double dResult = 0;

	for (int i = 0; i < _rFeatures.Size (); ++ i)
	{
		int iIndex = _rFeatures.Index (i);
		if (iIndex >= i_Features)
			continue;
		dResult += _rFeatures.Feature (i) * vec_Weights [iIndex];
	}
	
	return dResult;
}