in scripts/vw-hyperopt.py [0:0]
def _process_vw_argument(self, arg, value, algorithm):
try:
distr_part = self.distr_pattern.findall(value)[0]
except IndexError:
distr_part = ""
range_part = self.range_pattern.findall(value)[0]
is_continuous = ".." in range_part
ocd = self.only_continuous.findall(value)
if not is_continuous and len(ocd) > 0 and ocd[0] != "":
raise ValueError(
(
"Need a range instead of a list of discrete values to define "
"uniform or log-uniform distribution. "
"Please, use [min..max]%s form"
)
% (distr_part)
)
if is_continuous and arg == "-q":
raise ValueError(
(
"You must directly specify namespaces for quadratic features "
"as a list of values, not as a parametric distribution"
)
)
hp_choice_name = "_".join([algorithm, arg.replace("-", "")])
try_omit_zero = "O" in distr_part
distr_part = distr_part.replace("O", "")
if is_continuous:
vmin, vmax = [float(i) for i in range_part.split("..")]
if distr_part == "L":
distrib = hp.loguniform(hp_choice_name, log(vmin), log(vmax))
elif distr_part == "":
distrib = hp.uniform(hp_choice_name, vmin, vmax)
elif distr_part == "I":
distrib = hp.quniform(hp_choice_name, vmin, vmax, 1)
elif distr_part in {"LI", "IL"}:
distrib = hp.qloguniform(hp_choice_name, log(vmin), log(vmax), 1)
else:
raise ValueError("Cannot recognize distribution: %s" % (distr_part))
else:
possible_values = range_part.split(",")
if arg == "-q":
possible_values = [v.replace("+", " -q ") for v in possible_values]
distrib = hp.choice(hp_choice_name, possible_values)
if try_omit_zero:
hp_choice_name_outer = hp_choice_name + "_outer"
distrib = hp.choice(hp_choice_name_outer, ["omit", distrib])
return distrib