Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_trace_chi2_schi2(self):
self.history_options = HistoryOptions(
trace_record=True,
trace_record_chi2=True,
trace_record_schi2=True,
)
self.check_history()
def test_trace_all(self):
self.obj = rosen_for_sensi(
max_sensi_order=2,
integrated=True
)['obj']
self.history_options = HistoryOptions(
trace_record=True,
trace_record_grad=True,
trace_record_hess=True,
trace_record_res=True,
trace_record_sres=True,
trace_record_chi2=True,
trace_record_schi2=True,
)
self.fix_pars = False
self.check_history()
def test_trace_grad_integrated(self):
self.obj = rosen_for_sensi(
max_sensi_order=2,
integrated=True
)['obj']
self.history_options = HistoryOptions(
trace_record=True,
trace_record_grad=True,
trace_record_hess=False,
)
self.check_history()
def test_trace_grad(self):
self.history_options = HistoryOptions(
trace_record=True,
trace_record_grad=True,
)
self.check_history()
def test_trace_grad(self):
self.obj = rosen_for_sensi(
max_sensi_order=2,
integrated=False
)['obj']
self.history_options = HistoryOptions(
trace_record=True,
trace_record_grad=True,
trace_record_hess=False,
)
self.check_history()
def test_trace_schi2(self):
self.history_options = HistoryOptions(
trace_record=True,
trace_record_chi2=True,
trace_record_schi2=False,
)
self.check_history()
def test_trace_chi2(self):
self.history_options = HistoryOptions(
trace_record=True,
trace_record_chi2=True,
trace_record_schi2=False,
)
self.check_history()
# optimizer
if optimizer is None:
optimizer = ScipyOptimizer()
# startpoint method
if startpoint_method is None:
startpoint_method = uniform
# check options
if options is None:
options = OptimizeOptions()
options = OptimizeOptions.assert_instance(options)
if history_options is None:
history_options = HistoryOptions()
history_options = HistoryOptions.assert_instance(history_options)
# assign startpoints
startpoints = assign_startpoints(
n_starts=n_starts, startpoint_method=startpoint_method,
problem=problem, options=options)
if ids is None:
ids = [str(j) for j in range(n_starts)]
if len(ids) != n_starts:
raise AssertionError("Number of starts and ids must coincide.")
# prepare result
if result is None:
result = Result(problem)
# engine
# optimizer
if optimizer is None:
optimizer = ScipyOptimizer()
# startpoint method
if startpoint_method is None:
startpoint_method = uniform
# check options
if options is None:
options = OptimizeOptions()
options = OptimizeOptions.assert_instance(options)
if history_options is None:
history_options = HistoryOptions()
history_options = HistoryOptions.assert_instance(history_options)
# assign startpoints
startpoints = assign_startpoints(
n_starts=n_starts, startpoint_method=startpoint_method,
problem=problem, options=options)
if ids is None:
ids = [str(j) for j in range(n_starts)]
if len(ids) != n_starts:
raise AssertionError("Number of starts and ids must coincide.")
# prepare result
if result is None:
result = Result(problem)
def wrapped_minimize(self, problem, x0, id, allow_failed_starts,
history_options=None):
objective = problem.objective
# initialize the objective
objective.initialize()
# create optimizer history
if history_options is None:
history_options = HistoryOptions()
history = history_options.create_history(
id=id, x_names=[problem.x_names[ix]
for ix in problem.x_free_indices])
optimizer_history = OptimizerHistory(history=history, x0=x0)
# plug in history for the objective to record it
objective.history = optimizer_history
# perform the actual minimization
try:
result = minimize(self, problem, x0, id, history_options)
objective.history.finalize()
result.id = id
except Exception as err:
if allow_failed_starts:
logger.error(f'start {id} failed: {err}')