Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named mean and variance #1567

Open
joelberkeley-secondmind opened this issue Sep 16, 2020 · 2 comments
Open

Named mean and variance #1567

joelberkeley-secondmind opened this issue Sep 16, 2020 · 2 comments

Comments

@joelberkeley-secondmind
Copy link
Contributor

joelberkeley-secondmind commented Sep 16, 2020

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

@antonykamp
Copy link

Hey,
If this is still a requested feature, I would be really happy to work on it too :)

@st--
Copy link
Member

st-- commented Mar 26, 2021

Yes, that'd be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants