Add unit tests for fisher function in utils#55
Conversation
Oops, latest commit created (one) too many reflectivity data points. Don't push when tired...
jfkcooper
left a comment
There was a problem hiding this comment.
Quite a few comments here, please message if any are not clear, or if you want further info on how to implement them.
Add docstrings to the break-out functions. Also add some type hints, give the non-user facing functions an underscore prefix, and revert the instance check to an instance check instead of an attribute check. (Neither is ugly, instance check is probably more robust)
Add some docstrings, and did some minor formatting tweaks to make it slightly more in-line with PEP8 regarding line-length. (I am personally targeting 79 characters (PEP default, but they explictly state that one can deviate if agreed upon), but we probably want to formaly decide this with a linter (e.g. Flake8)
|
With regard to the latest PR, there's some bigger changes:
|
|
The refl1d model fixture would need to be refactored a bit once the I could move the logic that it borrows from |
jfkcooper
left a comment
There was a problem hiding this comment.
Some more comments, getting quite close now.
hogben/tests/test_fisher.py
Outdated
| """ | ||
| g_reference = get_fisher_information(refl1d_model, step=0.005) | ||
| g_compare = get_fisher_information(refl1d_model, step=step) | ||
| np.testing.assert_allclose(g_reference, g_compare, rtol=1e-02, atol=0) |
Add unit tests for `fisher` function in `utils`
Add unit tests for `fisher` function in `utils`
Fixes issue #53
In this current PR the following unit tests are performed for the
fisherfunction:test_fisher_information_valuestests for a known case whether the calculated values are still correcttest_fisher_shapeTests whether the shape of the fisher matrix remains correct when using different model parameterstest_fisher_diagonal_positivetests for varying sets of q-values whether the diagonal elements are greater than zero. As far as I understood, these diagonal elements represent the FI for the individual parameter on this row, and should never be zero.Also, the triple assignments in
fisherfunction have been removed, and the associated docstring now indicates the list type forqsandcounts(a list of list),I refactored the general structure of the unit test quite a bit since this morning, moving the
get_fisher_informationoutside of the testing Class, as to allow to test for different cases. Given it's a cheap calculation, it is probably still worth it to just calculate g in each test.There's probably a few more tests that could be added as well, such as the importance scaling and the gradient calculations. But I figured those may be added in a separate PR: