Skip to content

Conversation

williambdean
Copy link
Contributor

@williambdean williambdean commented Sep 25, 2022

What is this PR about?
Addressing the issue raised: #6094

Helps migrates toward standardized API for noise in GPs. Changes the noise parameter to sigma where applicable. A FutureWarning is used if noise parameter is still used in the previous locations.

Checklist

Major / Breaking Changes

  • NA

Bugfixes / New features

  • Standardize the gp API

Docs / Maintenance

  • GP docstring examples all work and use sigma parameter instead of noise
  • Small changes to the Latent GP docs that mistakenly reference the noise

@williambdean
Copy link
Contributor Author

williambdean commented Sep 25, 2022

Previous tests work on my end with the expect warnings. Working through specific tests soon for warnings

@codecov
Copy link

codecov bot commented Sep 25, 2022

Codecov Report

Merging #6145 (318e345) into main (1417785) will increase coverage by 1.09%.
The diff coverage is 98.80%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6145      +/-   ##
==========================================
+ Coverage   91.93%   93.02%   +1.09%     
==========================================
  Files         101       91      -10     
  Lines       20948    20752     -196     
==========================================
+ Hits        19258    19305      +47     
+ Misses       1690     1447     -243     
Impacted Files Coverage Δ
pymc/aesaraf.py 93.38% <ø> (ø)
pymc/distributions/transforms.py 100.00% <ø> (ø)
pymc/model.py 88.23% <ø> (ø)
pymc/gp/gp.py 93.82% <96.55%> (+0.62%) ⬆️
pymc/distributions/continuous.py 97.50% <100.00%> (ø)
pymc/distributions/multivariate.py 92.31% <100.00%> (ø)
pymc/smc/smc.py 97.24% <100.00%> (ø)
pymc/tests/gp/test_gp.py 100.00% <100.00%> (ø)
pymc/variational/updates.py 92.11% <100.00%> (ø)
pymc/parallel_sampling.py 85.80% <0.00%> (-1.00%) ⬇️
... and 12 more

@williambdean williambdean marked this pull request as ready for review September 25, 2022 22:38
@williambdean
Copy link
Contributor Author

williambdean commented Sep 25, 2022

The implementation should be at the point initially described. Namely,

  • switch logic and docs to use sigma parameter
  • allow for noise parameter until more formally deprecated. Have a warning to indicate

Think the tests are in a fine place as well. Was thinking of having one to compare the model parameters with the noise vs sigma parameterization but might be overkill way to test handling the parameters. Could just test function if desired.
Also, put the tests into a separate spot so they can be removed at some point.

Noticed a failing test on one of the windows runs from before. Don't know too much about that at the moment. It doesn't seem related to the changes I've made at first glance. Not sure if anyone has thoughts here.

@bwengals
Copy link
Contributor

Thanks for the contribution! I think from a user standpoint, it makes sense to have all functions take sigma.

For some background, the previous reason why one GP implementation was noise and the other was sigma was because in gp.Marginal you can pass in any covariance function for the noise, white $\sigma^2 \mathbf{I}$ or otherwise. But gp.MarginalApprox only handles white noise, so it's input was specifically $\sigma$ and not noise more generally.

That said, while it makes sense to have more simplicity for users to input sigma (and say the type can be an arbitrary covariance matrix) it is somewhat incorrect to have things like Knx = sigma(X) in the code, since one would reasonably assume sigma was a scalar and not an arbitrary covariance function. What about changing the name to noise_func (or similar) to go with cov_func internally?

@danhphan
Copy link
Member

Hi @wd60622 Thank you for the PR, and thanks @bwengals for the comments.

I will have a look in more details at this on tomorrow afternoon. Also, sorry for my late response!

@williambdean
Copy link
Contributor Author

Great. Thank you both for taking a look.
I like your suggestions @bwengals. Agree with the noise_func internal. Good suggestion for clarity.

I will make the adjustments a bit later today

@williambdean
Copy link
Contributor Author

@bwengals Changes implemented. Went with noise_func alternative. I like that suggestion and added wherever the previous sigma was being called. That transformed noise_func is still being saved in the sigma attribute as that is the argument and the name in the decorator. Tried to stay as true to the previous logic as possible. But feels a little weird to me as it is transformed. Let me know if you have any other comments on this implementation.

@bwengals
Copy link
Contributor

This looks great! For the decorator, for using .conditional with given, the user still specifies it as sigma right? I think as long as the user doesn't see or interact with noise_func it works well.

@williambdean
Copy link
Contributor Author

This looks great! For the decorator, for using .conditional with given, the user still specifies it as sigma right? I think as long as the user doesn't see or interact with noise_func it works well.

Yup, correct. Still sigma being passed / is the main attribute being used so the decorator is appropriate.
Just my thought there is that sigma will be transformed into Covariance (WhiteNoise) instance and being passed around under the name noise_func even though it is stored in self.sigma.
But a user could pass an instance of that class in the first place so I guess it is not that weird to do. Bit thinking out loud here 😄

Just waiting on these tests and will decode any fails when they are done. They have been successful in my the local checks.

Copy link
Member

@danhphan danhphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks @wd60622

Look good to me. I just add a couple of small comments for clarification.

Comment on lines +50 to +51
if (sigma is None and noise is None) or (sigma is not None and noise is not None):
raise ValueError("'sigma' argument must be specified.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, just want to understand the logic: If sigma is not None and noise is not None, should we raise this error, as we already specified sigma in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, the logic here could be:

if `sigma is not None`: good
else:
      if `noise is not None`: raise warning
      else: raise error.

OR

if `sigma is None`:
   if `noise is None`: raise error
   else: raise warning

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If both sigma and noise are specified, it is not really wrong, right? :) The user just provides more inputs than what is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hear what you are staying but thought it might be fine to nudge them toward the new input. Not likely for both to be used, but thought being explicit about the intended behavior would be best instead of throwing away or checking the two parameters silently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user passes in sigma=0.1 and noise=0.2, it's not really possible from the outside to know which value is going to be used in the model. The user must be a bit confused then, and an error message would help them out. Both your alternatives for doing the logic make sense to me too though @danhphan, but I think it also makes sense how it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well said @bwengals That's what I had in mind.
Was trying to make it easier from the developer's point of view

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks @wd60622 and @bwengals for the clarification. Total agree with "nudge users toward the new sigma" :)

Function input values.
given: dict
Can optionally take as key value pairs: `X`, `y`, `noise`,
Can optionally take as key value pairs: `X`, `y`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to replace noise by sigma here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for the latent class that doesn't use noise. I believe this was a mistake to begin with. Let me know if I am wrong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @wd60622 you are right! thanks to you both for catching this I didn't notice it....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for pointing it out :)

Copy link
Member

@danhphan danhphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks @wd60622 for the contribution!

Copy link
Contributor

@bwengals bwengals left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@canyon289 canyon289 merged commit e07eea7 into pymc-devs:main Sep 29, 2022
@williambdean williambdean deleted the gp_sigma_parameterize_6094 branch September 29, 2022 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants