def fit_routine_1(self, cell_data=None):
    global SAVE_PATH_PREFIX
    SAVE_PATH_PREFIX = "fit_routine_1_"
    # errors: [error_bf, error_vs, error_sc, error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope]
    self.counter = 0
    # fit only v_offset, mem_tau, noise_strength, input_scaling
    x0 = np.array([0.02, 0.03, 70])
    initial_simplex = create_init_simples(x0, search_scale=2)
    error_weights = (1, 1, 1, 1, 1, 0, 0)
    fmin_step1 = minimize(fun=self.cost_function_with_fixed_adaption_tau, args=(self.tau_a, self.delta_a, error_weights),
                          x0=x0, method="Nelder-Mead",
                          options={"initial_simplex": initial_simplex})
    res_parameters_step1 = self.base_model.get_parameters()

    if cell_data is not None:
        print("##### After step 1:   (fixed adaption)")
        print_comparision_cell_model(cell_data, res_parameters_step1)

    self.counter = 0
    x0 = np.array([res_parameters_step1["mem_tau"], res_parameters_step1["noise_strength"],
                   res_parameters_step1["input_scaling"], res_parameters_step1["tau_a"],
                   res_parameters_step1["delta_a"]])
    initial_simplex = create_init_simples(x0, search_scale=2)
    error_weights = (1, 1, 1, 1, 1, 2, 4)
    fmin_step2 = minimize(fun=self.cost_function_all, args=(error_weights), x0=x0, method="Nelder-Mead",
                          options={"initial_simplex": initial_simplex})
    res_parameters_step2 = self.base_model.get_parameters()

    if cell_data is not None:
        print("##### After step 2:   (Everything)")
        # print_comparision_cell_model(cell_data, res_parameters_step2)

    return fmin_step2, res_parameters_step2


def fit_routine_2(self, cell_data=None):
    global SAVE_PATH_PREFIX
    SAVE_PATH_PREFIX = "fit_routine_2_"
    # errors: [error_bf, error_vs, error_sc, error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope]
    self.counter = 0
    # fit only v_offset, mem_tau, noise_strength, input_scaling
    x0 = np.array([0.02, 0.03, 70])
    initial_simplex = create_init_simples(x0, search_scale=2)
    error_weights = (1, 1, 5, 1, 2, 0, 0)
    fmin = minimize(fun=self.cost_function_with_fixed_adaption_tau,
                    args=(self.tau_a, self.delta_a, error_weights), x0=x0, method="Nelder-Mead",
                    options={"initial_simplex": initial_simplex})
    res_parameters = self.base_model.get_parameters()

    return fmin, res_parameters


def fit_routine_3(self, cell_data=None):
    global SAVE_PATH_PREFIX
    SAVE_PATH_PREFIX = "fit_routine_3_"
    # errors: [error_bf, error_vs, error_sc, error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope]
    self.counter = 0
    # fit only v_offset, mem_tau, noise_strength, input_scaling, dend_tau
    x0 = np.array([0.02, 0.03, 70, 0.001])
    initial_simplex = create_init_simples(x0, search_scale=2)
    error_weights = (1, 1, 5, 1, 2, 0, 0)
    fmin = minimize(fun=self.cost_function_with_fixed_adaption_with_dend_tau,
                    args=(self.tau_a, self.delta_a, error_weights), x0=x0, method="Nelder-Mead",
                    options={"initial_simplex": initial_simplex})
    res_parameters = self.base_model.get_parameters()

    return fmin, res_parameters


def fit_routine_4(self, cell_data=None, start_parameters=None):
    global SAVE_PATH_PREFIX
    SAVE_PATH_PREFIX = "fit_routine_4_"
    # errors: [error_bf, error_vs, error_sc, error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope]
    self.counter = 0
    # fit only v_offset, mem_tau, input_scaling, dend_tau
    if start_parameters is None:
        x0 = np.array([0.02, 70, 0.001])
    else:
        x0 = np.array([start_parameters["mem_tau"], start_parameters["noise_strength"],
                       start_parameters["input_scaling"], start_parameters["dend_tau"]])
    initial_simplex = create_init_simples(x0, search_scale=2)
    error_weights = (0, 5, 15, 1, 2, 1, 0)
    fmin = minimize(fun=self.cost_function_with_fixed_adaption_with_dend_tau,
                    args=(self.tau_a, self.delta_a, error_weights),
                    x0=x0, method="Nelder-Mead",
                    options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 400, "maxiter": 400})
    res_parameters = fmin.x

    # print_comparision_cell_model(cell_data, self.base_model.get_parameters())

    self.counter = 0
    x0 = np.array([self.tau_a,
                   self.delta_a, res_parameters[0]])
    initial_simplex = create_init_simples(x0, search_scale=2)
    error_weights = (0, 1, 1, 2, 2, 4, 2)
    fmin = minimize(fun=self.cost_function_only_adaption,
                    args=(error_weights,), x0=x0, method="Nelder-Mead",
                    options={"initial_simplex": initial_simplex, "xatol": 0.001})
    print(fmin)
    print_comparision_cell_model(cell_data, self.base_model.get_parameters())

    #
    # # self.counter = 0
    # # x0 = np.array([res_parameters[0],
    # #                res_parameters[1], self.tau_a,
    # #                self.delta_a, res_parameters[2]])
    # # initial_simplex = create_init_simples(x0, search_scale=2)
    # # error_weights = (1, 3, 1, 2, 1, 3, 2)
    # # fmin = minimize(fun=self.cost_function_all_without_noise,
    # #                 args=(error_weights,), x0=x0, method="Nelder-Mead",
    # #                 options={"initial_simplex": initial_simplex, "xatol": 0.001})
    # # res_parameters = self.base_model.get_parameters()
    # #
    # # print_comparision_cell_model(cell_data, self.base_model.get_parameters())
    #
    # self.counter = 0
    # x0 = np.array([res_parameters[0], start_parameters["noise_strength"],
    #                res_parameters[1], res_parameters[2],
    #                res_parameters[3], res_parameters[4]])
    # initial_simplex = create_init_simples(x0, search_scale=2)
    # error_weights = (0, 1, 2, 1, 1, 3, 2)
    # fmin = minimize(fun=self.cost_function_all,
    #                 args=(error_weights,), x0=x0, method="Nelder-Mead",
    #                 options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxiter": 599})
    # res_parameters = self.base_model.get_parameters()

    return fmin, self.base_model.get_parameters()
