def g_inv(x, t=4): """Inverse of g transform.""" xp = np.clip(x, -t, t) diff = np.arctanh(np.clip(x - xp, -1 + 1e-10, 1 - 1e-10)) return xp + diff