Realistic tests
richardjgowers opened this issue · 6 comments
Related to #10 slightly (a good example would also make a good test). The tests currently just test edge cases, ie constant diffusion or zero diffusion, but there should be some tests that test against real data. It should be fairly easy to find some simple liquid diffusion, then ideally it would be checked against another common tool, something like Gromacs' g_msd
.
Do you have a reference on how to perform good tests on stochastic data? The tests are fully self-contained and relying on g_msd
is not aligned with this criterion. I could perform a "full O(N^2)" computation for comparison, a bit as in examples/plot_msd_1.py
but not skipping some of the data.
I think if you seed the random number generator then you get (a sequence of) reproducible random numbers. You can then produce a random walk like in the examples, with a known answer.
You don't have to include g_msd
in the tests, but it would be nice to know that it agrees with an existing established tool such as that. Eg g_msd says D=2.1, your tool says 2.1, you hard code a regression test that it should return 2.1. Maybe doing the bruteforce N^2 operation is easier to maintain in the future though.
For random walks, D is known analytically. In the MSD example, I plot the theoretical result (no fit) along with the numerical result.
I can do the same (i.e. generate 32 random walks of length 1000) and verify that a fit of the MSD is close enough. There wouldn't be any need for matplotlib, only NumPy which includes a polynomial fitting routine.
Fitting msd for D is quite noisy. I opted for an explicit brute force approach here: https://github.com/pdebuyl-lab/tidynamics/blob/master/tests/test_msd_2.py
The data is in the test is random. The comparison is made to a full loop over all time intervals available in the trajectory, using np.allclose
.
ping @richardjgowers ?
@pdebuyl yeah the tests look better now