gpflow.functions

Throughout GPflow, by default, latent functions being modelled with Gaussian processes are assumed to have zero mean, f ~ GP(0, k(x,x’)).

In some cases we may wish to model only the deviation from a fixed function with a Gaussian process. For flexibility this fixed function could be both input dependent and parameterised function, μ(x; θ), with some unknown parameters θ, resulting in f ~ GP(μ(x;θ), k(x,x’)).

The GPflow MeanFunction class allows this to be done whilst additionally learning parameters of the parametric function.

Classes

gpflow.functions.Additive

class gpflow.functions.Additive(first_part, second_part)[source]

Bases: MeanFunction, Function

Parameters:

gpflow.functions.Constant

class gpflow.functions.Constant(c=None)[source]

Bases: MeanFunction, Function

Parameters:

c (Union[ndarray[Any, Any], Tensor, Variable, Parameter])

gpflow.functions.Function

class gpflow.functions.Function(name=None)[source]

Bases: Module

The base function class. To implement a function, write the __call__ method. This takes a tensor X and returns a tensor f(X). In accordance with the GPflow standard, each row of X represents one datum, and each row of f(X) is computed independently for each row of X.

This class is not only used for mean functions. For example, the variance of a heteroskedastic model can be specified using a Function.

Function classes can have parameters, see the Linear class for an example.

gpflow.functions.Identity

class gpflow.functions.Identity(input_dim=None)[source]

Bases: Linear, Function

y_i = x_i

Parameters:

input_dim (Optional[int])

gpflow.functions.Linear

class gpflow.functions.Linear(A=None, b=None)[source]

Bases: MeanFunction, Function

y_i = A x_i + b

Parameters:
  • A (Union[ndarray[Any, Any], Tensor, Variable, Parameter])

  • b (Union[ndarray[Any, Any], Tensor, Variable, Parameter])

gpflow.functions.MeanFunction

class gpflow.functions.MeanFunction(name=None)[source]

Bases: Function

Mixin for Functions that are appropriate for use as mean functions.

gpflow.functions.Polynomial

class gpflow.functions.Polynomial(degree, input_dim=1, output_dim=1, w=None)[source]

Bases: MeanFunction, Function

A generic polynomial mean function.

Parameters:
  • degree (int)

  • input_dim (int)

  • output_dim (int)

  • w (Union[ndarray[Any, Any], Tensor, Variable, Parameter, None])

static compute_powers(degree, input_dim)[source]

Computes integer tuples corresponding to the powers to raise inputs to.

Specifically this returns, in lexicographical order, all tuples where:

  • The tuple has length input_dim.

  • The values are non-negative integers.

  • The sum of the tuple is no greater than degree.

For example:

compute_powers(degree=2, input_dim=3)

returns:

(0, 0, 0)
(0, 0, 1)
(0, 0, 2)
(0, 1, 0)
(0, 1, 1)
(0, 2, 0)
(1, 0, 0)
(1, 0, 1)
(1, 1, 0)
(2, 0, 0)

where a tuple:

(1, 0, 2)

will translate to a the term:

w[i] * (x[0]**1) * (x[1]**0) * (x[2]**2)
Parameters:
  • degree (int)

  • input_dim (int)

Return type:

Sequence[Tuple[int, ...]]

gpflow.functions.Product

class gpflow.functions.Product(first_part, second_part)[source]

Bases: MeanFunction, Function

Parameters:

gpflow.functions.SwitchedFunction

class gpflow.functions.SwitchedFunction(function_list)[source]

Bases: MeanFunction, Function

This class enables to use different (independent) functions respective to the data ‘label’. We assume the ‘label’ is stored in the extra column of X.

Parameters:

function_list (Collection[Function])

gpflow.functions.SwitchedMeanFunction

class gpflow.functions.SwitchedMeanFunction(meanfunction_list)[source]

Bases: SwitchedFunction

Renamed SwitchedFunction for backwards compatibility.

Parameters:

meanfunction_list (Collection[MeanFunction])

gpflow.functions.Zero

class gpflow.functions.Zero(output_dim=1)[source]

Bases: Constant, Function

Parameters:

output_dim (int)