def twiddle(objFunction, args, init=0.5, tolerance=0.00001, domain=(float("-inf"), float("inf"))):
    """
      Optimize a single parameter given an objective function.

      This is a local hill-climbing algorithm. Here is a simple description of it:
      https://www.youtube.com/watch?v=2uQ2BSzDvXs

      @param args       (tuple)   Arguments necessary for the objective function.

      @param tolerance  (float)   Number used to determine when optimization has
                                  converged to a sufficiently good score.

      @param objFunction(function)Objective Function used to quantify how good a
                                  particular parameter choice is.

      @param init       (float)   Initial value of the parameter.

      @param domain     (tuple)   Domain of parameter values, as (min, max).

      @return (dict) Contains:
            "parameter" (float)   Threshold that returns the largest score from the
                                  Objective function.

            "score"     (float)   The score from the objective function given the
                                  threshold.
    """

    pastCalls = {}
    x = init
    delta = 0.1
    bestScore = objFunction(x, args)

    pastCalls[x] = bestScore

    while delta > tolerance:

        # Keep x within bounds
        if x + delta > domain[1]:
            delta = abs(domain[1] - x) / 2
        x += delta

        if x not in pastCalls:
            score = objFunction(x, args)
            pastCalls[x] = score

        score = pastCalls[x]

        if score > bestScore:
            bestScore = score
            delta *= 2

        else:
            # Keep x within bounds
            if x - delta < domain[0]:
                delta = abs(domain[0] - x) / 2
            x -= 2 * delta

            if x not in pastCalls:
                score = objFunction(x, args)
                pastCalls[x] = score

            score = pastCalls[x]

            if score > bestScore:
                bestScore = score
                delta *= 2
            else:
                x += delta
                delta *= 0.5

        print("Parameter:", x)
        print("Best score:", bestScore)
        print("Step size:", delta)
        print()

    return {"parameter": x,
            "score": bestScore}