def as_learning_rate_by_sample(learning_rate_per_minibatch, minibatch_size, momentum=0, momentum_as_unit_gain=False):
    """
    Compute the scale parameter for the learning rate to match the learning rate
    definition used in other deep learning frameworks.
    In CNTK, gradients are calculated as follows:
        g(t + 1) = momentum * v(t) + (1-momentum) * gradient(t)

    Whereas in other frameworks they are computed this way :
        g(t + 1) = momentum * v(t)

    According to the above equations we need to scale the learning rate with regard to the momentum by a
    factor of 1/(1 - momentum)
    :param learning_rate_per_minibatch: The current learning rate
    :param minibatch_size: Size of the minibatch
    :param momentum: The current momentum (0 by default, used only when momentum_as_unit_gain is True)
    :param momentum_as_unit_gain: Indicate whetherf the momentum is a unit gain factor (CNTK) or not (TensorFlow, etc.)
    :return: Scaled learning rate according to momentum and minibatch size
    """
    assert learning_rate_per_minibatch > 0, "learning_rate_per_minibatch cannot be < 0"
    assert minibatch_size > 0, "minibatch_size cannot be < 1"

    learning_rate_per_sample = learning_rate_per_minibatch / minibatch_size

    if momentum_as_unit_gain:
        learning_rate_per_sample /= (1. - momentum)

    return learning_rate_per_sample