TouchML

Examples


Python I

Create an offset model

1.

Load data

Load N targeting actions from a csv-file with the four columns touch x, touch y, target x, target y:

data = loadData("data.csv")

2.

Train a model

Create a model object and call its fit method, providing the training data as a parameter:

model = LinearOffsetModel()
model.fit(data)

3.

Visualise it

Visualise the model with one of the following plots:

arrowPlot(model)
contourPlot(model, dim="x")
variancePlot(model)

Python II

Improve touch accuracy

1.

Create a model from data

Load targeting actions from a csv-file with the four columns touch x, touch y, target x, target y. Create an offset model and train it on the loaded data:

data = loadData("data.csv")
model = LinearOffsetModel()
model.fit(data)

2.

Predict offsets of new touches

After training, offset predictions for N touch locations can be computed as follows:

means, covs = model.predict(newTouches)

As a result, means is a N x 2 array with the predicted x, y offsets, and covs is a list of N corresponding covariance matrices. Together, means and covs define a Gaussian distribution of likely offsets for each touch.

3.

Correct touch locations

Correct touch locations by adding the predicted mean offset per touch

corrected = newTouches + means

Note: Thanks to numpy, arrays can be added up element-wise without loops.


JavaScript

Create an offset model on the web

1.

Create a model from external data

Create a model object and define a function to be called when the file is read. Finally, load targeting actions from a csv-file with the four columns touch x, touch y, target x, target y:

var model = new LinearOffsetModel();

function loadCallback(data){
model.fit(data);
};

loadData("data.csv", loadCallback);

2.

Predict offsets

After training, offset predictions for N touch locations can be computed as follows:

var pred = model.predict(newTouches, true);

As a result, pred is an object with two attributes:

  • means: an array of N arrays with the predicted x, y offsets
  • covs: an array of 2D arrays with the corresponding covariance matrices.

Together, means and covs define a Gaussian distribution of likely offsets for each touch.


Android / Java

Create an offset model in Android

1.

Create a model from external data

Create a model object, and provide N training touches in a 2D-array (of shape N x 4) with the four columns touch x, touch y, target x, target y:

double[][] trainingData = new double[N][4];
// ... fill data array (e.g. load from file)

OffsetModel model = new GPOffsetModel();
model.fit(data, false);

2.

Predict offsets

After training, offset predictions for a touch at location x, y are computed as follows:

double[] touch = new double[2];
touch[0] = x;
touch[1] = y;
double[] mean = model.predictMean(touch);
double[][] cov = model.predictVar(touch);

As a result, mean and cov define a Gaussian distribution of likely offsets for this touch.