--random-state for optimzer to get reproducible results added
This commit is contained in:
parent
d3e956f7cc
commit
a022b1a6c1
@ -315,6 +315,14 @@ class Arguments(object):
|
|||||||
dest='print_all',
|
dest='print_all',
|
||||||
default=False
|
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:
|
def _build_subcommands(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -385,6 +393,16 @@ class Arguments(object):
|
|||||||
return TimeRange(stype[0], stype[1], start, stop)
|
return TimeRange(stype[0], stype[1], start, stop)
|
||||||
raise Exception('Incorrect syntax for timerange "%s"' % text)
|
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:
|
def scripts_options(self) -> None:
|
||||||
"""
|
"""
|
||||||
Parses given arguments for scripts.
|
Parses given arguments for scripts.
|
||||||
|
@ -324,6 +324,10 @@ class Configuration(object):
|
|||||||
config.update({'print_all': self.args.print_all})
|
config.update({'print_all': self.args.print_all})
|
||||||
logger.info('Parameter --print-all detected: %s', config.get('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
|
return config
|
||||||
|
|
||||||
def _validate_config_schema(self, conf: Dict[str, Any]) -> Dict[str, Any]:
|
def _validate_config_schema(self, conf: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
@ -235,7 +235,8 @@ class Hyperopt(Backtesting):
|
|||||||
base_estimator="ET",
|
base_estimator="ET",
|
||||||
acq_optimizer="auto",
|
acq_optimizer="auto",
|
||||||
n_initial_points=30,
|
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:
|
def run_optimizer_parallel(self, parallel, asked) -> List:
|
||||||
|
Loading…
Reference in New Issue
Block a user