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

add docs for interpretation of length scales in periodic kernel #3989

Merged
merged 4 commits into from
Jul 17, 2020

Conversation

tirthasheshpatel
Copy link
Contributor

Fixes #3987.

I have added a versionchanged just so that the documentation warns the user when the next version is released. Changed the tests accordingly.

cc @bwengals

Copy link
Contributor

@AlexAndorra AlexAndorra left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @tirthasheshpatel ! I'll wait for @bwengals's approval and merge after that 😉

@AlexAndorra AlexAndorra requested a review from bwengals July 1, 2020 14:28
@bwengals
Copy link
Contributor

bwengals commented Jul 1, 2020

I think we ought to consider that this may make peoples past models / inference results wrong, and introduce bugs on the users end, especially since informative priors on lengthscales are a good idea, folks might have an informative prior on ell that would need to be re-scaled. I think here it's not so much a bug, as not using the most common convention. No users code is wrong or broken right now that uses Periodic (at least not because of this!).

So if someone does rerun their model, or are using a prefitted model in production, their new results after this change will have a very subtle bug now, that will be very tough on their end to figure out. I don't think we want this outcome.

Either way, we absolutely need to change the docs / docstring to be correct. But I'm not 100% sure on changing that factor at this point (even if it would have been better from the start).

Thoughts?

@AlexAndorra
Copy link
Contributor

Thanks for the detailed answer @bwengals. I agree with this and I think we have two options:

1. Status-quo: do nothing and not use the standard Periodic kernel formula. This way, there is no backwards issues but it might be confusing to new users: they think we're using the common kernel, set their priors and lenghtscale according to this parametrization and it turns out they should have scaled their priors otherwise (in short, the inverse problem of what you laid out).

2. Changing to the common kernel, with the issues you laid out. I tend to favor this option as it enforces good practices going forward (if I understood correctly what you were saying on the Discourse), which is something we want. From a "rolling out" perspective, this doesn't seem that challenging to me: it's basically akin to a bug whose fixes imply some backwards incompatibility -- but we have experience on how to do that.
If we take this road, maybe we should condition this fix for versions >= 3.9.5 and display a DeprecationWarning during 3.9.3 and 3.9.4.

How does it sound?

@tirthasheshpatel tirthasheshpatel changed the title BUG: fix the expression of periodic kernel fix the expression of periodic kernel Jul 2, 2020
@tirthasheshpatel
Copy link
Contributor Author

Agreed with both of you! What do say about a DeprecationWarning @bwengals. I am cool with keeping it as is or just adding a DeprecationWarning

@junpenglao
Copy link
Member

To me it is a breaking change with little gain. I think we should keep it as is and clarify in the comment of the differences in scaling compare to standard/other definitions.

@tirthasheshpatel
Copy link
Contributor Author

Yeah, I will add a docstring stating the difference between the two conventions.

@bwengals
Copy link
Contributor

bwengals commented Jul 6, 2020

Ya agree with @junpenglao, best to just fix the docs so it's clear

@AlexAndorra
Copy link
Contributor

Ok, so let's go with that @tirthasheshpatel ! I think you can do that directly in this PR 😉

@tirthasheshpatel
Copy link
Contributor Author

Sorry for the late response. Added the docs!

@tirthasheshpatel tirthasheshpatel changed the title fix the expression of periodic kernel add docs for interpretation of length scales in periodic kernel Jul 7, 2020
pymc3/gp/cov.py Outdated
Comment on lines 357 to 359
The interpretation of length-scale for this kernel is different than the
one used normally (see [1]_). Priors on length scale must be put keeping
this in mind.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The interpretation of length-scale for this kernel is different than the
one used normally (see [1]_). Priors on length scale must be put keeping
this in mind.
The scaling factor for this kernel is different compare to the other standard
definition (see [1]_), thus change the interpretation of length-scale in a subtle
way. Please keep that in mind when you are defining priors on length scale,
especially when you are trying to replicate other results.
You can divided the length-scale by 2 in the kernel initialization to recover the
standard definition.

@bwengals is this correct?

Copy link
Contributor

@bwengals bwengals Jul 9, 2020

Choose a reason for hiding this comment

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

If I read that it's different, how should one interpret it? I think it'd be good to be specific.

Also small wording suggestion, how does this sound?

Note that the scaling factor for this kernel is different compared to the more common definition (see [1]_). Here, 0.5 is in the exponent instead of the more common value, 4. Divide the length-scale by 2 when initializing the kernel to recover the standard definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for not replying earlier. I missed @bwengals's reply.

Here, 0.5 is in the exponent instead of the more common value, 4.

I think what you meant here was:

Here, 0.5 is in the exponent instead of the more common value, 2.

Right?

Copy link
Contributor

Choose a reason for hiding this comment

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

whoops, yep you're right!

@codecov
Copy link

codecov bot commented Jul 13, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@0790115). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #3989   +/-   ##
=========================================
  Coverage          ?   86.47%           
=========================================
  Files             ?       88           
  Lines             ?    14090           
  Branches          ?        0           
=========================================
  Hits              ?    12185           
  Misses            ?     1905           
  Partials          ?        0           
Impacted Files Coverage Δ
pymc3/gp/cov.py 97.96% <ø> (ø)
pymc3/step_methods/__init__.py 100.00% <0.00%> (ø)
pymc3/__init__.py 95.23% <0.00%> (ø)
pymc3/distributions/discrete.py 74.65% <0.00%> (ø)
pymc3/distributions/multivariate.py 78.13% <0.00%> (ø)
pymc3/parallel_sampling.py 88.36% <0.00%> (ø)
pymc3/backends/__init__.py 100.00% <0.00%> (ø)
pymc3/gp/gp.py 92.82% <0.00%> (ø)
pymc3/ode/utils.py 100.00% <0.00%> (ø)
pymc3/model_graph.py 88.48% <0.00%> (ø)
... and 79 more

@bwengals
Copy link
Contributor

good to merge?

Copy link
Contributor

@AlexAndorra AlexAndorra left a comment

Choose a reason for hiding this comment

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

Yep, all good now, thanks @tirthasheshpatel and @bwengals !

@AlexAndorra AlexAndorra merged commit 28a4621 into pymc-devs:master Jul 17, 2020
@tirthasheshpatel tirthasheshpatel deleted the fix-per branch July 17, 2020 16:01
gmingas added a commit to alan-turing-institute/pymc3 that referenced this pull request Jul 22, 2020
* Update GP NBs to use standard notebook style (pymc-devs#3978)

* update gp-latent nb to use arviz

* rerun, run black

* rerun after fixes from comments

* rerun black

* rewrite radon notebook using ArviZ and xarray (pymc-devs#3963)

* rewrite radon notebook using ArviZ and xarray

Roughly half notebook has been updated

* add comments on xarray usage

* rewrite 2n half of notebook

* minor fix

* rerun notebook and minor changes

* rerun notebook on pymc3.9.2 and ArviZ 0.9.0

* remove unused import

* add change to release notes

* SMC: refactor, speed-up and run multiple chains in parallel for diagnostics (pymc-devs#3981)

* first attempt to vectorize smc kernel

* add ess, remove multiprocessing

* run multiple chains

* remove unused imports

* add more info to report

* minor fix

* test log

* fix type_num error

* remove unused imports update BF notebook

* update notebook with diagnostics

* update notebooks

* update notebook

* update notebook

* Honor discard_tuned_samples during KeyboardInterrupt (pymc-devs#3785)

* Honor discard_tuned_samples during KeyboardInterrupt

* Do not compute convergence checks without samples

* Add time values as sampler stats for NUTS (pymc-devs#3986)

* Add time values as sampler stats for NUTS

* Use float time counters for nuts stats

* Add timing sampler stats to release notes

* Improve doc of time related sampler stats

Co-authored-by: Alexandre ANDORRA <[email protected]>

Co-authored-by: Alexandre ANDORRA <[email protected]>

* Drop support for py3.6 (pymc-devs#3992)

* Drop support for py3.6

* Update RELEASE-NOTES.md

Co-authored-by: Colin <[email protected]>

Co-authored-by: Colin <[email protected]>

* Fix Mixture distribution mode computation and logp dimensions

Closes pymc-devs#3994.

* Add more info to divergence warnings (pymc-devs#3990)

* Add more info to divergence warnings

* Add dataclasses as requirement for py3.6

* Fix tests for extra divergence info

* Remove py3.6 requirements

* follow-up of py36 drop (pymc-devs#3998)

* Revert "Drop support for py3.6 (pymc-devs#3992)"

This reverts commit 1bf867e.

* Update README.rst

* Update setup.py

* Update requirements.txt

* Update requirements.txt

Co-authored-by: Adrian Seyboldt <[email protected]>

* Show pickling issues in notebook on windows (pymc-devs#3991)

* Merge close remote connection

* Manually pickle step method in multiprocess sampling

* Fix tests for extra divergence info

* Add test for remote process crash

* Better formatting in test_parallel_sampling

Co-authored-by: Junpeng Lao <[email protected]>

* Use mp_ctx forkserver on MacOS

* Add test for pickle with dill

Co-authored-by: Junpeng Lao <[email protected]>

* Fix keep_size for arviz structures. (pymc-devs#4006)

* Fix posterior pred. sampling keep_size w/ arviz input.

Previously posterior predictive sampling functions did not properly
handle the `keep_size` keyword argument when getting an xarray Dataset
as parameter.

Also extended these functions to accept InferenceData object as input.

* Reformatting.

* Check type errors.

Make errors consistent across sample_posterior_predictive and fast_sample_posterior_predictive, and add 2 tests.

* Add changelog entry.

Co-authored-by: Robert P. Goldman <[email protected]>

* SMC-ABC add distance, refactor and update notebook (pymc-devs#3996)

* update notebook

* move dist functions out of simulator class

* fix docstring

* add warning and test for automatic selection of sort sum_stat when using wassertein and energy distances

* update release notes

* fix typo

* add sim_data test

* update and add tests

* update and add tests

* add docs for interpretation of length scales in periodic kernel (pymc-devs#3989)

* fix the expression of periodic kernel

* revert change and add doc

* FIXUP: add suggested doc string

* FIXUP: revertchanges in .gitignore

* Fix Matplotlib type error for tests (pymc-devs#4023)

* Fix for issue 4022.

Check for support for `warn` argument in `matplotlib.use()` call. Drop it if it causes an error.

* Alternative fix.

* Switch from pm.DensityDist to pm.Potential to describe the likelihood in MLDA notebooks and script examples. This is done because of the bug described in arviz-devs/arviz#1279. The commit also changes a few parameters in the MLDA .py example to match the ones in the equivalent notebook.

* Remove Dirichlet distribution type restrictions (pymc-devs#4000)

* Remove Dirichlet distribution type restrictions

Closes pymc-devs#3999.

* Add missing Dirichlet shape parameters to tests

* Remove Dirichlet positive concentration parameter constructor tests

This test can't be performed in the constructor if we're allowing Theano-type
distribution parameters.

* Add a hack to statically infer Dirichlet argument shapes

Co-authored-by: Brandon T. Willard <[email protected]>

Co-authored-by: Bill Engels <[email protected]>
Co-authored-by: Oriol Abril-Pla <[email protected]>
Co-authored-by: Osvaldo Martin <[email protected]>
Co-authored-by: Adrian Seyboldt <[email protected]>
Co-authored-by: Alexandre ANDORRA <[email protected]>
Co-authored-by: Colin <[email protected]>
Co-authored-by: Brandon T. Willard <[email protected]>
Co-authored-by: Junpeng Lao <[email protected]>
Co-authored-by: rpgoldman <[email protected]>
Co-authored-by: Robert P. Goldman <[email protected]>
Co-authored-by: Tirth Patel <[email protected]>
Co-authored-by: Brandon T. Willard <[email protected]>
@kyleabeauchamp kyleabeauchamp added this to the 3.9.3 milestone Jul 28, 2020
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.

GP Periodic Kernel uses uncommon formula
5 participants