def clean_start_config(start_config: dict, config: dict) -> dict: clean_start = {} for k, v in unpack_config(start_config).items(): if k in config: if type(config[k]) == ray.tune.sample.Float or type( config[k]) == ray.tune.sample.Integer: clean_start[k] = min(max(v, config['ranges'][k][0]), config['ranges'][k][1]) return clean_start
def get_expanded_ranges(config: dict) -> dict: updated_ranges = OrderedDict() unpacked = unpack_config(get_template_live_config()) for k0 in unpacked: if '£' in k0 or k0 in config['ranges']: for k1 in config['ranges']: if k1 in k0: updated_ranges[k0] = config['ranges'][k1] if 'pbr_limit' in k0: updated_ranges[k0] = [ updated_ranges[k0][0], min(updated_ranges[k0][1], config['max_leverage']) ] return updated_ranges
def create_config(config: dict) -> dict: updated_ranges = get_expanded_ranges(config) template = get_template_live_config() template['long']['enabled'] = config['do_long'] template['shrt']['enabled'] = config['do_shrt'] unpacked = unpack_config(template) for k in updated_ranges: side = 'long' if 'long' in k else ('shrt' if 'shrt' in k else '') if updated_ranges[k][0] != updated_ranges[k][1] and ( not side or config[f'do_{side}']): unpacked[k] = tune.uniform(updated_ranges[k][0], updated_ranges[k][1]) else: unpacked[k] = updated_ranges[k][0] return {**config, **unpacked, **{'ranges': updated_ranges}}
def config_to_xs(self, config): xs = np.zeros(len(self.bounds[0])) unpacked = unpack_config(config) for i, k in enumerate(self.expanded_ranges): xs[i] = unpacked[k] return xs
def config_to_xs(self, config): unpacked = unpack_config(config) return [unpacked[k] for k in self.xs_conf_map]
def xs_to_config(self, xs): config = unpack_config(self.base_config.copy()) for i, x in enumerate(xs): config[self.xs_conf_map[i]] = x return pack_config(config)