Demo 2: Temporal Shift Between Tasks

File name: demoMTGP_shift.m

The correlation between tasks can be effected by time-shifts between tasks (e.g., one task is temporally delayed with respect to another). This demo illustrates such an effect (in case 1) and shows how MTGP models can estimate and compensate for these time-shifts between tasks (in case 2). Case 3 then illustrates how this idea could be further used to perform multidimensional template matching. To use demoMTGP_shift.m, please include the path of the GPML toolbox or specify the path in demoMTGP_shift.m (line 6). The example contains 3 cases. Please select one of the cases by specifying the variable MTGP_case (line 21).

line 21:MTGP_case = 1% default method

The plots above show the original dataset (shown by the blue solid line) for three sinusoidally-varying tasks (S1 - S3). The tasks are not perfectly correlated with each other because a phase shift has been added to task S2 (phi2 = 45°) and task S3 (phi2 = 90°). The training data for task S1 are taken to be all data occurring within the range of t = [0 5]s. The training data for the other two tasks are taken to be those data between t = [0 2.5]s for both S2 and S3 (marked by the shaded yellow regions). The results have been generated by the MTGP toolbox using a squared exponential temporal covariance function k_t. The model is initialised assuming perfectly correlated tasks. The predicted values are shown by the red solid line and with the 95% confidence interval shown by the shaded grey area. These results indicate that this normal MTGP model (which is not modelling phase shift between tasks) is strongly affected by the phase shifts that exist. This leads to high values of RMSE_test for task S2 and S3, and where it may be seen that the predictions (blue line and grey region) do not closely follow the actual data (red line).

line 21:MTGP_case = 2

We can improve the accuracy of the predictions shown in case 1 by extending the MTGP with two hyperparameters that represent the phase shift between tasks S1-S2 and tasks S1-S3. The new hyperparameters can be optimised by minimising the NLML as before. As anticipated, we can see that the prediction accuracy increases (with a lower corresponding RMSE_test) and the confidence interval (shown in grey) decreases, representing our increased certainty in the prediction. The optimised phase-shift hyperparameters are shown at the console: theta_s2 = 0.126s and theta_s3 = 0.25s, which is equivalent to the phase shifts phi2 and phi3 for sinusoidal signals with a period of 1s (as we have in this example).

line 21:MTGP_case = 3

The above example can easily be extended from univariate time-series to multivariate quantities (e.g., over spatial coordinates). This case illustrates an example how MTGP could be used for template matching with a bivariate data space. We emphasise that, for this example, tasks S1 and S2 do not have any training data in common. The figures show two 2-dimensional tasks. Task S2 is shifted with respect to task S1 in the x-dimension by -0.15 and in the y-dimension by -0.26. The training points for each task are marked as black asterisks. A MTGP model that has two additional hyperparameters (one for each dimension) is used. As shown in the lower sub-plot (within the red box), the estimates for the x- and y-shift between task S1 and S2 are very close to the actual offsets.