dasher
Class CPPMLanguageModel

java.lang.Object
  extended by dasher.CDasherComponent
      extended by dasher.CLanguageModel
          extended by dasher.CPPMLanguageModel

public class CPPMLanguageModel
extends CLanguageModel

Subclass of LanguageModel which implements Prediction by Partial Match. For information on the algorithm and its implementation, see (http://www.compression-links.info/PPM).

For the general contract obeyed by LanguageModel methods, see the documentation of CLanguageModel.


Nested Class Summary
(package private)  class CPPMLanguageModel.CAddSymReturnValue
          Small struct for use by CPPMLanguageModel's AddSymbol method.
(package private)  class CPPMLanguageModel.CPPMContext
          Class representing a context which contains information relevant to the PPM model.
(package private)  class CPPMLanguageModel.CPPMnode
          Node in PPM's prediction trie.
 
Field Summary
 boolean bUpdateExclusion
           
private  long lpAlpha
           
private  long lpBeta
           
 double m_dBackOffConstat
           
 int m_iMaxOrder
           
 CPPMLanguageModel.CPPMnode m_Root
           
 CPPMLanguageModel.CPPMContext m_RootContext
           
 int NodesAllocated
           
 
Fields inherited from class dasher.CLanguageModel
m_Alphabet, nullContext
 
Fields inherited from class dasher.CDasherComponent
m_EventHandler, m_SettingsStore
 
Constructor Summary
CPPMLanguageModel(CEventHandler EventHandler, CSettingsStore SettingsStore, CSymbolAlphabet SymbolAlphabet)
           
 
Method Summary
private  void AddSymbol(CPPMLanguageModel.CPPMContext context, int sym)
           
private  CPPMLanguageModel.CAddSymReturnValue AddSymbolToNode(CPPMLanguageModel.CPPMnode Node, int sym, int updatein)
           
 CContextBase CloneContext(CContextBase Input)
          Clones a given context; changes to one clone must not effect the state of the other.
 CContextBase CreateEmptyContext()
          Creates an empty context
 void dumpString(java.lang.String str, int pos, int len)
          Diagnostic method; prints a given String starting at pos and with length len.
 void dumpSymbol(int sym)
          Diagnostic method; prints a given symbol.
 void EnterSymbol(CContextBase c, int Symbol)
          Modifies the supplied context, appending a given symbol.
 int GetMemory()
          Get some measure of the memory usage for diagnostic purposes.
 long[] GetProbs(CContextBase context, long norm)
          Given a context and a normalisation value to which all probabilities must add up, this should produce an array in which each term corresponds to the relative probability of that symbol coming next.
 void HandleEvent(CEvent Event)
          Ignores all events
 void LearnSymbol(CContextBase c, int Symbol)
          Modifies the supplied context, appending a given symbol.
 void ReleaseContext(CContextBase release)
          Releases a given context; if the LanguageModel is keeping track of them internally or doing allocation work, it should release their storage.
 
Methods inherited from class dasher.CLanguageModel
GetSize, isRemote, SymbolAlphabet
 
Methods inherited from class dasher.CDasherComponent
GetBoolParameter, GetLongParameter, GetParameterName, GetParameterType, GetStringParameter, InsertEvent, SetBoolParameter, SetLongParameter, SetStringParameter, UnregisterComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_RootContext

public CPPMLanguageModel.CPPMContext m_RootContext

m_Root

public CPPMLanguageModel.CPPMnode m_Root

m_iMaxOrder

public int m_iMaxOrder

m_dBackOffConstat

public double m_dBackOffConstat

NodesAllocated

public int NodesAllocated

bUpdateExclusion

public boolean bUpdateExclusion

lpAlpha

private long lpAlpha

lpBeta

private long lpBeta
Constructor Detail

CPPMLanguageModel

public CPPMLanguageModel(CEventHandler EventHandler,
                         CSettingsStore SettingsStore,
                         CSymbolAlphabet SymbolAlphabet)
Method Detail

HandleEvent

public void HandleEvent(CEvent Event)
Description copied from class: CLanguageModel
Ignores all events

Overrides:
HandleEvent in class CLanguageModel
Parameters:
Event - Event received.

GetMemory

public int GetMemory()
Description copied from class: CLanguageModel
Get some measure of the memory usage for diagnostic purposes. No need to implement this if you're not comparing language models. The exact meaning of the result will depend on the implementation (for example, could be the number of nodes in a trie, or the physical memory usage).

Specified by:
GetMemory in class CLanguageModel
Returns:
Memory usage in bytes, or 0 if unknown or we don't care

GetProbs

public long[] GetProbs(CContextBase context,
                       long norm)
Description copied from class: CLanguageModel
Given a context and a normalisation value to which all probabilities must add up, this should produce an array in which each term corresponds to the relative probability of that symbol coming next.

The indices assigned to symbols should match those in the SymbolAlphabet we're working with.

The size of the array returned should be equal to the number of symbols in our current alphabet.

Specified by:
GetProbs in class CLanguageModel

AddSymbol

private void AddSymbol(CPPMLanguageModel.CPPMContext context,
                       int sym)

EnterSymbol

public void EnterSymbol(CContextBase c,
                        int Symbol)
Description copied from class: CLanguageModel
Modifies the supplied context, appending a given symbol.

The model should not alter its predictions based upon this entry.

Specified by:
EnterSymbol in class CLanguageModel
Parameters:
c - Context to modify
Symbol - Symbol to enter

LearnSymbol

public void LearnSymbol(CContextBase c,
                        int Symbol)
Description copied from class: CLanguageModel
Modifies the supplied context, appending a given symbol.

The model should learn from this if it can in order to make better predictions in future.

If the model is not capable of learning, this should behave precisely as EnterSymbol.

Specified by:
LearnSymbol in class CLanguageModel
Parameters:
c - Context to modify
Symbol - Symbol to enter

dumpSymbol

public void dumpSymbol(int sym)
Diagnostic method; prints a given symbol.

Parameters:
sym - Symbol to print

dumpString

public void dumpString(java.lang.String str,
                       int pos,
                       int len)
Diagnostic method; prints a given String starting at pos and with length len.

Parameters:
str - String to print
pos - Position to start printing
len - Number of characters to print

AddSymbolToNode

private CPPMLanguageModel.CAddSymReturnValue AddSymbolToNode(CPPMLanguageModel.CPPMnode Node,
                                                             int sym,
                                                             int updatein)

CreateEmptyContext

public CContextBase CreateEmptyContext()
Description copied from class: CLanguageModel
Creates an empty context

Specified by:
CreateEmptyContext in class CLanguageModel
Returns:
Child of CContextBase representing the empty context

CloneContext

public CContextBase CloneContext(CContextBase Input)
Description copied from class: CLanguageModel
Clones a given context; changes to one clone must not effect the state of the other.

Specified by:
CloneContext in class CLanguageModel
Parameters:
Input - Context to clone
Returns:
Clone of said context.

ReleaseContext

public void ReleaseContext(CContextBase release)
Description copied from class: CLanguageModel
Releases a given context; if the LanguageModel is keeping track of them internally or doing allocation work, it should release their storage.

Specified by:
ReleaseContext in class CLanguageModel
Parameters:
release - Context to release