<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fit_beads_autofluorescence(fl_rfi, fl_mef):
 """ Fit a standard curve using a beads model with autofluorescence. Parameters fl_rfi : array Fluorescence values of bead populations in units of Relative Fluorescence Intensity (RFI). fl_mef : array Fluorescence values of bead populations in MEF units. Returns ------- std_crv : function Standard curve that transforms fluorescence values from RFI to MEF units. This function has the signature ``y = std_crv(x)``, where `x` is some fluorescence value in RFI and `y` is the same fluorescence expressed in MEF units. beads_model : function Fluorescence model of calibration beads. This function has the signature ``y = beads_model(x)``, where `x` is the fluorescence of some bead population in RFI units and `y` is the same fluorescence expressed in MEF units, without autofluorescence. beads_params : array Fitted parameters of the bead fluorescence model: ``[m, b, fl_mef_auto]``. beads_model_str : str String representation of the beads model used. beads_params_names : list of str Names of the parameters in a list, in the same order as they are given in `beads_params`. Notes ----- The following model is used to describe bead fluorescence:: m*log(fl_rfi[i]) + b = log(fl_mef_auto + fl_mef[i]) where ``fl_rfi[i]`` is the fluorescence of bead subpopulation ``i`` in RFI units and ``fl_mef[i]`` is the corresponding fluorescence in MEF units. The model includes 3 parameters: ``m`` (slope), ``b`` (intercept), and ``fl_mef_auto`` (bead autofluorescence). The last term is constrained to be greater or equal to zero. The bead fluorescence model is fit in log space using nonlinear least squares regression. In our experience, fitting in log space weights the residuals more evenly, whereas fitting in linear space vastly overvalues the brighter beads. A standard curve is constructed by solving for ``fl_mef``. As cell samples may not have the same autofluorescence as beads, the bead autofluorescence term (``fl_mef_auto``) is omitted from the standard curve; the user is expected to use an appropriate white cell sample to account for cellular autofluorescence if necessary. The returned standard curve mapping fluorescence in RFI units to MEF units is thus of the following form:: fl_mef = exp(m*log(fl_rfi) + b) This is equivalent to:: fl_mef = exp(b) * (fl_rfi**m) This works for positive ``fl_rfi`` values, but it is undefined for ``fl_rfi < 0`` and non-integer ``m`` (general case). To extend this standard curve to negative values of ``fl_rfi``, we define ``s(fl_rfi)`` to be equal to the standard curve above when ``fl_rfi >= 0``. Next, we require this function to be odd, that is, ``s(fl_rfi) = - s(-fl_rfi)``. This extends the domain to negative ``fl_rfi`` values and results in ``s(fl_rfi) < 0`` for any negative ``fl_rfi``. Finally, we make ``fl_mef = s(fl_rfi)`` our new standard curve. In this way,:: s(fl_rfi) = exp(b) * ( fl_rfi **m), fl_rfi >= 0 - exp(b) * ((-fl_rfi)**m), fl_rfi < 0 This satisfies the definition of an odd function. In addition, ``s(0) = 0``, and ``s(fl_rfi)`` converges to zero when ``fl_rfi -> 0`` from both sides. Therefore, the function is continuous at ``fl_rfi = 0``. The definition of ``s(fl_rfi)`` can be expressed more conveniently as:: s(fl_rfi) = sign(fl_rfi) * exp(b) * (abs(fl_rfi)**m) This is the equation implemented. """

    # Check that the input data has consistent dimensions
    if len(fl_rfi) != len(fl_mef):
        raise ValueError("fl_rfi and fl_mef have different lengths")
    # Check that we have at least three points
    if len(fl_rfi) <= 2:
        raise ValueError("standard curve model requires at least three "
            "values")
        
    # Initialize parameters
    params = np.zeros(3)
    # Initial guesses:
    # 0: slope found by putting a line through the highest two points.
    # 1: y-intercept found by putting a line through highest two points.
    # 2: bead autofluorescence initialized using the first point.
    params[0] = (np.log(fl_mef[-1]) - np.log(fl_mef[-2])) / \
                (np.log(fl_rfi[-1]) - np.log(fl_rfi[-2]))
    params[1] = np.log(fl_mef[-1]) - params[0] * np.log(fl_rfi[-1])
    params[2] = np.exp(params[0]*np.log(fl_rfi[0]) + params[1]) - fl_mef[0]

    # Error function
    def err_fun(p, x, y):
        return np.sum((np.log(y + p[2]) - ( p[0] * np.log(x) + p[1] ))**2)

    # Bead model function
    def fit_fun(p,x):
        return np.exp(p[0] * np.log(x) + p[1]) - p[2]

    # RFI-to-MEF standard curve transformation function
    def sc_fun(p,x):
        return np.sign(x) * np.exp(p[1]) * (np.abs(x)**p[0])
    
    # Fit parameters
    err_par = lambda p: err_fun(p, fl_rfi, fl_mef)
    res = minimize(err_par,
                   params,
                   bounds=((None, None), (None, None), (0, None)),
                   options = {'gtol': 1e-10, 'ftol': 1e-10})

    # Separate parameters
    beads_params = res.x

    # Beads model function
    beads_model = lambda x: fit_fun(beads_params, x)

    # Standard curve function
    std_crv = lambda x: sc_fun(beads_params, x)

    # Model string representation
    beads_model_str = 'm*log(fl_rfi) + b = log(fl_mef_auto + fl_mef)'

    # Parameter names
    beads_params_names = ['m', 'b', 'fl_mef_auto']
    
    return (std_crv,
            beads_model,
            beads_params,
            beads_model_str,
            beads_params_names)