--random-state for optimzer to get reproducible results added

This commit is contained in:
hroff-1902 2019-04-23 21:18:52 +03:00
parent d3e956f7cc
commit a022b1a6c1
3 changed files with 24 additions and 1 deletions

View File

@ -315,6 +315,14 @@ class Arguments(object):
dest='print_all',
default=False
)
parser.add_argument(
'--random-state',
help='Set random state to some positive integer for reproducible hyperopt results.',
dest='hyperopt_random_state',
default=None,
type=Arguments.check_positive,
metavar='INT',
)
def _build_subcommands(self) -> None:
"""
@ -385,6 +393,16 @@ class Arguments(object):
return TimeRange(stype[0], stype[1], start, stop)
raise Exception('Incorrect syntax for timerange "%s"' % text)
@staticmethod
def check_positive(value) -> int:
try:
uint = int(value)
if uint <= 0:
raise ValueError
except:
raise argparse.ArgumentTypeError(f"{value} is invalid for this parameter, should be a positive integer value")
return uint
def scripts_options(self) -> None:
"""
Parses given arguments for scripts.

View File

@ -324,6 +324,10 @@ class Configuration(object):
config.update({'print_all': self.args.print_all})
logger.info('Parameter --print-all detected: %s', config.get('print_all'))
if 'hyperopt_random_state' in self.args and self.args.hyperopt_random_state is not None:
config.update({'hyperopt_random_state': self.args.hyperopt_random_state})
logger.info("Parameter --random-state detected: %s", config.get('hyperopt_random_state'))
return config
def _validate_config_schema(self, conf: Dict[str, Any]) -> Dict[str, Any]:

View File

@ -235,7 +235,8 @@ class Hyperopt(Backtesting):
base_estimator="ET",
acq_optimizer="auto",
n_initial_points=30,
acq_optimizer_kwargs={'n_jobs': cpu_count}
acq_optimizer_kwargs={'n_jobs': cpu_count},
random_state=self.config.get('hyperopt_random_state', None)
)
def run_optimizer_parallel(self, parallel, asked) -> List: