gpflow.monitor

Provides basic functionality to monitor optimisation runs

gpflow.monitor.ExecuteCallback

class gpflow.monitor.ExecuteCallback(callback)[source]

Bases: gpflow.monitor.base.MonitorTask

Executes a callback as task

Methods

__call__(step, **kwargs)

It calls the 'run' function and sets the current step.

run(**kwargs)

Implements the task to be executed on __call__.

Parameters

callback (Callable[..., None]) –

run(**kwargs)[source]

Implements the task to be executed on __call__. The current step is available through self.current_step.

Parameters

kwargs (Any) – keyword arguments available to the run method.

Return type

None

gpflow.monitor.ImageToTensorBoard

class gpflow.monitor.ImageToTensorBoard(log_dir, plotting_function, name=None, *, fig_kw=None, subplots_kw=None)[source]

Bases: gpflow.monitor.tensorboard.ToTensorBoard

Methods

__call__(step, **kwargs)

It calls the 'run' function and sets the current step.

run(**unused_kwargs)

Implements the task to be executed on __call__.

run(**unused_kwargs)[source]

Implements the task to be executed on __call__. The current step is available through self.current_step.

Parameters

kwargs – keyword arguments available to the run method.

Parameters

unused_kwargs (Any) –

Return type

None

gpflow.monitor.ModelToTensorBoard

class gpflow.monitor.ModelToTensorBoard(log_dir, model, *, max_size=3, keywords_to_monitor=['kernel', 'likelihood'], left_strip_character='.')[source]

Bases: gpflow.monitor.tensorboard.ToTensorBoard

Monitoring task that creates a sensible TensorBoard for a model.

Monitors all the model’s parameters for which their name matches with keywords_to_monitor. By default, “kernel” and “likelihood” are elements of keywords_to_monitor. Example:

keyword = “kernel”, parameter = “kernel.lengthscale” => match keyword = “variational”, parameter = “kernel.lengthscale” => no match

Methods

__call__(step, **kwargs)

It calls the 'run' function and sets the current step.

run(**unused_kwargs)

Implements the task to be executed on __call__.

Parameters
  • log_dir (str) –

  • model (BayesianModel) –

  • max_size (int) –

  • keywords_to_monitor (List[str]) –

  • left_strip_character (str) –

run(**unused_kwargs)[source]

Implements the task to be executed on __call__. The current step is available through self.current_step.

Parameters

kwargs – keyword arguments available to the run method.

Parameters

unused_kwargs (Any) –

Return type

None

gpflow.monitor.Monitor

class gpflow.monitor.Monitor(*task_groups)[source]

Bases: object

Accepts any number of of MonitorTaskGroup instances, and runs them according to their specified periodicity.

Example use-case:

``` # Create some monitor tasks log_dir = “logs” model_task = ModelToTensorBoard(log_dir, model) image_task = ImageToTensorBoard(log_dir, plot_prediction, “image_samples”) lml_task = ScalarToTensorBoard(log_dir, lambda: model.log_marginal_likelihood(), “lml”)

# Plotting tasks can be quite slow, so we want to run them less frequently. # We group them in a MonitorTaskGroup and set the period to 5. slow_tasks = MonitorTaskGroup(image_task, period=5)

# The other tasks are fast. We run them at each iteration of the optimisation. fast_tasks = MonitorTaskGroup([model_task, lml_task], period=1)

# We pass both groups to the Monitor monitor = Monitor(fast_tasks, slow_tasks) ```

Methods

__call__(step, **kwargs)

Call self as a function.

Parameters

task_groups (MonitorTaskGroup) –

gpflow.monitor.MonitorTask

class gpflow.monitor.MonitorTask[source]

Bases: abc.ABC

A base class for a monitoring task.

All monitoring tasks are callable objects. A descendant class must implement the run method, which is the body of the monitoring task.

Methods

__call__(step, **kwargs)

It calls the 'run' function and sets the current step.

run(**kwargs)

Implements the task to be executed on __call__.

abstract run(**kwargs)[source]

Implements the task to be executed on __call__. The current step is available through self.current_step.

Parameters

kwargs (Any) – keyword arguments available to the run method.

Return type

None

gpflow.monitor.MonitorTaskGroup

class gpflow.monitor.MonitorTaskGroup(task_or_tasks, period=1)[source]

Bases: object

Class for grouping MonitorTask instances. A group defines all the tasks that are run at the same frequency, given by period.

A MonitorTaskGroup can exist of a single instance or a list of MonitorTask instances.

Attributes
tasks

Methods

__call__(step, **kwargs)

Call each task in the group.

Parameters

gpflow.monitor.ScalarToTensorBoard

class gpflow.monitor.ScalarToTensorBoard(log_dir, callback, name)[source]

Bases: gpflow.monitor.tensorboard.ToTensorBoard

Stores the return value of a callback in a TensorBoard.

Methods

__call__(step, **kwargs)

It calls the 'run' function and sets the current step.

run(**kwargs)

Implements the task to be executed on __call__.

Parameters
  • log_dir (str) –

  • callback (Callable[[], float]) –

  • name (str) –

run(**kwargs)[source]

Implements the task to be executed on __call__. The current step is available through self.current_step.

Parameters

kwargs (Any) – keyword arguments available to the run method.

Return type

None

gpflow.monitor.ToTensorBoard

class gpflow.monitor.ToTensorBoard(log_dir)[source]

Bases: gpflow.monitor.base.MonitorTask

Methods

__call__(step, **kwargs)

It calls the 'run' function and sets the current step.

run(**kwargs)

Implements the task to be executed on __call__.

Parameters

log_dir (str) –