For example, if I choose to test up to rank 2, it tries ranks up to 6. Also, for my dataset, it tries rank 6 on mode 2, but only up to rank 5 for the other modes. If I choose up to rank 3, it suddenly goes up from a maximum of 5 on mode 4 to a maximum of 7. I can't figure out how the ranks are being iterated through... it seems like something based on itertools.permutations would be more readable to ensure correctness.