Skip to content

Named mean and variance #1567

@joelberkeley-secondmind

Description

Feature request

It might be really nice to have the mean and variance returned by GPModel.predict_f and GPModel.predict_y to be typing.NamedTuples.

Motivation

This has two advantages. The main one is being able to calculate and use the mean or variance straightforwardly in one line, and in a clear, safe manner. Rather than

mean, _ = model.predict_f(...)
foo(mean)

which is a little verbose, or

foo(model.predict_f(...)[0])

which is prone to error and hard to read, you can do

foo(model.predict_f(...).mean)

The other advantage is that it's a little safer. Using res.mean is more explicit and less prone to error than res[0] or mean, _ = res.

Proposal

MeanAndVariance becomes a typing.NamedTuple like

class MeanAndVariance(NamedTuple):
    mean: tf.Tensor
    variance: tf.Tensor

Since NamedTuple is a typed version of namedtuple, which returns a subclass of tuple, I'm pretty sure this change is backwards compatible. Tests can be added to verify this

What alternatives have you considered?

None

Are you willing to open a pull request? (We really appreciate contributions!)

Maybe, not just now though

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions