def adjust_gamma(ratio, gamma):
    """
    Tune the scaling parameter for the step size in Markov chain stepper.

    Inspired by implementation of adaptive Metropolis algorithm in PyMC3
    """
    # Do nothing if the ratio is acceptable
    if ratio > 0.20 and ratio < 0.35:
        return gamma

    # Adjust gamma based on current ratio of accepted / total jumps
    if ratio < 0.05:
        gamma *= 0.10
    elif ratio < 0.10:
        gamma *= 0.15
    elif ratio < 0.17:
        gamma *= 0.35
    elif ratio < 0.20:
        gamma *= 0.5
    elif ratio > 0.95:
        gamma *= 10.0
    elif ratio > 0.75:
        gamma *= 6.0
    elif ratio > 0.50:
        gamma *= 3.0
    elif ratio > 0.35:
        gamma *= 2.0

    return gamma