Closed sstendahl closed 1 year ago
With regard to the latest PR, there's some bigger changes:
Two seperate methods can be called to either generate a proper calculation of the Fisher matrix, or two create one with mocked parameters and reflectivity (bypassing any models, simulations and reflectivity calculations).
The fisher matrix is tested against known values using the refl1d and refnx model
A test is added to check that an empty array of qs gives the proper empty matrix
A test is added to check that the Fisher matrix values remain (mostly) the same when changing step size
A mock of Xi (the list of parameters) has been created, as opposed to mocking the gradient calculation. The thinking being that the gradient calculation itself should be tested either way, and also that it's nice to be able to give actual dummy values for each parameter in the tests.
Some refactoring has been done in fisher function. This was mostly needed to facilitate the patch in get_fisher_mock
The refl1d model fixture would need to be refactored a bit once the simulate
class is refactored (as far as I can tell, that's the only part in test_fisher.py
that actually depends on simulate
), but I thought it would make most sense to do that once that refactor is actually in.
I could move the logic that it borrows from simulate
to a helper function in test_fisher.py
otherwise, but that would basically mean copying that current function to here, which would not be pretty and add several extra dependencies from the simulate
class.
Fixes issue #53
In this current PR the following unit tests are performed for the
fisher
function:test_fisher_information_values
tests for a known case whether the calculated values are still correcttest_fisher_shape
Tests whether the shape of the fisher matrix remains correct when using different model parameterstest_fisher_diagonal_positive
tests 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
fisher
function have been removed, and the associated docstring now indicates the list type forqs
andcounts
(a list of list),I refactored the general structure of the unit test quite a bit since this morning, moving the
get_fisher_information
outside 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: