[dasher: 25/38] Fix uniformity in RoutingPPM, make sure each route gets at least 1!
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 25/38] Fix uniformity in RoutingPPM, make sure each route gets at least 1!
- Date: Tue, 3 Jan 2012 15:34:45 +0000 (UTC)
commit 099afd0ed2b3feacfa9f7172b0b1707530b4b851
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Mon Dec 19 12:48:50 2011 +0000
Fix uniformity in RoutingPPM, make sure each route gets at least 1!
Otherwise some routes were disappearing after training.
.../LanguageModelling/RoutingPPMLanguageModel.cpp | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/Src/DasherCore/LanguageModelling/RoutingPPMLanguageModel.cpp b/Src/DasherCore/LanguageModelling/RoutingPPMLanguageModel.cpp
index 0737869..20ed83c 100644
--- a/Src/DasherCore/LanguageModelling/RoutingPPMLanguageModel.cpp
+++ b/Src/DasherCore/LanguageModelling/RoutingPPMLanguageModel.cpp
@@ -31,8 +31,8 @@ CRoutingPPMLanguageModel::CRoutingPPMLanguageModel(CSettingsUser *pCreator, cons
void CRoutingPPMLanguageModel::GetProbs(Context context, std::vector<unsigned int> &probs, int norm, int iUniform) const {
const CPPMContext *ppmcontext = (const CPPMContext *)(context);
- const int iNumSymbols(m_pBaseSyms->size()); //i.e., the #routes - so loop from i=1 to <iNumSymbols
- probs.resize(iNumSymbols);
+ const int iNumRoutes(m_pBaseSyms->size()); //i.e., the #routes - so loop from i=1 to <iNumSymbols
+ probs.resize(iNumRoutes);
unsigned int iToSpend = norm;
unsigned int iUniformLeft = iUniform;
@@ -40,9 +40,12 @@ void CRoutingPPMLanguageModel::GetProbs(Context context, std::vector<unsigned in
// TODO: Sort out zero symbol case
probs[0] = 0;
- for(int i = 1; i < iNumSymbols; i++) {
- probs[i] = iUniformLeft / (iNumSymbols - i);
- iUniformLeft -= probs[i];
+ //Make sure each ROUTE gets at least one
+ for(int i = 1; i < iNumRoutes; i++) {
+ if (iUniformLeft >= iNumRoutes-i)
+ iUniformLeft -= probs[i] = iUniformLeft / (iNumRoutes-i);
+ else
+ probs[i]=1; //leave iUniformLeft
iToSpend -= probs[i];
}
@@ -109,7 +112,7 @@ void CRoutingPPMLanguageModel::GetProbs(Context context, std::vector<unsigned in
//for each base, distribute any remaining probability mass
// uniformly to all the routes to that base.
for (int i=1; i<GetSize(); i++) {
- if (!baseProbs[i]) continue; //=already distributed
+ if (!baseProbs[i]) continue; //none for that base (routes already have >=1), or already distributed
//ok, so there's some probability mass assigned to the base symbol,
// which we haven't assigned to any route
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]