-
Notifications
You must be signed in to change notification settings - Fork 16
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
NDE implementation #353
base: master
Are you sure you want to change the base?
NDE implementation #353
Conversation
Just at a glance, you might want to have a look at how the optional dependency of |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #353 +/- ##
===========================================
- Coverage 100.00% 90.35% -9.65%
===========================================
Files 36 36
Lines 3043 3195 +152
===========================================
- Hits 3043 2887 -156
- Misses 0 308 +308 ☔ View full report in Codecov by Sentry. |
anesthetic/plot.py
Outdated
|
||
This functions as a wrapper around :meth:`matplotlib.axes.Axes.plot`, with | ||
a normalising flow as a neural density estimation (NDE) provided by | ||
`margarine.maf.MAF` or `margarine.clustered.clusterMAF` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting the docs to work properly for an optional dependency seems like a pain, so I've copied the fastkde approach of just putting a link to margarine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand, what was the issue here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's probably a few layers to this, but part of it is that margarine only contains submodules (so from margarine.maf import MAF
works but import margarine; margarine.maf.MAF
does not, and I couldn't get to the bottom of how to refer to them properly.
You'll be able to see the error messages in the earlier checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(personally I'd change the margarine api but I'm just a disruptive influence)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even changing the api hasn't made it straightforward - @lukashergt is the king when it comes to the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To explain a bit more, the issue was that the docstring contained :class:`margarine.maf`
, which tells autodoc to try and link to the documentation of a class called maf
in a package called margarine
, which autodoc wasn't able to find, though. Two issues here:
- There is no dedicated documentation for the class
:class:`margarine.maf`
, there is only documentation for the method:meth:`margarine.maf.MAF`
. - In order for autodoc to find the margarine documentation, you need to tell it where to look. In
docs/source/conf.py
you can find a dictionary that tells autodoc where to do that for matplotlib, pandas, and Co. You'll need to add the margarine readthedocs url to that dictionary in order to get the automatic linking to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think
:class:
is the right thing, sincemargarine.maf
is a submodule, andMAF
is a class inside that submodule. - I'd tried adding this and couldn't get it to work 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it appears that the margarine docs don't build all the needed reference targets. I've created a PR htjb/margarine#54 that uses more of the autodoc power that should hopefully remedy that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh okay I see! Thanks @lukashergt I will have a look at your PR on margarine asap.
tests now failing as expected (I'd forgotten to add margarine to the 'all' dependency!) |
@AdamOrmondroyd Cant remember what needs doing here? is it just the tests need tidying? and master merging? |
The tests need a rethink, because simply adding nde everywhere we previously saw kde slows everything down too much Also at least one of them appears to have failed at the last time of running, and you're missing some coverage |
Ahh yes the NDEs are not particularly quick... maybe like a few minutes for a few thousands of samples (dependent on the architecture). Has the potential to slow the tests down... Looks like the test failed because of a version mismatch between TensorFlow and TensorFlow Probability. What does the |
This also needed waiting for the margarine docs to work, which is now the case. So now the NDE docstrings properly link to the margarine docs. |
@AdamOrmondroyd pointed out that I might have set the code up to train a new NDE for every panel in the corner plot if I just replaced KDE with NDE in the plotting script. I think it should be possible to train an nD NDE and use this to plot contours on a corner plot. Need to check over the code though. |
Description
Adding in optional neural density estimator plot functions as an alternative to KDE and histogram plotters.
Fixes #334
Checklist:
flake8 anesthetic tests
)pydocstyle --convention=numpy anesthetic
)python -m pytest
)