Seed hyperopt random_state if not passed

This commit is contained in:
hroff-1902 2019-12-12 03:12:28 +03:00
parent f44e3dc319
commit 6e778ad710

View File

@ -6,6 +6,7 @@ This module contains the hyperopt logic
import locale import locale
import logging import logging
import random
import sys import sys
import warnings import warnings
from collections import OrderedDict from collections import OrderedDict
@ -436,7 +437,7 @@ class Hyperopt:
acq_optimizer="auto", acq_optimizer="auto",
n_initial_points=INITIAL_POINTS, n_initial_points=INITIAL_POINTS,
acq_optimizer_kwargs={'n_jobs': cpu_count}, acq_optimizer_kwargs={'n_jobs': cpu_count},
random_state=self.config.get('hyperopt_random_state', None), random_state=self.random_state,
) )
def fix_optimizer_models_list(self): def fix_optimizer_models_list(self):
@ -475,7 +476,13 @@ class Hyperopt:
logger.info(f"Loaded {len(trials)} previous evaluations from disk.") logger.info(f"Loaded {len(trials)} previous evaluations from disk.")
return trials return trials
def _set_random_state(self, random_state: Optional[int]) -> int:
return random_state or random.randint(1, 2**32 - 1)
def start(self) -> None: def start(self) -> None:
self.random_state = self._set_random_state(self.config.get('hyperopt_random_state', None))
logger.info(f"Using optimizer random state: {self.random_state}")
data, timerange = self.backtesting.load_bt_data() data, timerange = self.backtesting.load_bt_data()
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data) preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)