def aic(lnL, nfp, sample_size=None):
    """returns Aikake Information Criterion
    
    Arguments:
        - lnL: the maximum log-likelihood of a model
        - nfp: the number of free parameters in the model
        - sample_size: if provided, the second order AIC is returned
    """
    if sample_size is None:
        correction = 1
    else:
        assert sample_size > 0, 'Invalid sample_size %s' % sample_size
        correction = sample_size / (sample_size - nfp - 1)
    return -2 * lnL + 2 * nfp * correction
