[dasher: 26/38] Different (better?) fix: AlphabetManager forces iUniformAdd>0. TODO rationalize!



commit 7716ec480022c5ae328a300420fd8c13596fad95
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Mon Dec 19 12:55:48 2011 +0000

    Different (better?) fix: AlphabetManager forces iUniformAdd>0. TODO rationalize!
    
    Does the language model implement uniformity (as sig suggests, and most LMs
     have code for, but 0 always passed in)? Or does AlphabetManager (=> so can
     remove duplication, and parameter from LanguageModel::GetProbs)? Decide!

 Src/DasherCore/AlphabetManager.cpp                 |    2 +-
 .../LanguageModelling/RoutingPPMLanguageModel.cpp  |   15 ++++++---------
 2 files changed, 7 insertions(+), 10 deletions(-)
---
diff --git a/Src/DasherCore/AlphabetManager.cpp b/Src/DasherCore/AlphabetManager.cpp
index 3504ff3..8f6acd5 100644
--- a/Src/DasherCore/AlphabetManager.cpp
+++ b/Src/DasherCore/AlphabetManager.cpp
@@ -418,7 +418,7 @@ void CAlphabetManager::GetProbs(vector<unsigned int> *pProbInfo, CLanguageModel:
   const unsigned long iNorm(m_pNCManager->GetAlphNodeNormalization());
   //the case for control mode on, generalizes to handle control mode off also,
   // as then iNorm - control_space == iNorm...
-  const unsigned int iUniformAdd = ((iNorm * GetLongParameter(LP_UNIFORM)) / 1000) / iSymbols;
+  const unsigned int iUniformAdd = max(1ul, ((iNorm * GetLongParameter(LP_UNIFORM)) / 1000) / iSymbols);
   const unsigned long iNonUniformNorm = iNorm - iSymbols * iUniformAdd;
   //  m_pLanguageModel->GetProbs(context, Probs, iNorm, ((iNorm * uniform) / 1000));
 
diff --git a/Src/DasherCore/LanguageModelling/RoutingPPMLanguageModel.cpp b/Src/DasherCore/LanguageModelling/RoutingPPMLanguageModel.cpp
index 20ed83c..0737869 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 iNumRoutes(m_pBaseSyms->size()); //i.e., the #routes - so loop from i=1 to <iNumSymbols
-  probs.resize(iNumRoutes);
+  const int iNumSymbols(m_pBaseSyms->size()); //i.e., the #routes - so loop from i=1 to <iNumSymbols
+  probs.resize(iNumSymbols);
   
   unsigned int iToSpend = norm;
   unsigned int iUniformLeft = iUniform;
@@ -40,12 +40,9 @@ void CRoutingPPMLanguageModel::GetProbs(Context context, std::vector<unsigned in
   // TODO: Sort out zero symbol case
   probs[0] = 0;
   
-  //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
+  for(int i = 1; i < iNumSymbols; i++) {
+    probs[i] = iUniformLeft / (iNumSymbols - i);
+    iUniformLeft -= probs[i];
     iToSpend -= probs[i];
   }
   
@@ -112,7 +109,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; //none for that base (routes already have >=1), or already distributed
+    if (!baseProbs[i]) continue; //=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]