gpflow: GPflow Python Module

Description Usage Details Documentation Examples

Description

gpflow is the imported GPflow python module. You can access the various methods via the $ operator. For example, to access the submodule of kernel constructor functions type gpflow$kernels.

gpflow_available() tests whether the GPflow module is installed and available to the version of Python being used by reticulate.

Usage

1

Details

reticulate converts R objects to python objects on the fly. It won't always guess how to do that correctly though, so here are a few gotchas to look out for:

If you want to tidy up your code, you can rename gpflow by assigning it to a new object (e.g. gp <- gpflow).

Documentation

The submodules and methods in gpflow are not documented in this package. You can access the python docs at http://gpflow.readthedocs.io/en/latest/.

If you're using a recent version of the Rstudio editor, you can also get inline help and autocompletion by hitting the tab key.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if (gpflow_available()) {

  # translation of the simple GP regression example from GPflow:
  # http://gpflow.readthedocs.io/en/latest/notebooks/regression.html
  
  # fake data
  N <- 12
  X <- matrix(runif(N))
  Y = sin(12 * X) + 0.66 * cos(25 * X) + matrix(rnorm(N)) * 0.1 + 3
  plot(X, Y)
  
  # set up kernel and GP
  k <- gpflow$kernels$Matern52(1L, lengthscales = 0.3)
  m <- gpflow$gpr$GPR(X, Y, kern=k)
  
  # adjust the likelihood
  m$likelihood$variance = 0.01
  
  # predict and plot
  xx <- matrix(seq(-0.1, 1.1, len = 100))
  tmp <- m$predict_y(xx)
  mean <- tmp[[1]]
  lines(mean ~ xx)
 
}

goldingn/gpflowr documentation built on May 17, 2019, 7:41 a.m.