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

Split code into submodules for the different approximations #96

Merged
merged 29 commits into from
Mar 11, 2022

Conversation

st--
Copy link
Member

@st-- st-- commented Jan 14, 2022

New submodules:

  • API: common interface
  • SparseVariationalApproximationModule
  • LaplaceApproximationModule

This does not change the exports of ApproximateGPs.jl, and hence users should not have to actually change their code.

NOTE: users of this package should only use the exported symbols.
Functions &c inside the submodules are liable to change, and are not part of the public interface!


Example implementation of #90. I'm actually happy with how it turned out, so changed it to "ready for review", let's continue the discussion until we find something we can all settle on:)

(Side note - ignore any of the code around expected_loglik, that should really move into GPLikelihoods.jl anyways.)

test/expected_loglik.jl Outdated Show resolved Hide resolved
test/expected_loglik.jl Outdated Show resolved Hide resolved
test/laplace.jl Outdated Show resolved Hide resolved
test/laplace.jl Outdated Show resolved Hide resolved
st-- and others added 3 commits January 14, 2022 15:05
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@@ -114,7 +114,7 @@
function eval_newton_inner_loop(theta)
k = with_lengthscale(Matern52Kernel(), exp(theta))
K = kernelmatrix(k, xs)
f, cache = ApproximateGPs._newton_inner_loop(
f, cache = LaplaceApproximationModule._newton_inner_loop(
Copy link
Member Author

Choose a reason for hiding this comment

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

I really like how this makes clear where the function is coming from.

@codecov
Copy link

codecov bot commented Jan 14, 2022

Codecov Report

Merging #96 (11b186b) into master (bae0a1e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #96   +/-   ##
=======================================
  Coverage   95.78%   95.78%           
=======================================
  Files           4        4           
  Lines         285      285           
=======================================
  Hits          273      273           
  Misses         12       12           
Impacted Files Coverage Δ
src/SparseVariationalApproximationModule.jl 96.20% <ø> (ø)
src/expected_loglik.jl 95.34% <ø> (ø)
src/utils.jl 42.85% <ø> (ø)
src/LaplaceApproximationModule.jl 98.07% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bae0a1e...11b186b. Read the comment docs.

src/LaplaceApproximationModule.jl Outdated Show resolved Hide resolved
src/LaplaceApproximationModule.jl Outdated Show resolved Hide resolved
@theogf
Copy link
Member

theogf commented Jan 14, 2022

Two main comments if we go in this direction:

  • Can LaplaceApproximationModule can be shortened? I think LaplaceModule is still understandable
  • Why put SparseVariationalApproximation in a sub-module? I can see the point of having each approach in a different sub-module but SVA is not an approach in itself

st-- and others added 2 commits January 14, 2022 15:19
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
src/LaplaceApproximationModule.jl Outdated Show resolved Hide resolved
src/LaplaceApproximationModule.jl Outdated Show resolved Hide resolved
@st--
Copy link
Member Author

st-- commented Jan 14, 2022

  • Can LaplaceApproximationModule can be shortened? I think LaplaceModule is still understandable

Yes, could do, but wouldn't work quite the same for ExpectationPropagation; it could be EPModule, but I found it cleaner to have the module name follow the name of the approximation struct. You're not

  • Why put SparseVariationalApproximation in a sub-module? I can see the point of having each approach in a different sub-module but SVA is not an approach in itself

I'm not sure what you mean... ?

@theogf
Copy link
Member

theogf commented Jan 14, 2022

I'm not sure what you mean... ?

I don't understand the point of having SparseVariationalApproximationModule.

@st--
Copy link
Member Author

st-- commented Jan 14, 2022

I don't understand the point of having SparseVariationalApproximationModule.

For the same reason we've got LaplaceApproximationModule - to separate the different subcomponents of the ApproximateGPs package. No?

(In a sense we might just want them all to be their own packages, which the submodules would prepare us for later down the road, but right now it's probably not worth it.)

@theogf
Copy link
Member

theogf commented Jan 14, 2022

For the same reason we've got LaplaceApproximationModule - to separate the different subcomponents of the ApproximateGPs package. No?

Yeah but that's not the argument you raised initially. It was more about conflicting naming between methods EP and Laplace for example. But SVA is basically the common core of the package used by the rest of the methods, it's not "just another solving algorithm", that's why I would not put it in a module. My proposal would be instead to have all the core common objects in the main module and every algorithm Laplace, EP and more in their own module.

@st--
Copy link
Member Author

st-- commented Jan 14, 2022

For the same reason we've got LaplaceApproximationModule - to separate the different subcomponents of the ApproximateGPs package. No?

Yeah but that's not the argument you raised initially.

It was part of the argument I was trying to make! 😅

But SVA is basically the common core of the package used by the rest of the methods, it's not "just another solving algorithm", that's why I would not put it in a module.

I disagree both with the premise and the conclusion...
Contra premise: Laplace doesn't use SVA, and EP shouldn't use SVA (it'd be more numerically stable and faster to implement it making use of the specific EP structure). I'm not convinced what would make SVA more than "just another approximation algorithm".
Contra conclusion: accepting that EP depends on SVA, it should mainly depend on it in terms of the public API - which is easily handled by using .ApproximateGPs: SparseVariationalApproximation. What would we gain from having all the SVA internals within the "umbrella" package?

@st--

This comment has been minimized.

@st-- st-- changed the title stab at submodules Split code into submodules for the different approximations Jan 14, 2022
@st-- st-- marked this pull request as ready for review January 14, 2022 14:41
@theogf
Copy link
Member

theogf commented Jan 19, 2022

Contra premise: Laplace doesn't use SVA, and EP shouldn't use SVA (it'd be more numerically stable and faster to implement it making use of the specific EP structure). I'm not convinced what would make SVA more than "just another approximation algorithm".

Sorry, I was somehow convinced that SVA was a core element and was used by everything else. Than, all you said makes sense

docs/src/api.md Outdated
@@ -1,5 +1,5 @@
# ApproximateGPs API

```@autodocs
Modules = [ApproximateGPs]
Modules = [ApproximateGPs, ApproximateGPs.API, ApproximateGPs.SparseVariationalApproximationModule, ApproximateGPs.LaplaceApproximationModule]
Copy link
Member Author

Choose a reason for hiding this comment

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

The only potential downside I would see is that it might look a bit weirder to see the fully-qualified names in the API docs (see https://juliagaussianprocesses.github.io/ApproximateGPs.jl/previews/PR96/api/)

Copy link
Member Author

Choose a reason for hiding this comment

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

On the other hand, that keeps related functions next to each other, and perhaps it would actually be more helpful to have different sub-pages for each of the approximations?

Copy link
Member

Choose a reason for hiding this comment

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

I really like the idea of having one page per approximation.

@st--
Copy link
Member Author

st-- commented Jan 20, 2022

Ah that comes from :
If strict=true (or strict=:missing_docs or strict=[:missing_docs, ...]) is also set then the build will fail if any missing docstrings are encountered.

I wish it would just give a meaningful error message instead of just saying "error" (and not even hinting that you might want to look at warnings)...

Update: I've opened an issue JuliaDocs/Documenter.jl#1756

Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

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

lgtm

src/ApproximateGPs.jl Outdated Show resolved Hide resolved
src/ApproximateGPs.jl Outdated Show resolved Hide resolved
@st--
Copy link
Member Author

st-- commented Jan 20, 2022

Note: @reexport also exports the submodule itself! This is not what we want. The only solution I could come up with is to explicitly qualify the @reexport using .Foo: bar, baz.

st-- and others added 4 commits January 20, 2022 17:05
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
src/LaplaceApproximationModule.jl Outdated Show resolved Hide resolved
src/SparseVariationalApproximationModule.jl Outdated Show resolved Hide resolved
st-- and others added 2 commits January 20, 2022 17:45
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@st--
Copy link
Member Author

st-- commented Jan 26, 2022

One thing I don't like about this yet is that it took away all the docstrings for methods-from-other-packages (such as AbstractGPs.posterior) defined for the types of ApproximateGPs. I'm not quite sure why that would be...

@theogf
Copy link
Member

theogf commented Jan 26, 2022

Wait you cannot access them from the REPL or from Documenter?

@st--
Copy link
Member Author

st-- commented Jan 27, 2022

Wait you cannot access them from the REPL or from Documenter?

From Documenter. Something about how it discovers functions? Maybe because I changed to Private = true? 🤔

It all works fine from the REPL (see tests, notebooks passing)!

@st-- st-- merged commit e57ac47 into master Mar 11, 2022
@st-- st-- deleted the st/submodules branch March 11, 2022 11:25
st-- added a commit that referenced this pull request Mar 15, 2022
* stab at submodules

* move approx_lml to API

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* clean up imports

* remove unused imports

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* docfix

* missing import

* test: remove submodules from api docs

* subpages in docs

* hide private API docstrings

* mention types in api/index.md

* qualify

* remove extra line

* minor bump#

* change docs/ compat

* update test compat

* explicitly `@reexport` to avoid exporting the submodules!

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* add likelihood imports

* add import

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* add import

* Update src/SparseVariationalApproximationModule.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
st-- added a commit that referenced this pull request Mar 15, 2022
* resolves #100

* try it out for notebooks

* Update docs/literate.jl

* explicit html for notebook

* Update docs/literate.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* pre-1.7 compat

* Update docs/literate.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* add horizontal rules at top and bottom

* fix notebook/documenter link discrepancy

* bugfix

* fix hrules

* fix markdown

* fixup

* fix notebook formatting

* use Markdown.htmlesc

* separate System information section ......

* Fix file size of notebook (#103)

* Fix file size of notebook

* Fix format

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Change comment

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* CompatHelper: bump compat for "GPLikelihoods" to "0.3" (#107)

* CompatHelper: bump compat for "GPLikelihoods" to "0.3"

* Reorder Gamma parametrization

* Update project versions

* Missing one

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Théo Galy-Fajou <[email protected]>

* Fix outdated `literate.jl` script (#111)

* Fix outdated `literate.jl` script

* Fix format

* Split code into submodules for the different approximations (#96)

* stab at submodules

* move approx_lml to API

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* clean up imports

* remove unused imports

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* docfix

* missing import

* test: remove submodules from api docs

* subpages in docs

* hide private API docstrings

* mention types in api/index.md

* qualify

* remove extra line

* minor bump#

* change docs/ compat

* update test compat

* explicitly `@reexport` to avoid exporting the submodules!

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* add likelihood imports

* add import

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* add import

* Update src/SparseVariationalApproximationModule.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Rename the test files (#113)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: Théo Galy-Fajou <[email protected]>
Co-authored-by: Ross Viljoen <[email protected]>
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.

5 participants