TouchML

Documentation

Python | JavaScript | Android


Python
GPOffsetModel:

GPOffsetModel(gamma=2, noiseVar=0.001, diag=0.9, kernelMix=0.1)

Constructor for creating a new Gaussian Process offset model.

Parameters:

gamma - the length-scale of the Gaussian (gamma in the paper)

noiseVar - the variance of the assumed noise (sigma squared in the paper)

diag - dependency of x and y (alpha in the paper)

kernelMix - the relative weight of the linear and non-linear parts of the kernel function ("a" in the paper)

GPOffsetModel:

fit(touchData, targetsAreOffsets=False)

Fits the model to the given training data using Gaussian Process regression.

Parameters:

touchData - 2D array, each row is one touch with intended target, with columns touch x and y, and target x and y

targetsAreOffsets - boolean, defaults to false; if true, the 3rd and 4th column of each row in the touchData array are interpreted as measured offsets directly, instead of target locations

GPOffsetModel:

predict(inputs, returnVar=False)

Predicts offsets for the given touches. Only call this method after fitting the model.

Parameters:

inputs - 2D array, each row is one touch with columns x and y

returnVar - boolean, defaults to false; if false this method only returns the mean prediction for each touch; if true, the method also returns the predictive covariance matrix for each touch

Returns:

If returnVar is set to false, this method returns a 2D array: each row contains the x and y mean predictions for the touch in the corresponding row of the inputs array. If returnVar is set to true, this method returns two objects:

  • means: the array of mean predictions as described above
  • covs: an array of 2D arrays, where the i-th entry is the predictive covariance matrix for the i-th touch in the inputs array

LinearOffsetModel:

LinearOffsetModel(lambdaReg=0.001)

Constructor for creating a new linear offset model.

Parameters:

lambdaReg - the regularisation parameter

LinearOffsetModel:

fit(touchData, targetsAreOffsets=False)

Fits the model to the given training data using regularised linear regression.

Parameters:

touchData - 2D array, each row is one touch with intended target, with columns touch x and y, and target x and y

targetsAreOffsets - boolean, defaults to false; if true, the 3rd and 4th column of each row in the touchData array are interpreted as measured offsets directly, instead of target locations

LinearOffsetModel:

predict(inputs, returnVar=False)

Predicts offsets for the given touches. Only call this method after fitting the model.

Parameters:

inputs - 2D array, each row is one touch with columns x and y

returnVar - boolean, defaults to false; if false this method only returns the mean prediction for each touch; if true, the method also returns the predictive covariance matrix for each touch

Returns:

If returnVar is set to false, this method returns a 2D array: each row contains the x and y mean predictions for the touch in the corresponding row of the inputs array. If returnVar is set to true, this method returns two objects:

  • means: the array of mean predictions as described above
  • covs: an array of 2D arrays, where the i-th entry is the predictive covariance matrix for the i-th touch in the inputs array


JavaScript
LinearOffsetModel:

LinearOffsetModel(lambdaReg)

Constructor for creating a new linear offset model.

Parameters:

lambdaReg - float, defaults to 0.001; the regularisation parameter

LinearOffsetModel:

fit(touchData, targetsAreOffsets)

Fits the model to the given training data using regularised linear regression.

Parameters:

touchData - 2D array, each row is one touch with intended target, with columns touch x and y, and target x and y

targetsAreOffsets - boolean, defaults to false; if true, the 3rd and 4th column of each row in the touchData array are interpreted as measured offsets directly, instead of target locations

LinearOffsetModel:

predict(inputs, returnVar)

Predicts offsets for the given touches. Only call this method after fitting the model.

Parameters:

inputs - 2D array, each row is one touch with columns x and y

returnVar - boolean, defaults to false; if false this method only returns the mean prediction for each touch; if true, the method also returns the predictive covariance matrix for each touch

Returns:

If returnVar is set to false, this method returns a 2D array: each row contains the x and y mean predictions for the touch in the corresponding row of the inputs array. If returnVar is set to true, this method returns an object with two attributes:

  • means: the array of mean predictions as described above
  • covs: an array of 2D arrays, where the i-th entry is the predictive covariance matrix for the i-th touch in the inputs array

GPOffsetModel:

GPOffsetModel(gamma, noiseVar, kernelMix)

Constructor for creating a new Gaussian Process offset model.

Parameters:

gamma - float, defaults to 2; the length-scale of the Gaussian (gamma in the paper)

noiseVar - float, defaults to 0.001; the variance of the assumed noise (sigma squared in the paper)

kernelMix - float, defaults to 0.1; the relative weight of the linear and non-linear parts of the kernel function ("a" in the paper)

Note: In contrast to the Python version, this JavaScript implementation of the GP models uses diag fixed to zero for reasons of performance. This avoids doubling the size of the covariance matrix (see GP model description in the paper).

GPOffsetModel:

fit(touchData, targetsAreOffsets)

Fits the model to the given training data using Gaussian Process regression.

Parameters:

touchData - 2D array, each row is one touch with intended target, with columns touch x and y, and target x and y

targetsAreOffsets - boolean, defaults to false; if true, the 3rd and 4th column of each row in the touchData array are interpreted as measured offsets directly, instead of target locations

GPOffsetModel:

predict(inputs, returnVar)

Predicts offsets for the given touches. Only call this method after fitting the model.

Parameters:

inputs - 2D array, each row is one touch with columns x and y

returnVar - boolean, defaults to false; if false this method only returns the mean prediction for each touch; if true, the method also returns the predictive covariance matrix for each touch

Returns:

If returnVar is set to false, this method returns a 2D array: each row contains the x and y mean predictions for the touch in the corresponding row of the inputs array. If returnVar is set to true, this method returns an object with two attributes:

  • means: the array of mean predictions as described above
  • covs: an array of 2D arrays, where the i-th entry is the predictive covariance matrix for the i-th touch in the inputs array

loadData(file, callback)

Load targeting data from a separate file.

Parameters:

file - the file (path) with the data

callback - function to be called after loading the data. The callback function should take one parameter, which is the data.


Android

The usage of the Android part of the toolkit is equivalent to the others and is demonstrated in an example app (Android-Studio project), which showcases learning and predicting touch targeting behaviour.

To use the models in other Android projects right away, just copy over the "ml" package from the Android "src" directory to your own project - it contains all relevant files (GPOffsetModel.java, LinearOffsetModel.java, OffsetModel.java). This saves you the time to import a library, and you can easily edit the code as well, if you so desire.

Basic code snippets can be found on the Examples page.