brian2modelfitting.optimizer module

class brian2modelfitting.optimizer.NevergradOptimizer(method='DE', use_nevergrad_recommendation=False, **kwds)[source]

Bases: brian2modelfitting.optimizer.Optimizer

NevergradOptimizer instance creates all the tools necessary for the user to use it with Nevergrad library.

Parameters:
  • parameter_names (list or dict) – List/Dict of strings with parameters to be used as instruments.
  • bounds (list) – List with appropriate bounds for each parameter.
  • method (str or callable, optional) – The optimization method. By default differential evolution, can be chosen by name from any method in Nevergrad registry. Alternatively, a callable object can be provided.
  • use_nevergrad_recommendation (bool, optional) – Whether to use Nevergrad’s recommendation as the “best result”. This recommendation takes several evaluations of the same parameters (for stochastic simulations) into account. The alternative is to simply return the parameters with the lowest error so far (the default). The problem with Nevergrad’s recommendation is that it can give wrong result for errors that are very close in magnitude due (see github issue #16).
  • budget (int or None) – number of allowed evaluations
  • num_workers (int) – number of evaluations which will be run in parallel at once
ask(n_samples)[source]

Returns the requested number of samples of parameter sets

Parameters:n_samples (int) – number of samples to be drawn
Returns:parameters – list of drawn parameters [n_samples x n_params]
Return type:list
initialize(parameter_names, popsize, rounds, **params)[source]

Initialize the instrumentation for the optimization, based on parameters, creates bounds for variables and attaches them to the optimizer

Parameters:
  • parameter_names (list[str]) – list of parameter names in use
  • popsize (int) – population size
  • rounds (int) – Number of rounds (for budget calculation)
  • **params – bounds for each parameter
Returns:

popsize – The actual population size that will be used by the algorithm. Does not always correspond to popsize, since some algorithms have minimal/maximal population sizes.

Return type:

int

recommend()[source]

Returns best recommendation provided by the method

Returns:result – list of best fit parameters[n_params]
Return type:list
tell(parameters, errors)[source]

Provides the evaluated errors from parameter sets to optimizer

Parameters:
  • parameters (list) – list of parameters [n_samples x n_params]
  • errors (list) – list of errors [n_samples]
class brian2modelfitting.optimizer.Optimizer[source]

Bases: object

Optimizer class created as a base for optimization initialization and performance with different libraries. To be used with modelfitting Fitter.

ask(n_samples)[source]

Returns the requested number of samples of parameter sets

Parameters:n_samples (int) – number of samples to be drawn
Returns:parameters – list of drawn parameters [n_samples x n_params]
Return type:list
initialize(parameter_names, popsize, rounds, **params)[source]

Initialize the instrumentation for the optimization, based on parameters, creates bounds for variables and attaches them to the optimizer

Parameters:
  • parameter_names (list[str]) – list of parameter names in use
  • popsize (int) – population size
  • rounds (int) – Number of rounds (for budget calculation)
  • **params – bounds for each parameter
Returns:

popsize – The actual population size that will be used by the algorithm. Does not always correspond to popsize, since some algorithms have minimal/maximal population sizes.

Return type:

int

recommend()[source]

Returns best recommendation provided by the method

Returns:result – list of best fit parameters[n_params]
Return type:list
tell(parameters, errors)[source]

Provides the evaluated errors from parameter sets to optimizer

Parameters:
  • parameters (list) – list of parameters [n_samples x n_params]
  • errors (list) – list of errors [n_samples]
class brian2modelfitting.optimizer.SkoptOptimizer(method='GP', **kwds)[source]

Bases: brian2modelfitting.optimizer.Optimizer

SkoptOptimizer instance creates all the tools necessary for the user to use it with scikit-optimize library.

Parameters:
  • parameter_names (list[str]) – Parameters to be used as instruments.
  • bounds (list) – List with appropiate bounds for each parameter.
  • method (str, optional) – The optimization method. Possibilities: “GP”, “RF”, “ET”, “GBRT” or sklearn regressor, default=”GP”
  • n_calls (int) – Number of calls to func. Defaults to 100.
ask(n_samples)[source]

Returns the requested number of samples of parameter sets

Parameters:n_samples (int) – number of samples to be drawn
Returns:parameters – list of drawn parameters [n_samples x n_params]
Return type:list
initialize(parameter_names, popsize, rounds, **params)[source]

Initialize the instrumentation for the optimization, based on parameters, creates bounds for variables and attaches them to the optimizer

Parameters:
  • parameter_names (list[str]) – list of parameter names in use
  • popsize (int) – population size
  • rounds (int) – Number of rounds (for budget calculation)
  • **params – bounds for each parameter
Returns:

popsize – The actual population size that will be used by the algorithm. Does not always correspond to popsize, since some algorithms have minimal/maximal population sizes.

Return type:

int

recommend()[source]

Returns best recommendation provided by the method

Returns:result – list of best fit parameters[n_params]
Return type:list
tell(parameters, errors)[source]

Provides the evaluated errors from parameter sets to optimizer

Parameters:
  • parameters (list) – list of parameters [n_samples x n_params]
  • errors (list) – list of errors [n_samples]
brian2modelfitting.optimizer.calc_bounds(parameter_names, **params)[source]

Verify and get the provided for parameters bounds

Parameters:
  • parameter_names (list[str]) – list of parameter names in use
  • **params – bounds for each parameter