Parent: MorphoOptimizationProject

When replacing one algorithm with another, it is very easy to introduce tiny differences that cause later code to produce visibly different results.

Rather than just comparing the final results, which does not help with debugging, it is best to compare the intermediate results either immediately after the algorithm or, ideally, during the execution of the algorithm - this will greatly assist debugging any differences.

To this end, the following outline of a change seems to work well

Add the new code with very few changes to the old

eg.

becomes

Add the comparison

Comparing the results may vary from (a) the simple comparison of their return value, or (b) comparing many fields that they wrote. In the later case, sometimes I have resorted to this

However there are worse situations, such as when the algorithm looks like this

By using the mris_hash function, it is possible to compare MRIS, but it may take too long. To reduce the number of tests, I will do something like

Now it is possible to compare the outputs and, by changing the sequence of limit values, narrow in on the iteration causing the difference.

When the algorithm changes its own inputs

If the algorithm modifies its own inputs, it may not be possible to run both and compare as above.

It may be necessary to either (a) save and restore the inputs around the first call, or (b) use two different runs and compare the outputs as described above.

MorphoOptimizationProject_ComparingOldAndNew (last edited 2018-04-05 19:26:58 by BevinBrett)