diff --git a/src/f3dasm/_src/design/domain.py b/src/f3dasm/_src/design/domain.py index a4d9a030..b4a6b745 100644 --- a/src/f3dasm/_src/design/domain.py +++ b/src/f3dasm/_src/design/domain.py @@ -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""" @@ -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: @@ -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)): diff --git a/src/f3dasm/_src/experimentdata/experimentdata.py b/src/f3dasm/_src/experimentdata/experimentdata.py index 30f4bfe4..5ae1f1c6 100644 --- a/src/f3dasm/_src/experimentdata/experimentdata.py +++ b/src/f3dasm/_src/experimentdata/experimentdata.py @@ -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(): @@ -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]: @@ -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: diff --git a/src/f3dasm/_src/optimization/adapters/scipy_implementations.py b/src/f3dasm/_src/optimization/adapters/scipy_implementations.py index f0566325..d2d4273a 100644 --- a/src/f3dasm/_src/optimization/adapters/scipy_implementations.py +++ b/src/f3dasm/_src/optimization/adapters/scipy_implementations.py @@ -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) @@ -63,3 +64,5 @@ def fun(x): bounds=self.domain.get_bounds(), tol=0.0, ) + + # self.data.evaluate(data_generator=data_generator)