|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdasher.CDasherComponent
dasher.CDasherModel
public class CDasherModel
Dasher 'world' data structures and dynamics.
The DasherModel represents the current state of Dasher. It contains a tree of DasherNodes, knows the current viewpoint and knows how to evolve the viewpoint.
It also plays host to the LanguageModel, being responsible for its creation and passing some requests to it from external components.
The Model does not know how to draw Dasher; this is the responsibility of a DasherView.
| Nested Class Summary | |
|---|---|
(package private) class |
CDasherModel.CTrainer
Helper class to assist in training of the language model. |
(package private) class |
CDasherModel.GNRCReturn
Simple struct for returning min/max pairs. |
(package private) class |
CDasherModel.SGotoItem
Simple struct recording a point to which we are scheduled to zoom. |
| Field Summary | |
|---|---|
protected long |
ControlSpace
Probability assinged to the Control Node |
protected CContextBase |
LearnContext
Our current prediction context. |
protected CAlphabetManagerFactory |
m_AlphabetManagerFactory
Our alphabet manager, for functions which require knowledge of an Alphabet. |
boolean |
m_bContextSensitive
Are the current model's predictions dependent on our context? |
protected CAlphabet |
m_cAlphabet
Alphabet used by this Model |
CDasherInterfaceBase |
m_DasherInterface
The Interface to which this Model belongs. |
protected java.util.LinkedList<CDasherModel.SGotoItem> |
m_deGotoQueue
List of points which we are to go to before responding to user input again. |
protected double |
m_dMaxRate
The probability that gets added to every symbol |
protected CFrameRate |
m_fr
Framerate tracker |
protected long |
m_iTargetMax
Next upper bound which NewGoto will make the upper edge of the viewport on its next call. |
protected long |
m_iTargetMin
Next lower bound which NewGoto will make the lower edge of the viewport on its next call. |
protected CLanguageModel |
m_LanguageModel
LanguageModel used by this Model for prediction. |
protected CDasherNode |
m_Root
Node which is currently root of the Node tree. |
protected long |
m_Rootmax
Root node's upper bound in Dasher world co-ordinates |
protected long |
m_Rootmax_max
Maximum allowable value of m_Rootmax |
protected long |
m_Rootmin
Root node's lower bound in Dasher world co-ordinates |
protected long |
m_Rootmin_min
Minimum allowable value of m_Rootmin |
protected int |
m_Stepnum
Number of interpolated steps to use in Click Mode. |
protected java.util.LinkedList<CDasherNode> |
oldroots
List of previous roots, to which we may revert if the user backs off sufficiently. |
protected double |
total_nats
Record of 'amount of information' entered so far, for logging purposes. |
protected int |
uniformAdd
Amount to add to all symbols' probabilities, in order to avoid a zero probability. |
| Fields inherited from class dasher.CDasherComponent |
|---|
m_EventHandler, m_SettingsStore |
| Constructor Summary | |
|---|---|
CDasherModel(CEventHandler EventHandler,
CSettingsStore SettingsStore,
CDasherInterfaceBase DashIface,
CAlphIO AlphIO)
Initialise a new DasherModel. |
|
| Method Summary | |
|---|---|
void |
adjustProbs(long[] probs)
Increments all probabilities by the value of uniformAdd, and sets the final probability to ControlSpace. |
boolean |
CheckForNewRoot(CDasherView View)
If the view reports that our current root node isn't visible, calls Reparent_root; if only one child of the current root is Alive (ie. |
protected void |
ClearRootQueue()
Forget about the queue of old root nodes. |
void |
ConnectNode(int iChild,
int iParent,
int iAfter)
Stub; implement if Control Mode is required. |
protected double |
CorrectionFactor(long dasherx,
long dashery)
TODO work out what this does and document. |
protected CContextBase |
CreateEmptyContext()
Deferred to m_LanguageModel |
protected boolean |
DeleteCharacters(CDasherNode newnode,
CDasherNode oldnode)
Traces back from oldnode to either a) newnode, in the case that oldnode is a descendent of newnode, or b) to the nearest common ancestor (ie. |
void |
deleteLM()
Runs the LanguageModel's UnregisterComponent method, if there is currently a LanguageModel. |
void |
DisconnectNode(int iChild,
int iParent)
Stub; implement if Control Mode is required. |
void |
EnterText(CContextBase context,
java.lang.String TheText)
Extends a given language model context without modifying the model itself. |
double |
Framerate()
Deferred to m_fr. |
protected CDasherModel.GNRCReturn |
Get_new_root_coords(long Mousex,
long Mousey)
Calculate the new co-ordinates for the root node after a single update step. |
protected CDasherNode |
Get_node_under_crosshair()
|
protected CDasherNode |
Get_node_under_mouse(long Mousex,
long Mousey)
Gets the node under the current mouse position. |
CAlphabet |
GetAlphabet()
Retrieves our current alphabet. |
CAlphabet |
GetAlphabetNew()
Retrieves our current alphabet. |
int |
GetColour(int s)
Deferred to m_cAlphabet |
java.util.ArrayList<java.lang.Integer> |
GetColours()
Deferred to m_cAlphabet |
protected long |
getControlSpace(int iNorm)
Gets the probability to associate with the control node |
int |
GetControlSymbol()
Gets our current alphabet's Control symbol |
java.lang.String |
GetDisplayText(int iSymbol)
Deferred to m_cAlphabet |
double |
GetNats()
Gets total_nats |
int |
getNonUniformNorm(int iNorm)
Calculates the non-uniform norm. |
long[] |
GetProbs(CContextBase context,
int iNorm)
Requests node probabilities from the language model given a context and a normalization value (usually LP_NORMALIZATION). |
CDasherNode |
GetRoot(int iType,
CDasherNode Parent,
long iLower,
long iUpper,
int UserData)
Constructs a new root Node of a given type, with a given parent which may be null if necessary. |
int |
GetSpaceSymbol()
Gets our current alphabet's Space symbol |
int |
GetStartConversionSymbol()
Gets our current alphabet's Start-conversion symbol |
CDasherModel.CTrainer |
GetTrainer()
Gets this model's helper training class. |
protected int |
getUniformAdd(int iNorm)
Calculates a value to add to all probabilities before use, preventing any zero values from being used and potentially resulting in missing nodes. |
void |
Halt()
Deferred to m_fr.Initialise(). |
void |
HandleEvent(CEvent Event)
The Model responds to the following events: |
protected void |
HandleOutput(CDasherNode NewNode,
CDasherNode OldNode)
Handles output based on the nodes which were under the crosshair before and after a move. |
void |
LearnText(CContextBase context,
java.lang.String TheText,
boolean IsMore)
Extends a given context with a given string of characters, whilst modifying the language model itself based on what is entered. |
protected void |
Make_root(CDasherNode whichchild)
Makes a specified child the new root node, deleting all of its siblings (by virtue of instructing its parent, the current root, to DeleteNephews. |
protected void |
MatchTarget()
Sets each of RootMin and RootMax to match their TargetMax and TargetMin partners. |
void |
NewFrame(long Time)
Deferred to m_fr. |
protected void |
NewGoTo(long newRootmin,
long newRootmax)
Changes the state of the Model updating the values of m_RootMax and m_RootMin, which has the effect of making us appear to move around. |
void |
Offset(int iOffset)
Sets each of Rootmin and Rootmax to TargetMin and TargetMax plus a given offset. |
protected void |
OldPush(long iMousex,
long iMousey)
Expands sections of the node tree, using random point selection and the Get_node_under method to try to bias the process in favour of larger nodes. |
protected void |
Push_Node(CDasherNode Node)
Deletes and then repopulates the children of a given node. |
protected void |
RebuildAroundNode(CDasherNode Node)
Makes a given Node the root, and then deletes and rebuilds its children. |
protected void |
Recursive_Push_Node(CDasherNode Node,
int iDepth)
Pushes a given node and recursively pushes its children to a given depth. |
protected void |
RecursiveMakeRoot(CDasherNode NewRoot)
Calls Make_root repeatedly to make a specified node the new root node. |
protected void |
RecursiveOutput(CDasherNode Node,
java.util.ArrayList<CSymbolProb> pAdded)
Given a Node which is supposed to be the current end of output, recursively checks whether the parent's Seen property is true (which indicates it has been output if appropriate) and invokes the AlphabetManager's Enter and Output methods on each unseen ancestor in tree-descending order. |
void |
RegisterNode(int iID,
java.lang.String strLabel,
int iColour)
Stub; implement if Control Mode is required. |
boolean |
RenderToView(CDasherView View,
boolean bRedrawDisplay)
Calls the View's Render method on our current Root; the View will take care of all drawing from here on in. |
protected void |
Reparent_root(long lower,
long upper)
Reconstructs the existing root's parent, so that we can back out of it. |
void |
Reset_framerate(long Time)
Deferred to m_fr. |
void |
ResetNats()
Sets total_nats back to 0. |
int |
ScheduledSteps()
Retrieves the number of points currently in the m_deGotoQueue. |
void |
ScheduleZoom(long dasherx,
long dashery)
Interpolates between our current position and a given new position, scheduling a zoom to the new position by adding the interpolated points to m_deGotoQueue. |
void |
SetBitrate(double TargetRate)
Deferred to m_fr. |
void |
SetContext(java.lang.String sNewContext)
Forces the current context to a given value, and resets our position in the Dasher world based upon it. |
void |
Start()
Sets a blank context. |
boolean |
Tap_on_display(long miMousex,
long miMousey,
long Time,
java.util.ArrayList<CSymbolProb> pAdded)
Performs a single update of the model based on a given mouse position and the time elpased since the last update took place. |
void |
UnregisterComponent()
Unregisters the language model and then ourselves. |
| 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 |
|---|
public boolean m_bContextSensitive
In reality almost all models are context sensitive.
public CDasherInterfaceBase m_DasherInterface
protected CLanguageModel m_LanguageModel
protected CAlphabet m_cAlphabet
protected CContextBase LearnContext
protected CDasherNode m_Root
protected java.util.LinkedList<CDasherNode> oldroots
protected long m_Rootmin
protected long m_Rootmax
protected long m_iTargetMin
protected long m_iTargetMax
protected long m_Rootmin_min
protected long m_Rootmax_max
protected CFrameRate m_fr
protected double total_nats
protected double m_dMaxRate
protected int m_Stepnum
CClickFilterprotected CAlphabetManagerFactory m_AlphabetManagerFactory
protected java.util.LinkedList<CDasherModel.SGotoItem> m_deGotoQueue
protected int uniformAdd
protected long ControlSpace
| Constructor Detail |
|---|
public CDasherModel(CEventHandler EventHandler,
CSettingsStore SettingsStore,
CDasherInterfaceBase DashIface,
CAlphIO AlphIO)
This does not train the newly created language model; this must be requested from outside, typically by the Interface.
EventHandler - Event handler with which to register ourselvesSettingsStore - Settings repositoryDashIface - Interface which we serveAlphIO - AlphIO object from which to retrieve the AlphInfo object describing the user's chosen alphabet| Method Detail |
|---|
public void HandleEvent(CEvent Event)
LP_MAX_BITRATE: Informs the CFrameRate which performs frame rate tracking for us of the new frame rate.
BP_CONTROL_MODE: Rebuilds the model (calls RebuildAroundNode) to include/exclude a control node.
BP_DELAY_VIEW: Sets the TargetMax to match RootMax and similarly RootMin.
LP_UNIFORM: Updates our internally cached value (uniformAdd) to reflect the new value.
HandleEvent in class CDasherComponentEvent - Event received.protected void Make_root(CDasherNode whichchild)
This function does not make any checks that the specified Node really is a child of the current root, or that we are in a sensible position to redefine the root; the behaviour if this is not ensured before calling is undefined.
The former root node will be added to oldroots, in case we need to recover it in future.
m_RootMax, m_TargetMax and their brethren are also updated to take into account the new root's Hbnd and Lbnd values.
Due to this function's lack of checks made on the validity of the requested operation, it is recommended to use RecursiveMakeRoot instead where possible.
whichchild - Child to make the new root node.protected void ClearRootQueue()
This should be called when the previous context is no longer valid.
protected void RecursiveMakeRoot(CDasherNode NewRoot)
This function must be called on some descendent of the current root.
Behaviour if called upon a node which is not is undefined; most likely it would eventually run into a node whose parent has been deleted, and fail with a NullPointerException.
NewRoot - Node to make the root.protected void RebuildAroundNode(CDasherNode Node)
This is intended for situations when an existing Node has children which are no longer correct; for instance, if Control Mode has been switched on necessitating a new child Node, or if the language model has been changed.
The specified Node must be a descendent of the existing root, or RecursiveMakeRoot will fail to find a link between the two.
Node - New root node after the rebuild.
protected void Reparent_root(long lower,
long upper)
This will first try to use an old Node stored in the oldroots list, but if this is empty will use the AlphabetManager's RebuildParent method to instantiate a new parent.
If unsuccessful in building a parent, or if the current root is the base node in which Dasher starts, the method will return without performing any action.
m_RootMax, m_TargetMax and their brethren will also be appropriately updated.
lower - Current root's Lbndupper - Current root's Hbndprotected CDasherNode Get_node_under_crosshair()
protected CDasherNode Get_node_under_mouse(long Mousex,
long Mousey)
Mousex - Current mouse x co-ordinateMousey - Current mouse y co-ordinate
public void Start()
This ought not to matter as SetContext fulfils this purpose with a given context, and so can duplicate the function of Start by passing it the empty string.
public void SetContext(java.lang.String sNewContext)
If the given context is empty, the context is actually set to ". " so that the prediction is the same as for the beginning of a new sentence.
Internally, this works by requesting a new Root node from the Alphabet Manager, creating a blank context, and training it using the supplied String.
This method also has the following side-effects:
sNewContext - Context to set
protected CDasherModel.GNRCReturn Get_new_root_coords(long Mousex,
long Mousey)
Mousex - x mouse co-ordinate measured right to left.Mousey - y mouse co-ordinate measured top to bottom.
public boolean Tap_on_display(long miMousex,
long miMousey,
long Time,
java.util.ArrayList<CSymbolProb> pAdded)
If BP_OLD_STYLE_PUSH is enabled, prompts the creation of new segments of tree where appropriate, using OldPush. If not, we let node pushing take place elsewhere.
In the case that the m_deGotoQueue contains any points, indicating that a pre-scheduled zoom is currently in progress, we move to the next specified point in the queue instead and ignore the mouse position.
Internally, this method uses Get_new_root_coords to work out where to go, and NewGoto to actually go there.
If this method is called whilst Dasher is paused, it will do nothing and return false.
miMousex - Current mouse X co-ordinatemiMousey - Current mouse Y co-ordinateTime - Current system time as a UNIX timestamppAdded - Ignored parameter
protected void OldPush(long iMousex,
long iMousey)
Takes account of the current frame rate, and does more pushing if Dasher is performing better.
This method is only ever used if BP_OLD_STYLE_PUSH is enabled which is not the default.
The actual node pushing is done by Push_Node.
iMousex - Current mouse X co-ordinateiMousey - Current mosue Y co-ordinate
protected void RecursiveOutput(CDasherNode Node,
java.util.ArrayList<CSymbolProb> pAdded)
The nodes' Seen flag is also set, preventing repeated output of the same nodes.
Node - Node to output, possibly including its ancestorspAdded - ArrayList which will be filled with output characters
for logging purposes.
protected void NewGoTo(long newRootmin,
long newRootmax)
Both values are checked for sanity and truncated if necessary.
m_iTargetMax and Min are also updated according to the new values of RootMax/Min.
For the purpose of output handling, the node under the crosshair is noted before and after enacting the move, and HandleOutput invoked upon this pair.
At present, this function takes no action if the proposed new values are not allowable; it returns without making any changes which has the effect of causing Dasher to freeze.
newRootmin - Desired new value of m_RootMinnewRootmax - Desired new value of m_RootMax
protected void HandleOutput(CDasherNode NewNode,
CDasherNode OldNode)
If the NewNode has its Seen flag already set, returns without taking any action.
Internally this works by calling DeleteCharacters on the two nodes if they are different, and then RecursiveOutput on the current node and null.
NewNode - Node now under the crosshairOldNode - Node previously under the crosshair (maybe the same as NewNode)
protected boolean DeleteCharacters(CDasherNode newnode,
CDasherNode oldnode)
In case a) we will now be consistent with the user's current location; in case b) we have deleted the text belonging to oldnode's branch but not output the text for newnode; HandleOutput must be used to finish the job.
If either parameter is null, this method will return false and take no action.
newnode - Node currently under the crosshairoldnode - Node previously under the crosshair
public long[] GetProbs(CContextBase context,
int iNorm)
Internally, this recalculates the norm value using getNonUniformNorm, and passes the context and this new norm onto m_LanguageModel.getProbs.
Once the probabilities are calculated, it runs them through adjustProbs before returning.
context - Language model context in which the
probabilities are to be found.iNorm - Normalization
public void adjustProbs(long[] probs)
probs - The probabilities to modifypublic int getNonUniformNorm(int iNorm)
iNorm - Normalization value, usually LP_NORMALIZATION
protected int getUniformAdd(int iNorm)
iNorm - Normalization value (usually LP_NORMALIZATION)
protected long getControlSpace(int iNorm)
This will be either 5% of the norm value if control mode is enabled, or zero otherwise.
iNorm - Normalization value (usually LP_NORMALIZATION)
public void LearnText(CContextBase context,
java.lang.String TheText,
boolean IsMore)
The bulk of the work is deferred to the language model's LearnSymbol method.
context - Context to extendTheText - Text to addIsMore - Ignored
public void EnterText(CContextBase context,
java.lang.String TheText)
The bulk of the work itself is deferred to the LanguageModel's EnterSymbol method.
context - Context to extendTheText - Text to addpublic CDasherModel.CTrainer GetTrainer()
protected void Push_Node(CDasherNode Node)
If the pushed node has no associated context, an attempt is made to derive it by extending that of the node's parent, and as a last ditch, creating an empty one.
Node - Node to push. Must not be null.
protected void Recursive_Push_Node(CDasherNode Node,
int iDepth)
The tree of recursive pushes will be truncated whenever an attempt is made to push a node filling less than 10% of the screen or which is the control node.
Node - Node at which to start pushingiDepth - Maximum depth to which we should push
public boolean RenderToView(CDasherView View,
boolean bRedrawDisplay)
If BP_OLD_STYLE_PUSH is not enabled, all Nodes which the View reports it has drawn will be pushed here, and all which the View reported as undrawable due to being too small, off the screen, etc, will have their children deleted.
View - View to which we wish to drawbRedrawDisplay - Whether to force a complete redraw
public boolean CheckForNewRoot(CDasherView View)
The actual work will be done by Reparent_root and Make_root respectively; this just decides which to use and when.
View - View against which to check node visibility.
protected double CorrectionFactor(long dasherx,
long dashery)
dasherx - Dasher X co-ordinatedashery - Dasher Y co-ordinate
public void ScheduleZoom(long dasherx,
long dashery)
dasherx will be increased to 100 if this is not already so.
The number of points to interpolate (and hence the smoothness of the zoom, at the expense of speed,) is controlled by LP_ZOOMSTEPS.
dasherx - Destination Dasher X co-ordinatedashery - Destination Dasher Y co-ordinatepublic void deleteLM()
public void UnregisterComponent()
UnregisterComponent in class CDasherComponentpublic void Offset(int iOffset)
iOffset - Offset to addprotected void MatchTarget()
public void NewFrame(long Time)
public double Framerate()
public void Reset_framerate(long Time)
public void Halt()
public void SetBitrate(double TargetRate)
public void ResetNats()
public double GetNats()
public int GetSpaceSymbol()
public int GetControlSymbol()
public int GetStartConversionSymbol()
public java.lang.String GetDisplayText(int iSymbol)
public CAlphabet GetAlphabet()
public CAlphabet GetAlphabetNew()
public CDasherNode GetRoot(int iType,
CDasherNode Parent,
long iLower,
long iUpper,
int UserData)
iType - Type of node to create. At present, ignored; only ordinary letter nodes are created.Parent - Parent of the node we will create. May be null.iLower - Desired Lbnd of the new NodeiUpper - Desired Hbnd of the new Node
public void RegisterNode(int iID,
java.lang.String strLabel,
int iColour)
The code for this is commented but present in the source.
public void ConnectNode(int iChild,
int iParent,
int iAfter)
The code for this is commented but present in the source.
public void DisconnectNode(int iChild,
int iParent)
The code for this is commented but present in the source.
public int ScheduledSteps()
protected CContextBase CreateEmptyContext()
public int GetColour(int s)
public java.util.ArrayList<java.lang.Integer> GetColours()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||