def _ilsr(fun, params, max_iter, tol):
converged = NormOfDifferenceTest(tol, order=<NUM_LIT:1>)<EOL>for _ in range(max_iter):<EOL><INDENT>params = fun(initial_params=params)<EOL>if converged(params):<EOL><INDENT>return params<EOL><DEDENT><DEDENT>raise RuntimeError("<STR_LIT>".format(max_iter))<EOL>
Iteratively refine LSR estimates until convergence.

    Raises
    ------
    RuntimeError
        If the algorithm does not converge after ``max_iter`` iterations.