Description Usage Details Documentation Examples
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.
1 |
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:
data - GPflow expects vectors to be *column* vectors. Vectors
should there be converted to one-column matrices before being passed to
most functions. E.g. using matrix()
, as in the example below.
integers - Python (and therefore GPflow) is more stringent about
integers than R is. For example, when specifying the number of active
dimensions of a kernel, you should make sure the number passed is of type
integer, not numeric. In most cases that just means adding an 'L
',
i.e. switching 1
to 1L
etc.
If you want to tidy up your code, you can rename gpflow
by assigning
it to a new object (e.g. gp <- gpflow
).
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.
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)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.