Skip to content

Commit

Permalink
bugfix output parameter names with optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
mpvanderschelling committed Dec 5, 2023
1 parent ddda5e7 commit 506d0ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/f3dasm/_src/design/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def names(self) -> List[str]:
"""Return a list of the names of the parameters"""
return list(self.keys())

@property
def output_names(self) -> List[str]:
"""Return a list of the names of the output parameters"""
return list(self.output_space.keys())

@property
def continuous(self) -> Domain:
"""Returns a Domain object containing only the continuous parameters"""
Expand Down Expand Up @@ -748,6 +753,7 @@ def _check_output(self, names: List[str]):
"""
for output_name in names:
if not self.is_in_output(output_name):
print(f"Output {output_name} not in domain. Adding it.")
self.add_output(output_name, to_disk=False)

def is_in_output(self, output_name: str) -> bool:
Expand Down Expand Up @@ -824,7 +830,7 @@ def _domain_factory(domain: Domain | DictConfig | None,
input_data: pd.DataFrame,
output_data: pd.DataFrame) -> Domain:
if isinstance(domain, Domain):
domain._check_output(output_data.columns)
# domain._check_output(output_data.columns)
return domain

elif isinstance(domain, (Path, str)):
Expand Down
23 changes: 16 additions & 7 deletions src/f3dasm/_src/experimentdata/experimentdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def __init__(self,
job_value = Status.FINISHED

self.domain = _domain_factory(
domain, self._input_data.to_dataframe(),
self._output_data.to_dataframe())
domain=domain, input_data=self._input_data.to_dataframe(),
output_data=self._output_data.to_dataframe())

# Create empty input_data from domain if input_data is empty
if self._input_data.is_empty():
Expand All @@ -139,6 +139,9 @@ def __init__(self,
if not self._input_data.has_columnnames(self.domain.names):
self._input_data.set_columnnames(self.domain.names)

if not self._output_data.has_columnnames(self.domain.output_names):
self._output_data.set_columnnames(self.domain.output_names)

# For backwards compatibility; if the output_data has
# only one column, rename it to 'y'
if self._output_data.names == [0]:
Expand Down Expand Up @@ -1220,13 +1223,19 @@ def _iterate_scipy(self, optimizer: Optimizer,
# n_data_before_iterate + iterations amount of elements!
# If x_new is empty, repeat best x0 to fill up total iteration
if len(self) == n_data_before_iterate:
repeated_last_element = self.get_n_best_output(
n_samples=1).to_numpy()[0].ravel()
repeated_x, repeated_y = self.get_n_best_output(
n_samples=1).to_numpy()
# repeated_last_element = self.get_n_best_output(
# n_samples=1).to_numpy()[0].ravel()

for repetition in range(iterations):
self._add_experiments(
ExperimentSample.from_numpy(repeated_last_element,
domain=self.domain))
# self._add_experiments(
# ExperimentSample.from_numpy(repeated_last_element,
# domain=self.domain))

self.add(
domain=self.domain, input_data=repeated_x,
output_data=repeated_y)

# Repeat last iteration to fill up total iteration
if len(self) < n_data_before_iterate + iterations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def run_algorithm(self, iterations: int, data_generator: DataGenerator):
"""

def fun(x):
sample: ExperimentSample = data_generator._run(x)
sample: ExperimentSample = data_generator._run(
x, domain=self.domain)
_, y = sample.to_numpy()
return float(y)

Expand All @@ -63,3 +64,5 @@ def fun(x):
bounds=self.domain.get_bounds(),
tol=0.0,
)

# self.data.evaluate(data_generator=data_generator)

0 comments on commit 506d0ae

Please sign in to comment.