Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_optimization_results(objective):
# create optimizer, pypesto problem and options
options = {
'maxiter': 200
}
optimizer = optimize.ScipyOptimizer(method='TNC', options=options)
lb = -2 * np.ones(2)
ub = 2 * np.ones(2)
problem = pypesto.Problem(objective, lb, ub)
optimize_options = optimize.OptimizeOptions(allow_failed_starts=True)
# run optimization
result = optimize.minimize(
problem=problem,
optimizer=optimizer,
n_starts=5,
startpoint_method=pypesto.startpoint.uniform,
options=optimize_options
)
def create_optimizer(self):
config = self.config
if config is not None and 'pypesto' in config:
if 'optimizer' not in config['pypesto']:
return None
optimizers = {'ScipyOptimizer': ScipyOptimizer}
config_optimizer = config['pypesto']['optimizer']
if config_optimizer not in optimizers:
raise ValueError(f"Optimizer must be one of {optimizers}.")
if config_optimizer == 'ScipyOptimizer':
kwargs = {}
if 'method' in config['pypesto']:
kwargs['method'] = config['pypesto']['method']
if 'optimizer_options' in config['pypesto']:
kwargs['options'] = config['pypesto']['optimizer_options']
return ScipyOptimizer(**kwargs)
# TODO: add Dlib
return None