Skip to content

Commit bdfdc69

Browse files
committed
Reduce memory footprint on optimizer, merge kernc#884
1 parent bbf5830 commit bdfdc69

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

backtesting/backtesting.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ def _optimize_skopt() -> Union[pd.Series,
15361536
# Avoid recomputing re-evaluations:
15371537
# "The objective has been evaluated at this point before."
15381538
# https://github.com/scikit-optimize/scikit-optimize/issues/302
1539-
memoized_run = lru_cache()(lambda tup: self.run(**dict(tup)))
1539+
memoized_run = lru_cache()(lambda tup: -maximize(self.run(**dict(tup))))
15401540

15411541
# np.inf/np.nan breaks sklearn, np.finfo(float).max breaks skopt.plots.plot_objective
15421542
INVALID = 1e300
@@ -1549,8 +1549,7 @@ def objective_function(**params):
15491549
# TODO: Adjust after https://github.com/scikit-optimize/scikit-optimize/pull/971
15501550
if not constraint(AttrDict(params)):
15511551
return INVALID
1552-
res = memoized_run(tuple(params.items()))
1553-
value = -maximize(res)
1552+
value = memoized_run(tuple(params.items()))
15541553
if np.isnan(value):
15551554
return INVALID
15561555
return value

0 commit comments

Comments
 (0)