ENH: Add hmfc calculation

Ready for review/merge. Hopefully the tests make it clear how the function works. @rkmaddox let me know if there are other corner cases you think we need to check, it's important to get this one right.
Good call, test fixed