Skip to content

Commit

Permalink
Allowing out-of-search-space samples through cli, resume and default
Browse files Browse the repository at this point in the history
This change just gives the user more freedom over which data to input. For real world cases this can be useful. In the future more safety features will be added in to make sure that this is what the user wants as well as go allow the same freedom through the non-cli interface.
  • Loading branch information
ErikOrm committed Aug 30, 2023
1 parent b6e5760 commit 60d5ad3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
23 changes: 7 additions & 16 deletions hypermapper/param/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ def convert(
- the converted value
"""
if from_type in ["string", "internal"]:
intermediate_value = int(input_value)
intermediate_value = np.float64(input_value)
elif from_type == "01":
intermediate_value = (
int(
np.float64(
np.floor(input_value * (self.get_max() + 0.999999 - self.get_min()))
)
+ self.get_min()
Expand All @@ -369,6 +369,8 @@ def convert(
intermediate_value = input_value

if to_type == "string":
if abs(np.round(intermediate_value) - intermediate_value) < 1e-8:
return f"{int(np.round(intermediate_value))}"
return f"{intermediate_value}"
elif to_type == "01":
return (intermediate_value - self.get_min()) / (
Expand Down Expand Up @@ -521,21 +523,10 @@ def convert(
]
else:
intermediate_value = input_value
# this is a fix to safeguard against numerical imprecision
if intermediate_value not in self.values:
closest_value = min(
self.values, key=lambda x: abs(x - intermediate_value)
)
if abs(closest_value - intermediate_value) > 1e-6:
raise Exception(
"The input value in OrdinalParameter.convert() is not in the list of values."
f" Value: {intermediate_value} closest value: {closest_value}"
)
intermediate_value = closest_value


if to_type == "string":
if self.int_ordinal:
return f"{int(intermediate_value)}"
if self.int_ordinal and abs(intermediate_value - np.round(intermediate_value)) < 1e-8:
return f"{int(np.round(intermediate_value))}"
else:
return f"{intermediate_value}"
elif to_type == "01":
Expand Down
15 changes: 12 additions & 3 deletions hypermapper/param/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ def get_default_configuration(self):
return None
default_configuration = torch.tensor([default_configuration])
if self.conditional_space and not self.evaluate(default_configuration):
sys.stdout.write_to_logfile("Warning: infeasible default configuration.")
return None
sys.stdout.write_to_logfile("Warning: the default configuration is infeasible. Are you sure you want this?.")
return default_configuration
return default_configuration

def convert(
Expand Down Expand Up @@ -625,9 +625,14 @@ def run_configurations_client_server(
metric_indices = [
parameters_header.index(name) for name in self.metric_names
]
param_indices = [
parameters_header.index(name) for name in self.parameter_names
]
new_configurations = []
metrics = []
feasible = []
for row in parameters_data:
new_configurations.append([row[p] for p in param_indices])
metrics.append([float(row[m]) for m in metric_indices])
if self.enable_feasible_predictor:
feasible.append(
Expand All @@ -644,8 +649,12 @@ def run_configurations_client_server(
print("Failed to parse received message:")
print(ve)
raise SystemError

new_configurations = self.convert(
new_configurations, "string", "internal"
)
timestamps = torch.tensor([self.current_milli_time()] * len(configurations))
new_data_array = DataArray(configurations, metrics, timestamps, feasible)
new_data_array = DataArray(new_configurations, metrics, timestamps, feasible)
write_data_array(self, new_data_array, output_data_file)
return new_data_array

Expand Down

0 comments on commit 60d5ad3

Please sign in to comment.