dasher
Class CRemotePPM

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

public class CRemotePPM
extends CLanguageModel

Implements the client side of a remote language model. Whilst named RemotePPM, there is no reason why the remote side shouldn't operate some different language model.

For details on the server required, see the website at www.smowton.net/chris

For details of the PPM Language model see CPPMLanguageModel

For details of the general contract of a language model, see CLanguageModel.


Nested Class Summary
(package private)  class CRemotePPM.CloneContextOp
           
(package private)  class CRemotePPM.CreateEmptyContextOp
           
(package private)  class CRemotePPM.EnterSymbolOp
           
(package private)  class CRemotePPM.GetProbsOp
           
(package private)  class CRemotePPM.MessageDispatcherThread
           
(package private)  class CRemotePPM.MessageListenerThread
           
(package private)  class CRemotePPM.ReleaseContextOp
           
(package private)  class CRemotePPM.RemotePPMContext
           
(package private)  class CRemotePPM.RemotePPMOperation
           
(package private) static class CRemotePPM.RemotePPMOperationType
           
 
Field Summary
private  CRemotePPM.MessageDispatcherThread dispatch
           
private  java.util.LinkedList<ProbsListener> eventListeners
           
private  int lastHandle
           
private  java.util.LinkedList<CRemotePPM.RemotePPMOperation> pendingMessageQueue
           
 
Fields inherited from class dasher.CLanguageModel
m_Alphabet, nullContext
 
Fields inherited from class dasher.CDasherComponent
m_EventHandler, m_SettingsStore
 
Constructor Summary
CRemotePPM(CEventHandler EventHandler, CSettingsStore SettingsStore, CSymbolAlphabet SymbolAlphabet)
           
 
Method Summary
 CContextBase CloneContext(CContextBase Context)
          Clones a given context; changes to one clone must not effect the state of the other.
 CContextBase CreateEmptyContext()
          Creates an empty context
private  void enQueueMessage(CRemotePPM.RemotePPMOperation message)
           
 void EnterSymbol(CContextBase context, 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 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.
private  int GetUnusedHandle()
           
static void intToBytes(byte[] destination, int input, int offset)
           
 boolean isRemote()
          Indicates whether this is a remote/asynchronous model with respect to returning probabilities.
 void LearnSymbol(CContextBase context, int Symbol)
          Modifies the supplied context, appending a given symbol.
static void longToBytes(byte[] destination, long input, int offset)
           
 void notifyNetworkFailure(int errorCode)
           
 void ProbsArrived(long[] probs)
           
 void PromptForProbs(CContextBase Context, long iNorm)
           
 void RegisterProbsListener(ProbsListener it)
           
 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.
 void transmitMessages(java.io.OutputStream out)
           
 void UnregisterComponent()
          Unregisters this component with the EventHandler, preventing the receipt of any further events, though new ones can still be dispatched.
 
Methods inherited from class dasher.CLanguageModel
GetSize, HandleEvent, SymbolAlphabet
 
Methods inherited from class dasher.CDasherComponent
GetBoolParameter, GetLongParameter, GetParameterName, GetParameterType, GetStringParameter, InsertEvent, SetBoolParameter, SetLongParameter, SetStringParameter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastHandle

private int lastHandle

dispatch

private CRemotePPM.MessageDispatcherThread dispatch

pendingMessageQueue

private java.util.LinkedList<CRemotePPM.RemotePPMOperation> pendingMessageQueue

eventListeners

private java.util.LinkedList<ProbsListener> eventListeners
Constructor Detail

CRemotePPM

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

intToBytes

public static void intToBytes(byte[] destination,
                              int input,
                              int offset)

longToBytes

public static void longToBytes(byte[] destination,
                               long input,
                               int offset)

CloneContext

public CContextBase CloneContext(CContextBase Context)
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:
Context - Context to clone
Returns:
Clone of said context.

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

EnterSymbol

public void EnterSymbol(CContextBase context,
                        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:
context - Context to modify
Symbol - Symbol to enter

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

PromptForProbs

public void PromptForProbs(CContextBase Context,
                           long iNorm)

ProbsArrived

public void ProbsArrived(long[] probs)

RegisterProbsListener

public void RegisterProbsListener(ProbsListener it)

GetProbs

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

LearnSymbol

public void LearnSymbol(CContextBase context,
                        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:
context - Context to modify
Symbol - Symbol to enter

ReleaseContext

public void ReleaseContext(CContextBase Context)
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:
Context - Context to release

GetUnusedHandle

private int GetUnusedHandle()

enQueueMessage

private void enQueueMessage(CRemotePPM.RemotePPMOperation message)

transmitMessages

public void transmitMessages(java.io.OutputStream out)

isRemote

public boolean isRemote()
Description copied from class: CLanguageModel
Indicates whether this is a remote/asynchronous model with respect to returning probabilities.

Overrides:
isRemote in class CLanguageModel
Returns:
True if asynchronous, false if not

UnregisterComponent

public void UnregisterComponent()
Description copied from class: CDasherComponent
Unregisters this component with the EventHandler, preventing the receipt of any further events, though new ones can still be dispatched. Typically this is called on destruction of the object.

Overrides:
UnregisterComponent in class CDasherComponent

notifyNetworkFailure

public void notifyNetworkFailure(int errorCode)