Parameter estimation (biomass.estimation.optimizer)

class biomass.estimation.Optimizer(model, optimize, x_id, disp_here=False, overwrite=False)

Use an external optimization method for parameterization of a mechanistic model.

model

The BioMASS model object.

Type:

ModelObject

optimize

The optimizer, e.g., scipy.optimize.differential_evolution().

Type:

Callable

x_id

Index of parameter set to estimate.

Type:

int

disp_here

Whether to show the evaluated objective at every iteration.

Type:

bool (default: False)

overwrite

If True, the directory (x_id/) will be overwritten.

Type:

bool (default: False)

Examples

>>> from scipy.optimize import differential_evolution
>>> from biomass import create_model
>>> from biomass.estimation import Optimizer
>>> from biomass.models import copy_to_current
>>> copy_to_current("Nakakuki_Cell_2010")
>>> model = create_model("Nakakuki_Cell_2010")
>>> param_idx = 1
>>> optimizer = Optimizer(model, differential_evolution, param_idx)
>>> def obj_fun(x):
...    '''Objective function to be minimized.'''
...    return model.get_obj_val(x)
>>> res = optimizer.minimize(
...     obj_fun,
...     [(0, 1) for _ in range(len(model.problem.bounds))],
...     strategy="best1bin",
...     maxiter=50,
...     tol=1e-4,
...     mutation=0.1,
...     recombination=0.5,
...     disp=True,
...     polish=False,
...     workers=-1,
... )

differential_evolution step 1: f(x)= 5.19392

differential_evolution step 2: f(x)= 2.32477

differential_evolution step 3: f(x)= 1.93583

differential_evolution step 50: f(x)= 0.519774

>>> from biomass import run_simulation
>>> param_values = model.gene2val(res.x)
>>> optimizer.import_solution(param_values)
>>> run_simulation(model, viz_type=str(param_idx))
import_solution(x, cleanup=True)

Import the solution of the optimization to the model. The solution vector x will be saved to path_to_model/out/x_id/. Use biomass.run_simulation to visualize the optimization result.

Parameters:
  • x (Union[np.ndarray, List[float]]) – The solution of the optimization.

  • cleanup (bool (default: True)) – If True (default), delete the temporary folder after the optimization is finished.

Return type:

None

minimize(*args, **kwargs)

Execute the external optimizer.

class biomass.estimation.InitialPopulation(model, popsize=3, threshold=1000000000000.0)
model

BioMASS model object.

Type:

ModelObject

popsize

A multiplier for setting the total population size.

Type:

int (default: 3)

threshold

Allowable error for generating initial population. Default value is 1e12 (numerically solvable).

Type:

float (default: 1e12)

generate(n_proc=1, progress=False)

Return initial population for optimizer_options['init'] in biomass.optimize function.

Parameters:
  • n_proc (int (default: 1)) – Number of processes to use (default: 1). Set to a larger number (e.g. the number of CPU cores available) for parallel execution of simulations.

  • progress (bool (default: False)) – Whether the progress bar is animating or not.

Returns:

population – Array specifying the initial population. The array should have shape (M, len(x)), where M is the total population size and len(x) is the number of parameters.

Return type:

numpy.ndarray

Examples

>>> from biomass import create_model, optimize
>>> from biomass.estimation import InitialPopulation
>>> from biomass.models import copy_to_current
>>> copy_to_current("Nakakuki_Cell_2010")
>>> model = create_model("Nakakuki_Cell_2010")
>>> initpop = InitialPopulation(model).generate(n_proc=2, progress=True)
>>> optimize(model, x_id=1, optimizer_options={"init": initpop})