import torch


def fastslow_anneal(i, maxval, minval, num_steps, a=0.3):
    """
    This function quickly decays from 1.0, then slowly decays to 0.0. The "a" parameter
    (which should be greater than 0) controls the curvature of the annealing. A large value of
    "a" (e.g., greater than 1) leads to an approximately-linear annealing. A value of
    "a" close to 0 leads to a rapid decay from 1.0 and a very gradual decay to 0.0.
    """
    assert maxval == 1.0
    assert minval == 0.0
    na = num_steps * a
    val = (na - a * i) / (na + i)
    return torch.tensor(val, dtype=torch.float)