def isValid(self, threshold=1e-7): """Rate matrix is valid if rows sum to 0 and no negative off-diags. threshold gives maximum error allowed in row sums. """ if max(abs(sum(self._data, -1)) > threshold): return False return not has_neg_off_diags(self._data)
def hasNegOffDiags(self): """Returns True if any off-diagonal elements negative.""" return has_neg_off_diags(self._data)