text
stringlengths
0
2.2M
m_currentUttInfo = uttInfo;
// Checks if we need to read more loglikelihoods.
m_needLikelihood = (m_epochEnd || m_uttPool.size() > 0) ? false : true;
if (m_needLikelihood == true)
{
m_uttReady.assign(m_numUttsPerMinibatch, false);
}
return true;
}
template <class ElemType>
bool UtteranceDerivativeBuffer<ElemType>::GetObjective(
const std::vector<std::vector<std::pair<wstring, size_t>>>& uttInfo,
MBLayoutPtr pMBLayout,
Matrix<ElemType>* objectivesIn)
{
assert(objectivesIn != NULL);
// Checks utterance information.
bool match = CompareUttInfo(uttInfo, m_currentUttInfo);
if (!match)
{
RuntimeError("Current objective does not correspond to the"
" minibatch utterance information, perhaps you did not"
" run GetObjective() right after GetDerivative()?");
}
// Sets the objectives...
objectivesIn->Resize(1, pMBLayout->GetNumCols());
objectivesIn->SetValue(
m_currentObj / static_cast<ElemType>(pMBLayout->GetNumCols()));
return true;
}
template <class ElemType>
bool UtteranceDerivativeBuffer<ElemType>::HasResourceForDerivative(
const wstring& uttID) const
{
return m_derivativeInterface->HasResourceForDerivative(uttID);
}
template <class ElemType>
bool UtteranceDerivativeBuffer<ElemType>::CompareUttInfo(
const std::vector<std::vector<std::pair<wstring, size_t>>>& uttInfo1,
const std::vector<std::vector<std::pair<wstring, size_t>>>& uttInfo2)
{
bool match = true;
if (uttInfo1.size() == uttInfo2.size())
{
for (size_t i = 0; i < uttInfo1.size(); ++i)
{
if (uttInfo1[i].size() != uttInfo2[i].size())
{
match = false;
break;
}
for (size_t j = 0; j < uttInfo1[i].size(); ++j)
{
if (uttInfo1[i][j].first != uttInfo2[i][j].first ||
uttInfo1[i][j].second != uttInfo2[i][j].second)
{
match = false;
break;
}
}
}
}
else
{
match = false;
}
return match;
}
template <class ElemType>
void UtteranceDerivativeBuffer<ElemType>::ResetEpoch()
{
m_needLikelihood = true;
m_currentObj = 0;
m_epochEnd = false;
m_uttPool.clear();
m_currentUttInfo.clear();
m_uttReady.assign(m_numUttsPerMinibatch, false);
}
template class UtteranceDerivativeBuffer<float>;
template class UtteranceDerivativeBuffer<double>;
} } }
// bdlat_typecategory.t.cpp -*-C++-*-
// ----------------------------------------------------------------------------
// NOTICE
//
// This component is not up to date with current BDE coding standards, and
// should not be used as an example for new development.
// ----------------------------------------------------------------------------