dasher
Class CLanguageModel

java.lang.Object
  extended by dasher.CDasherComponent
      extended by dasher.CLanguageModel
Direct Known Subclasses:
CPPMLanguageModel, CRemotePPM

public abstract class CLanguageModel
extends CDasherComponent

LanguageModels are responsible for predicting / guessing the probabilities associated with members of a given alphabet in a given context.

They have no internal state except for knowledge of the alphabet in which they make predictions; rather they produce, modify and destroy Context objects (subclasses of CContextBase) which represent the context in which they were working. This enables the impression of multiple diverging models, when in fact the model is only capable of answering one question: "What comes next in this context?"

Models can adapt themselves in response to user input, and should do so if they are capable when LearnSymbol is called. Calls to EnterSymbol on the other hand should modify their context without altering the model.


Field Summary
protected  CSymbolAlphabet m_Alphabet
          Alphabet in which we make predictions
static CContextBase nullContext
          Value to be returned when we need a null context.
 
Fields inherited from class dasher.CDasherComponent
m_EventHandler, m_SettingsStore
 
Constructor Summary
CLanguageModel(CEventHandler EventHandler, CSettingsStore SettingsStore, CSymbolAlphabet Alphabet)
          Creates a LanguageModel working in a given alphabet.
 
Method Summary
abstract  CContextBase CloneContext(CContextBase Context)
          Clones a given context; changes to one clone must not effect the state of the other.
abstract  CContextBase CreateEmptyContext()
          Creates an empty context
abstract  void EnterSymbol(CContextBase context, int Symbol)
          Modifies the supplied context, appending a given symbol.
abstract  int GetMemory()
          Get some measure of the memory usage for diagnostic purposes.
abstract  long[] GetProbs(CContextBase Context, long iNorm)
          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.
protected  int GetSize()
          Gets the number of characters in our alphabet
 void HandleEvent(CEvent Event)
          Ignores all events
 boolean isRemote()
          Indicates whether this is a remote/asynchronous model with respect to returning probabilities.
abstract  void LearnSymbol(CContextBase context, int Symbol)
          Modifies the supplied context, appending a given symbol.
abstract  void ReleaseContext(CContextBase Context)
          Releases a given context; if the LanguageModel is keeping track of them internally or doing allocation work, it should release their storage.
 CSymbolAlphabet SymbolAlphabet()
          Gets our working alphabet
 
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

nullContext

public static final CContextBase nullContext
Value to be returned when we need a null context.


m_Alphabet

protected CSymbolAlphabet m_Alphabet
Alphabet in which we make predictions

Constructor Detail

CLanguageModel

public CLanguageModel(CEventHandler EventHandler,
                      CSettingsStore SettingsStore,
                      CSymbolAlphabet Alphabet)
Creates a LanguageModel working in a given alphabet.

Parameters:
EventHandler - Event handler with which to register ourselves
SettingsStore - Settings repository to use
Alphabet - Alphabet to work in
Method Detail

HandleEvent

public void HandleEvent(CEvent Event)
Ignores all events

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

isRemote

public boolean isRemote()
Indicates whether this is a remote/asynchronous model with respect to returning probabilities.

Returns:
True if asynchronous, false if not

CreateEmptyContext

public abstract CContextBase CreateEmptyContext()
Creates an empty context

Returns:
Child of CContextBase representing the empty context

CloneContext

public abstract CContextBase CloneContext(CContextBase Context)
Clones a given context; changes to one clone must not effect the state of the other.

Parameters:
Context - Context to clone
Returns:
Clone of said context.

ReleaseContext

public abstract void ReleaseContext(CContextBase Context)
Releases a given context; if the LanguageModel is keeping track of them internally or doing allocation work, it should release their storage.

Parameters:
Context - Context to release

EnterSymbol

public abstract void EnterSymbol(CContextBase context,
                                 int Symbol)
Modifies the supplied context, appending a given symbol.

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

Parameters:
context - Context to modify
Symbol - Symbol to enter

LearnSymbol

public abstract void LearnSymbol(CContextBase context,
                                 int Symbol)
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.

Parameters:
context - Context to modify
Symbol - Symbol to enter

GetProbs

public abstract long[] GetProbs(CContextBase Context,
                                long iNorm)
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.


GetMemory

public abstract int GetMemory()
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).

Returns:
Memory usage in bytes, or 0 if unknown or we don't care

SymbolAlphabet

public CSymbolAlphabet SymbolAlphabet()
Gets our working alphabet

Returns:
m_Alphabet

GetSize

protected int GetSize()
Gets the number of characters in our alphabet

Returns:
m_Alphabet.size()