示例#1
0
def check_minimize(objective, library, solver, allow_failed_starts=False):

    options = {'maxiter': 100}

    optimizer = None

    if library == 'scipy':
        optimizer = pypesto.ScipyOptimizer(method=solver, options=options)
    elif library == 'dlib':
        optimizer = pypesto.DlibOptimizer(method=solver, options=options)
    elif library == 'pyswarm':
        optimizer = pypesto.PyswarmOptimizer(options=options)

    lb = 0 * np.ones((1, 2))
    ub = 1 * np.ones((1, 2))
    problem = pypesto.Problem(objective, lb, ub)

    optimize_options = pypesto.OptimizeOptions(
        allow_failed_starts=allow_failed_starts)

    result = pypesto.minimize(problem=problem,
                              optimizer=optimizer,
                              n_starts=1,
                              startpoint_method=pypesto.startpoint.uniform,
                              options=optimize_options)

    assert isinstance(result.optimize_result.list[0]['fval'], float)
示例#2
0
def parameter_estimation(objective, library, solver, fixed_pars, n_starts):

    if re.match(r'(?i)^(ls_)', solver):
        options = {'max_nfev': 10}
    else:
        options = {'maxiter': 10}

    if library == 'scipy':
        optimizer = pypesto.ScipyOptimizer(method=solver, options=options)
    elif library == 'dlib':
        optimizer = pypesto.DlibOptimizer(method=solver, options=options)
    elif library == 'pyswarm':
        optimizer = pypesto.PyswarmOptimizer(options=options)
    else:
        raise ValueError("This code should not be reached")

    optimizer.temp_file = os.path.join('test', 'tmp_{index}.csv')

    dim = len(objective.x_ids)
    lb = -2 * np.ones((1, dim))
    ub = 2 * np.ones((1, dim))
    pars = objective.amici_model.getParameters()
    problem = pypesto.Problem(objective,
                              lb,
                              ub,
                              x_fixed_indices=fixed_pars,
                              x_fixed_vals=[pars[idx] for idx in fixed_pars])

    optimize_options = pypesto.OptimizeOptions(
        allow_failed_starts=False,
        startpoint_resample=True,
    )

    pypesto.minimize(problem, optimizer, n_starts, options=optimize_options)
示例#3
0
def parameter_estimation(
    objective,
    library,
    solver,
    fixed_pars,
    n_starts,
):
    options = {
        'maxiter': 100
    }

    if library == 'scipy':
        optimizer = pypesto.ScipyOptimizer(method=solver,
                                           options=options)
    elif library == 'dlib':
        optimizer = pypesto.DlibOptimizer(method=solver,
                                          options=options)

    optimizer.temp_file = os.path.join('test', 'tmp_{index}.csv')

    lb = -2 * np.ones((1, objective.dim))
    ub = 2 * np.ones((1, objective.dim))
    pars = objective.amici_model.getParameters()
    problem = pypesto.Problem(objective, lb, ub,
                              x_fixed_indices=fixed_pars,
                              x_fixed_vals=[pars[idx] for idx in fixed_pars]
                              )

    optimize_options = pypesto.OptimizeOptions(
        allow_failed_starts=False,
        startpoint_resample=True,
    )

    results = pypesto.minimize(
        problem, optimizer, n_starts, options=optimize_options,
    )
    results = results.optimize_result.list