Gaussian process code in C++ including some implementations of GP-LVM and IVM.
| Workflow | Badge |
|---|---|
| Compile | |
| Reference tests | |
| Coverage | |
| Wheels | |
| Codecov |
Platforms: Ubuntu and macOS are the blessed build targets (CIP-0006). Compile and Reference tests are hard gates on both. Coverage stays on Ubuntu. Windows has an experimental soft-gated CMake smoke job (MSVC + Intel ifx + OpenBLAS, CIP-002B); there is no blessed make path on Windows.
Verification: reference fixtures under matfiles/ load through libmatio — MATLAB is not required to build or run the test gate (make USE_MATIO=1 run-matio-tests). Optional object-level MATLAB I/O remains behind _NDLMATLAB.
Release: there is no numbered product release and no git tag yet. Treat main as the living source of truth; the Status badges above reflect CI on that branch.
Maintainer notes (build/CI rationale, numerics policy, planning workflow) live under docs/. The target architecture shared with a future JAX-based GPy2 is in docs/target-architecture.md.
Tutorials: step-by-step CLI recipes for the shipped examples/*.svml workflows (CIP-0015 Stage 1), plus Bayesian GPLVM / MRD pointers (CIP-0017 / CIP-0018), live under docs/tutorials/. Start at docs/tutorials/README.md.
Python façade (gpc): NumPy-facing wrapper (CIP-001D / CIP-002C). Users: pip install gpc once published (see python/README.md). Contributors: pip install -e "python/[test]" with OpenBLAS + gfortran (same page).
Binaries / demos: make gp ivm gplvm bgplvm ppa (or make all). Optional API demos: make demos builds demo_regression_1d, demo_sparse_dtcvar, demo_bayes_gplvm, and demo_mrd. Optimiser budget semantics for -#: docs/optimisers.md.
This page describes how to compile and gives some examples of use of the C++ Gaussian Process code.
The software is written in C++ so models stay flexible without the interpreter tax that made flexible MATLAB GP designs slow. It relies on FORTRAN helpers plus LAPACK/BLAS for dense linear algebra. Optional MATLAB/OCTAVE helpers remain useful for visualisation; they are not part of the build or test gate.
The software was written with gcc on ubuntu and builds on contemporary macOS via Homebrew.
Part of the reason for using gcc is the ease of interoperability with FORTRAN. The code base makes fairly extensive use of FORTRAN so you need a Fortran compiler (gfortran on contemporary systems; historically g77). The software is compiled by writing
$ make gpat the command line. Architecture-specific options live in make.linux (Ubuntu / GitHub Actions) and make.osx (Homebrew macOS). Copy the right file to make.inc for a local override; without make.inc, make.linux is used (C++17). make.inc is gitignored. Make remains the blessed native and CI path. An optional thin CMake build (CIP-0020) can produce the same core library and CLI smoke targets (cmake -B build -DCMAKE_PREFIX_PATH="$(brew --prefix openblas)" && cmake --build build on Homebrew macOS); it is not the CI gate yet. Older platform fragments and an archived 2020 CMake stub live under make/legacy/ and are not CI targets.
$ brew install gcc openblas libmatio
$ cp make.osx make.inc
$ make clean
$ make gp
$ ./gp -hmake.osx uses Homebrew g++-16 / gfortran-16 and OpenBLAS. For the matio reference suite on the Mac: make clean && make USE_MATIO=1 matio-tests then make run-matio-tests (rebuild without USE_MATIO if you need gp/ivm/gplvm again, or link with matio as well).
Default make.linux links OpenBLAS (libopenblas-dev) and builds with -O2 -g and cheap checks (GPC_CHECKS=1: dimensions / API invariants). For the timed / documented competitive path:
$ sudo apt-get install -y g++ gfortran libopenblas-dev
$ make clean
$ make RELEASE=1 gp
$ OPENBLAS_NUM_THREADS=1 make RELEASE=1 bench
$ OPENBLAS_NUM_THREADS=1 ./benchGPc --kind ftc --N 1000 --q 2
$ OPENBLAS_NUM_THREADS=1 python bench/run_bench.py --kinds ftc,dtcvar,fitc --N 1000 --M 50make RELEASE=1 is -O2 -DNDEBUG with checks off (GPC_CHECKS=0). Exhaustive per-element checks: make CHECKS=full … (GPC_CHECKS=2); reference CI uses that. See docs/build-and-ci.md and cip/cip002D.md.
Numeric fixtures in matfiles/ can be loaded with libmatio instead of a full MATLAB/mex install:
$ sudo apt-get install -y libmatio-dev # Debian/Ubuntu
$ make USE_MATIO=1 matio-tests
$ make run-matio-testsGitHub Actions runs this path as the Reference tests workflow. Object-level MATLAB I/O remains behind _NDLMATLAB.
Kernel types exercised by testKern include the CIP-000C set: matern32ard, matern52ard, ratquadard, exp, stdperiodic, cosine, brownian (plus the historical catalogue). Regenerate those fixtures with scripts/gen_cip000C_kern_fixtures.py (project .venv with numpy/scipy). Stream type string for the periodic kernel is stdperiodic.
Instrument the same matio suite with gcov and upload to Codecov (CIP-0004):
$ sudo apt-get install -y libmatio-dev lcov
$ make clean
$ make USE_MATIO=1 COVERAGE=1 matio-tests
$ make run-matio-tests
$ lcov --capture --directory . --output-file coverage.info
$ lcov --remove coverage.info '/usr/*' '*/test*.cpp' '*test*.cpp' --output-file coverage.info
$ lcov --list coverage.infocodecov.yml ignores test*.cpp so patch coverage tracks library changes, not unhit FAILURE: branches in the drivers.
The Coverage workflow builds with COVERAGE=1, collects coverage.info, and uploads via codecov/codecov-action@v7. Add a repository secret CODECOV_TOKEN from Codecov (same pattern as GPy) so uploads authenticate for the org.
One of the advantages of interfacing to the LAPACK and BLAS libraries is that they are often optimised for particular architectures.
The way the software operates is through the command line. Supervised GP regression uses ./gp. Classification / IVM uses ./ivm. Probabilistic Point Assimilation (variational EM classification) uses ./ppa (CIP-0023). MAP GP-LVM uses ./gplvm; Bayesian GP-LVM uses ./bgplvm. Multi-view MRD is the library class CMrd (make demo_mrd). Help:
$ ./gp -h
$ ./ivm -h
$ ./gplvm -h
$ ./bgplvm -hHelp for each command, for example:
$ ./gp learn -hAll the tutorial optimisations suggested take less than 1/2 hour to run on my less than 2GHz Pentium IV machine. The first oil example runs in a couple of minutes. Below I suggest using the highest verbosity options -v 3 in each of the examples so that you can track the iterations.
Preferred training data is dense CSV/TSV (last column = target y; preceding columns = X). The file extension selects the reader (.csv/.tsv/.txt, or legacy SVM-light .svml). Python examples that need third-party sets should use pods (GPy parity; see CIP-0022 / REQ-0011). Older .svml files remain supported.
For the maintained tutorial versions of these walks (GPy checklist mapping, DTCVAR sparse path, IVM / MAP GPLVM / Bayesian GPLVM / MRD), see docs/tutorials/.
Provided with the software, in the examples directory, is a one dimensional regression problem. Prefer sinc.csv (see also docs/tutorials/regression_1d.md); sinc.svml still works.
First we will learn the data using the following command,
$ ./gp -v 3 learn -# 100 examples/sinc.csv sinc.modelThe flag -v 3 sets the verbosity level to 3 (the highest level) which causes the iterations of the scaled conjugate gradient algorithm to be shown. The flag -# 100 is the optimiser budget (setMaxIters): for SCG (default) that is algorithm iterations; for -O lbfgs / quasinew it caps both reverse-communication steps and function evaluations (GPy-aligned). See docs/optimisers.md.
The software will load the data in sinc.csv (dense CSV: last column is the continuous target).
The learned model is saved in a file called sinc.model. This file has a plain text format to make it human readable. Once training is complete, the learned covariance function parameters of the model can be displayed using
$ ./gp display sinc.modelLoading model file.
... done.
Standard GP Model:
Optimiser: scg
Data Set Size: 40
Kernel Type:
Scales learnt: 0
X learnt: 0
Bias: 0.106658
Scale: 1
Gaussian Noise:
Bias on process 0: 0
Variance: 1e-06
compound kernel:
rbfinverseWidth: 0.198511
rbfvariance: 0.0751124
biasvariance: 1.6755e-05
whitevariance: 0.00204124Notice the fact that the covariance function is composed of an RBF kernel, also known as squared exponential kernel or Gaussian kernel; a bias kernel, which is just a constant, and a white noise kernel, which is a diagonal term. This is the default setting, it can be changed with flags to other covariance function types, see ./gp learn -h for details.
For your convenience a gnuplot file may generated to visualise the data. First run
$ ./gp gnuplot -r 400 examples/sinc.csv sinc.model sincThe sinc supplied as the last argument acts as a stub for gnuplot to create names from. Generated scripts use the Qt terminal by default (works with a stock Homebrew gnuplot). For example:
$ brew install gnuplot # provides qt, pngcairo, pdfcairo, and svg terminals
$ gnuplot sinc_plot.gpTo write a file for documentation (no interactive window), use GPLOT_OUT (terminal chosen from the extension) or the explicit GPLOT_PNG / GPLOT_PDF / GPLOT_SVG variables:
$ gnuplot -e "GPLOT_OUT='sinc.png'" sinc_plot.gp
$ gnuplot -e "GPLOT_OUT='sinc.pdf'" sinc_plot.gp
$ gnuplot -e "GPLOT_OUT='sinc.svg'" sinc_plot.gpThen you should obtain the plot shown below
Gaussian process applied to sinc data.
The other files created are sinc_error_bar_data.dat (x, ymin, ymax for the ±2σ band), sinc_line_data.dat (posterior mean), and sinc_scatter_data.dat (training data). Colours follow the GPy Tango palette.
You might also want to try a larger 1D set, examples/spgp1d.csv (.svml still works). Full GP:
$ ./gp -v 3 learn -# 100 examples/spgp1d.csv spgp1d.modelSparse variational (DTCVAR) with an inducing set — the maintained sparse tutorial path (prefer this over FITC; -A fitc / -A dtc also available):
$ ./gp -v 3 learn -# 100 -A dtcvar -a 20 examples/spgp1d.csv spgp1d_dtcvar.model
$ ./gp display spgp1d_dtcvar.model
$ ./gp gnuplot -r 400 examples/spgp1d.csv spgp1d_dtcvar.model spgp1d_dtcvarOptional inducing families (default points): --inducing whitenoise for stationary kernels when (K_{uu}) is lengthscale-ill-conditioned (CIP-001C); --inducing greens for 1-D Brownian / Matérn causal features (CIP-0029); --inducing weightspace for MLP / arc-cosine ridge windows in whitened weight space (CIP-0028 — finite (\Sigma) via -k mlp, angular limit via -k arccos --arccos-order 0). Window width: --window-width. Compounds: one of mlp/mlpard/arccos plus optional white; noise in (\beta). See docs/numerics.md (Sparse inducing families).
See docs/tutorials/sparse_regression_1d.md and optional make demo_sparse_dtcvar.
While MATLAB can be slow (and very expensive for non-academic users) it can still be a lot easier to code the visualisation routines by building on MATLAB's graphics facilities. To this end you can load in the results from the MATLAB/OCTAVE GPmat toolbox for further manipulation. You can download the toolbox from here. Once the relevant toolboxes (you need all the dependent toolboxes) are downloaded you can visualise the results in MATLAB using
>> [y, X] = svmlread('sinc.svml')
>> gpReadFromFile('sinc.model', X, y)
>>where we have used the SVML toolbox of Anton Schwaighofer to load in the data.
This page describes how to compile and gives some examples of use of the C++ Informative Vector Machine Software (IVM).
The software is written in C++ to try and get a degree of flexibility in the models that can be used without a serious performance hit.
The software is mainly written in C++ but relies for some functions on FORTRAN code by other authors and the LAPACK and BLAS libraries.
Use the contemporary build notes at the top of this README (make.linux /
make.osx, Homebrew on macOS, C++17). Then:
$ make ivmHistorical notes about gcc 3.2 / g77, Cygwin, and MSVC below describe older packaging; the cygwin/ and MSVC/ trees are not in the current checkout.
One of the advantages of interfacing to the LAPACK and BLAS libraries is that they are often optimised for particular architectures. The file make/legacy/make.atlas includes options for compiling the ATLAS optimised versions of lapack and blas that are available on a server I have access to. These options may vary for particular machines.
Historical Windows packaging notes (Cygwin LAPACK/BLAS; MSVC under MSVC/ivm) apply to older releases; those trees are not in the current checkout. See docs/build-and-ci.md.
The way the software operates is through the command line. The IVM executable is ./ivm (classification / null-category noise). Help:
$ ./ivm -hHelp for each command, for example:
$ ./ivm learn -hMaintained IVM tutorials: docs/tutorials/ivm_unitsquare.md, ivm_ard_clusters, ivm_semisupervised.
All the tutorial optimisations are suggested take less than 1/2 hour to run on my less than 2GHz Pentium IV machine. The first oil example runs in a couple of minutes. Below I suggest using the highest verbosity options -v 3 in each of the examples so that you can track the iterations.
Victor Cheng writes:
" ... I've tested your IVM C++ Gaussian Process tool (IVMCPP0p12 version). It is quite useful. However, the gnuplot function seems has a problem. Every time I type the command: "Ivm gnuplot traindata name.model", an error comes out as: "Unknown noise model!". When I test this function with IVMCPP0p11 IVM, its fine, but IVMCPP0p11 has another problem that it gives "out of memory" error in test mode! So I use two vesions simultaneously. "
Historical note (31/12/2007). Prefer the current ./ivm gnuplot path and the maintained tutorials under docs/tutorials/ if you hit issues; please open a GitHub issue with a reproducer.
The software loads in data in the SVM light format. Anton Schwaighofer has written a package which can write from MATLAB to the SVM light format.
In this section we present some simple examples. The results will be visualised using gnuplot (Qt terminal; Homebrew: brew install gnuplot).
Provided with the software, in the examples directory, are some simple two dimensional problems. We will first try classification with these examples.
The first example is data sampled from a Gaussian process with an RBF kernel function with inverse width of 10. The input data is sampled uniformly from the unit square. This data can be learnt with the following command.
$ ./ivm -v 3 learn -a 200 -k rbf examples/unitsquaregp.svml unitsquaregp.modelThe flag -v 3 sets the verbosity level to 3 (the highest level) which causes the iterations of the scaled conjugate gradient algorithm to be shown. The flag -a 200 sets the active set size. The kernel type is selected with the flag -k rbf.
The learned model is saved in a file called unitsquaregp.model. This file has a plain text format to make it human readable. Once training is complete, the learned kernel parameters of the model can be displayed using
$ ./ivm display unitsquaregp.modelLoading model file.
... done.
IVM Model:
Active Set Size: 200
Kernel Type:
compound kernel:
rbfinverseWidth: 12.1211
rbfvariance: 0.136772
biasvariance: 0.000229177
whitevariance: 0.0784375
Noise Type:
Probit noise:
Bias on process 0: 0.237516Notice the fact that the kernel is composed of an RBF kernel, also known as squared exponential kernel or Gaussian kernel; a bias kernel, which is just a constant, and a white noise kernel, which is a diagonal term. The bias kernel and the white kernel are automatically added to the rbf kernel. Other kernels may also be used, see ivm learn -h for details.
For this model the input data is two dimensional, you can therefore visualise the decision boundary using
$ ./ivm gnuplot examples/unitsquaregp.svml unitsquaregp.model unitsquaregpThe unitsquaregp supplied as the last argument acts as a stub for gnuplot to create names from. For an interactive plot, or a PNG for the docs:
$ gnuplot unitsquaregp_plot.gp
$ gnuplot -e "GPLOT_PNG='unitsquaregp_plot.png'" unitsquaregp_plot.gpand obtain the plot shown below
The decision boundary learnt for the data sampled from a Gaussian process classification. Note the active points (dark red) typically lie along the decision boundary.
Generated plot artefacts for this 2-D IVM example follow the stub name (for example unitsquaregp_*.dat); see the gnuplot script header for the exact list. Maintained walk-through: docs/tutorials/ivm_unitsquare.md.
Next we consider a simple ARD kernel. The toy data in this case is sampled from three Gaussian distributions. To separate the data only one input dimension is necessary. The command is run as follows,
$ ./ivm learn -a 100 -k rbf -i 1 examples/ard_gaussian_clusters.svml ard_gaussian_clusters.modelDisplaying the model it is clear that it has selected one of the input dimensions,
Loading model file.<br>
... done.<br>
IVM Model:<br>
Active Set Size: 100<br>
Kernel Type:<br>
compound kernel:<br>
rbfardinverseWidth: 0.12293<br>
rbfardvariance: 2.25369<br>
rbfardinputScale: 5.88538e-08<br>
rbfardinputScale: 0.935148<br>
biasvariance: 9.10663e-07<br>
whitevariance: 2.75252e-08<br>
Noise Type:<br>
Probit noise:<br>
Bias on process 0: 0.745098
Once again the results can be displayed as a two dimensional plot,
$ ./ivm gnuplot examples/ard_gaussian_clusters.svml ard_gaussian_clusters.model ard_gaussian_clustersThe IVM learnt with an ARD RBF kernel. One of the input directions has been recognised as not relevant.
The software also provides an implementation of the null category noise model described in Lawrence and Jordan.
The toy example given in the paper is reconstructed here. To run it type
$ ./ivm learn -a 100 -k rbf examples/semisupercrescent.svml semisupercrescent.modelThe result of learning is
Loading model file.
... done.
IVM Model:
Active Set Size: 100
Kernel Type:
compound kernel:
rbfinverseWidth: 0.0716589
rbfvariance: 2.58166
biasvariance: 2.03635e-05
whitevariance: 3.9588e-06
Noise Type:
Ncnm noise:
Bias on process 0: 0.237009
Missing label probability for -ve class: 0.9075
Missing label probability for +ve class: 0.9075and can be visualised using
$ ./ivm gnuplot examples/semisupercrescent.svml semisupercrescent.model semisupercrescentfollowed by
$ gnuplot semisupercrescent_plot.gp
$ gnuplot -e "GPLOT_PNG='semisupercrescent_plot.png'" semisupercrescent_plot.gpThe result of the visualisation being,
The result of semi-supervised learning on the crescent data. At the top is the result from the null category noise model. The bottom shows the result from training only on the labelled data only with the standard probit noise model. Purple squares are unlabelled data; dark-red markers are the active set.
Maintained walk-through: docs/tutorials/ivm_semisupervised.md.
MAP GP-LVM (./gplvm), Bayesian GP-LVM (./bgplvm), and MRD (CMrd / demo_mrd) share the same contemporary build as ./gp — see Status and Compiling above. Historical download links from the mid-2000s packaging are obsolete; use this repository.
These notes describe old tarball releases. They are not the current project version.
Fixed bug which meant that back constraint wasn't working due to failure to initialise lwork properly for dsysv.
Fixed bug in gplvm.cpp which meant dynamics wasn't working properly because initialization of dynamics model learning parameter wasn't set to zero.
Thanks to Gustav Henter for pointing out these problems.
Updated the GP-LVM class structure and file storage. Introduced the dynamics model of Wang et al. (initial port by William V. Baxter). Sparse FITC/DTC/variational paths later landed in CGp and Bayesian GP-LVM rather than in that stopgap tarball.
Version 0.101 (21 October 2005) added Visual Studio 7.1 support (William V. Baxter). Version 0.1 (July 2005) was the original release.
The software is written in C++ to try and get a degree of flexibility in the models that can be used without a serious performance hit. This was difficult to do in MATLAB as users who have tried version 1 (which was fast but inflexible) and version 2 (which was flexible but slow) of the MATLAB software will appreciate.
MAP ./gplvm remains a dense latent-variable path and is still aimed at
smaller data sets (on the order of a thousand points). Sparse variational
inducing approximations live in CGp (DTCVAR; see the sparse GP section
above) and in the Bayesian GP-LVM (./bgplvm, CIP-0017). Multi-view MRD
(CMrd / demo_mrd, CIP-0018) reuses that Bayesian inducing path.
The software is mainly written in C++ but relies for some functions on FORTRAN code by other authors and the LAPACK and BLAS libraries.
As well as the C++ code some utilities are supplied in MATLAB code for visualising the results.
Use the contemporary build notes at the top of this README (make.linux /
make.osx, Homebrew on macOS, C++17). Then:
$ make gplvm
$ make bgplvmHistorical notes about gcc 3.2 / g77 and make.ARCHITECTURE files below the
GP section still describe older packaging; prefer make.linux / make.osx.
One of the advantages of interfacing to the LAPACK and BLAS libraries
is that they are often optimised for particular architectures. The
file make/legacy/make.atlas includes options for compiling the ATLAS
optimised versions of lapack and blas that are available on a server I
have access to. These options may vary for particular machines.
Historical Windows packaging (Cygwin prebuilt LAPACK/BLAS; MSVC 7.1 /
CLAPACK under MSVC/gplvm) is described in older releases. Those trees are
not in the current checkout; Windows CI waits on a maintained make path
(docs/build-and-ci.md). Thanks to William V. Baxter
for the original MSVC port.
The way the software operates is through the command line. MAP GP-LVM
uses ./gplvm. Bayesian GP-LVM (CIP-0017) uses a separate binary
./bgplvm so MAP defaults stay unchanged. Manifold Relevance
Determination (CIP-0018) is the library class CMrd (shared
(q(\mathbf{X})) across views); try make demo_mrd && ./demo_mrd
(see docs/tutorials/mrd.md). Bayesian oil-100 CLI walk:
docs/tutorials/bgplvm_oil100.md. Help for the single-view CLI:
$ ./gplvm -h
$ ./bgplvm -hHelp for each command, for example:
$ ./gplvm learn -h
$ ./bgplvm learn -hAll the tutorial optimisations suggested take less than 1/2 hour to
run on my less than 2GHz Pentium IV machine. The first oil example
runs in a couple of minutes. Below I suggest using the highest
verbosity options -v 3 in each of the examples so that
you can track the iterations.
The software loads in data in the SVM light format. This is to provide compatibility with other Gaussian Process software. Anton Schwaighofer has written a package which can write from MATLAB to the SVM light format.
In the original NIPS paper the first example was the oil flow data (see this page for details) sub-sampled to 100 points. I use this data a lot for checking the algorithm is working so in some senses it is not an independent `proof' of the model.
Provided with the software, in the examples directory,
is a sub-sample of the oil data. The file is called
oilTrain100.svml.
First we will learn the data using the following command,
$ ./gplvm -v 3 learn -# 100 examples/oilTrain100.svml oil100.modelMaintained MAP walk-through: docs/tutorials/gplvm_oil100.md.
The same data with the Bayesian GP-LVM (q=2, M=10 inducing points):
$ make bgplvm
$ ./bgplvm -v 2 learn -x 2 -M 10 -# 100 -o oil100_bayes \
examples/oilTrain100.svml oil100_bayes.model
$ ./bgplvm display oil100_bayes.model
$ ./bgplvm gnuplot oil100_bayes.model oil100_bayes
$ gnuplot oil100_bayes_plot.gp
# or: gnuplot -e "GPLOT_OUT='oil100_bayes.png'" oil100_bayes_plot.gpDefault kernel is RBF-ARD (rbfard) so latent input scales can shut off unused
dimensions (GPy BayesianGPLVM default). Override with -k rbf for isotropic
RBF, or -k rbf -i true (same as ./gplvm). Psi statistics for ARD are on
CRbfardKern and covered by ./testPsi.
-o writes oil100_bayes_mu.dat and oil100_bayes_S.dat (variational
mean and diagonal variance of (q(\mathbf{X}))). gnuplot plots the
variational means (\boldsymbol{\mu}) (coloured by SVM-light labels when
present) over a predictive-variance background, same style as ./gplvm gnuplot.
For (q>2), choose the plane with -d i j (zero-based; default 0 1);
other latent dims are fixed at the mean of (\boldsymbol{\mu}) for the
variance map — typically the two largest ARD input scales.
Maintained Bayesian walk-through: docs/tutorials/bgplvm_oil100.md.
Multi-view MRD (CIP-0018) shares one (q(\mathbf{X})) and inducing set (Z)
across aligned views, each with its own RBF-ARD kernel. There is no dedicated
./mrd CLI yet; use the library demo:
$ make demo_mrd
$ ./demo_mrdSee docs/tutorials/mrd.md. GPy ELBO/scale fixtures for CI compare are still outstanding on REQ-000C.
The flag -v 3 sets the verbosity level to 3 (the
highest level) which causes the iterations of the scaled conjugate
gradient algorithm to be shown. The flag -# 100
is the optimiser budget (see docs/optimisers.md).
The software will load the data in
oilTrain100.svml. The labels are included in this file
but they are not used in the optimisation of the model. They
are for visualisation purposes only.
The learned model is saved in a file called
oil100.model. This file has a plain text format to make
it human readable. Once training is complete, the learned kernel
parameters of the model can be displayed using
$ ./gplvm display oil100.modelLoading model file.
... done.
GPLVM Model:
Data Set Size: 100
Kernel Type:
compound kernel:
rbfinverseWidth: 3.97209
rbfvariance: 0.337566
biasvariance: 0.0393251
whitevariance: 0.00267715Notice the fact that the kernel is composed of an RBF kernel, also
known as squared exponential kernel or Gaussian kernel; a bias kernel,
which is just a constant, and a white noise kernel, which is a
diagonal term. This is the default setting, it can be changed with
flags to other kernel types, see gplvm learn -h for
details.
For your convenience a gnuplot file may generated to
visualise the data. First run
$ ./gplvm gnuplot oil100.model oil100The oil100 supplied as the last argument acts as a
stub for gnuplot to create names from. Interactive Qt, or PNG for docs:
$ gnuplot oil100_plot.gp
$ gnuplot -e "GPLOT_PNG='oil100_plot.png'" oil100_plot.gpAnd obtain the plot shown below
Visualisation of 100 points of the oil flow data.
The other files created are
oil100_variance_matrix.dat, which produces the grayscale
map of the log precisions and oil100_latent_data1-3.dat
which are files containing the latent data positions associated with
each label.
Running the GPLVM for 1000 iterations on all 1000 points of the oil data leads to the visualisation below.
All 1000 points of the oil data projected into latent space. This visualisation takes overnight to optimise on a Pentinum IV.
While MATLAB can be horribly slow (and very expensive for non-academic users) it is still a lot easier (for me) to code the visualisation routines by building on MATLAB's graphics facilities. To this end a new release of the GPLVM code in MATLAB has been provided (vs 2.012 and above) which allows you to load the results of the learning from the C++ code into MATLAB for further manipulation. You can download the toolbox from here. Once the relevant toolboxes (you need the IVM toolbox and the toolboxes on which it depends: KERN, NOISE, etc.) are downloaded you can visualise the results in MATLAB using
>> gplvmResultsCpp('oil100.model', 'vector')
>>This will load the results and allow you to move around the latent space visualising (in the form of a line plotted from the vector) the nature of the data at each point.
One popular use of the GPLVM has been in learning of human motion styles (see Grochow et al.). Personally, I find this application very motivating as Motion Capture data is a rare example of high dimensional data about which humans have a strong intuition. If the model fails to model `natural motion' it is quite apparant to a human observer. Therefore, as a second example, we will look at data of this type. In particular we will consider a data sets containing a walking man and a further data set containing a horse. To run these demos you will also need a small MATLAB mocap toolkit.
To prepare a new bvh file for visualisation you need the MATLAB mocap toolkit and Anton Schwaighofer's SVM light MATLAB interface (you don't need the SVM light software itself).
>> [bvhStruct, channels, frameLength] = bvhReadFile('examples/Swagger.bvh');
>>This motion capture data was taken from Ohio State University's ACCAD centre.
The motion capture channels contain values for the offset of the root node at each frame. If we don't want to model this motion it can be removed at this stage. Setting the 1st, 3rd and 6th channels to zero removes X and Z position and the rotation in the Y plane.
>> channels(:, [1 3 6]) = zeros(size(channels, 1), 3);You can now play the data using the command
>> bvhPlayData(bvhStruct, channels, frameLength);Data in the bvh format consists of angles, this presents a problem when the angle passes through a discontinuity. For example in this data the 'lhumerus' and 'rhumerus' joints rotate through 180 degrees and the channel moves from -180 to +180. This arbitrary difference will seriously effect the results. The fix is to add or subtract 360 as appropriate. In the toolbox provided this is done automatically in the file bvhReadFile.m using the function channelsAngles. This works well for the files we use here, but may not be a sufficient solution for files with more rotation on the joints.
Then channels can be saved for modelling using Schwaighofer's SVM light interface. First we downsample so that things run quickly,
>> channels = channels(1:4:end, :);Then the data is saved as follows:
>> svmlwrite('examples/swagger.svml',channels)Before you save you might want to check you haven't messed
anything up by playing the data again! It makes sense to learn
the scale independently for each the channels (particularly since we
have set three of them to zero!), so we now use the gplvm code to
learn the data setting the flag -L true for learning of
scales.
$ ./gplvm -v 3 learn -L true examples/swagger.svml swagger.modelOnce learning is complete the results can be visualised in MATLAB using the command
>> mocapResultsCppBvh('swagger.model', 'examples/Swagger.bvh', 'bvh');Latent space for the Swagger data. Note the breaks in the sequence.
Note that there are breaks in the sequence. These reason for these breaks is as follows. The GPLVM maps from the latent space to the data space with a smooth mapping. This means that points that are nearby in latent space will be nearby in data space. However that does not imply the reverse, i.e. points that are nearby in data space will not necessarily be nearby in latent space. It implies that if points are far apart in data space they will be far apart in latent space which is a slightly different thing. This means that the model is not strongly penalised for breaking the sequence (even if a better solution can be found through not breaking the sequence).
For visualisation you often want points being nearby in data space to be nearby in latent space. For example, most of the recent spectral techniques (including kernel PCA, Isomap, and LLE) try and guarantee this. In recent unpublished work with Joaquin Quinonero Candela, we have shown that this can be achieved in the GPLVM using `back constraints'. We constrain the data in the latent space to be represented by a second reverse-mapping from the data space. For the walking man the show results you can test the back constraints with the command
$ ./gplvm -v 3 learn -L true -c rbf -g 0.0001 examples/swagger.svml swagger_back_constrained.modelThe back constraint here is a kernel mapping with an `RBF' kernel which is specified as having an inverse width of 1e-4.
The results can then be seen in MATLAB using
>> mocapResultsCppBvh('swagger_back_constrained.model', 'examples/Swagger.bvh', 'bvh');The repeated circular pattern is associated with the repeated walking paces in the data.
It conceptually straightforward to add MAP dynamics in the GP-LVM
latent space by placing a prior that relates the latent points
temporally. There are several ways one could envisage doing this. Wang et al
proposed introducing dynamics through the use of a Gaussian process
mapping across time points. William V. Baxter implemented this
modification to the code and kindly allowed me to make his
modifications available. In the base case adding dynamics associated
with a GP doesn't change things very much: the Gaussian process
mapping is too flexible and doesn't constrain the behaviour of the
model. To solve this problem Wang suggests using a particular prior on
the hyper parameters of the GP-LVM (see pg 58 of his Master's
thesis). This prior is unusual as it is improper, but it is not
the standard uninformative 1/x prior. The historical -dh (Wang
weighting) switch is commented out in the current gplvm CLI. An
alternative approach of scaling the portion of the likelihood associated
with the dynamics up by a factor uses -ds. Prefer -dr (below) for
most runs.
My own preference is to avoid either of these approaches. A key
motivation of the GP-LVM as a probabilistic model was to design an
approach that avoided difficult to justify scalings and unusual
priors. The basic problem is that if the hyper parameters are
optimised the Gaussian process is too flexible a model for application
modelling the dynamics. However it is also true that a non-linear
model is needed. As an alternative approach we suggest fixing the
hyper parameters. The level of noise can be fixed by suggesting a
signal to noise ratio. This approach has also been implemented in the
code using the -dr flag (-ds scales the dynamics likelihood;
-dh is historical and not exposed in the current CLI help).
Motion-capture MATLAB helpers remain deferred relative to the native
CLI tutorials (see CIP-0015 non-goals / Swagger notes in
docs/tutorials/).
$ ./gplvm -v 3 learn -L true -D rbf -g 0.01 -dr 20 examples/swagger.svml swagger_dynamics.modelHere -D rbf selects the dynamics kernel, -g sets its inverse width, and
-dr 20 fixes a signal-to-noise ratio for the dynamics GP (preferable to
-dh / -ds for most runs). The results of the visualisation are shown below.
Latent space for the Swagger data with the dynamics. By constraining the GP-LVM with an unusual prior the sequence stays continuous in latent space.
This result can also be loaded into MATLAB and played using the command
>> mocapResultsCppBvh('swagger_dynamics.model', 'examples/Swagger.bvh', 'bvh');It is possible to use GPc in Matlab using a mex-file, combining the speed of C++ and comfort of Matlab.
The folder mex contains an example of a mex-file mirroring the functionality
of the gp binary. It offers choices for (re)training, querying and clearing
the model. Scripts for compiling and testing the mex-file are provided as well.
For general information on usage and available commands, type just fGP in your
Matlab command window. For information on usage of a particular command, type
fGP('command').
There are several issues which might need a special attention:
-
when getting errors about symbols defined in discarded section, it surprisingly might help to remove the Matlab interface (comment the Matlab-related lines in your makefile.platform out);
-
when getting segmentation faults in calls to BLAS/LAPACK libraries, it might help to compile the mex-file against MKL library instead (use -lmkl_rt instead of -lblas -llapack) and/or preload the libmkl_rt.so library file.









