Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of DoEStrategy data model class #448

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

jduerholt
Copy link
Contributor

This PR provides a draft for the restructured DoEStrategy.

The following things changed:

  • The objective is now criterion to prevent confusion with the objectives of the output features.
  • The former objectives like DOptimality are not anymore enums, but classes, for example DOptimalityCriterion. This allows for the clean implementation of criterion specific attributes.
  • The formula is now anymore a direct attribute of the DoEStrategy but instead an attribute of the criterion.

When the functional part of the DoE module is refactored, we should have a mapper which takes the criterion and domain and returns a functional criterion class which provides then the actual objective funtion for the actual ipopt optimizer.

On the long run, we can then also provide a common base class on the data model level for both the DoEStrategy and the SpaceFillingStrategy. In case of the latter one the only allowed criterion will then be the SpaceFillingCriterion which has no formula attribute.

@Osburg: What do you think?

@dlinzner-bcs dlinzner-bcs marked this pull request as ready for review December 4, 2024 15:02
@dlinzner-bcs
Copy link
Contributor

dlinzner-bcs commented Dec 4, 2024

@jduerholt @Osburg i made some changes. We still want to support the old interface with find_local_max_ipopt. For this I allowed mapping a criterion to the old enum. Is this a valid compromise? Update: We no longer support the old interface.

@dlinzner-bcs dlinzner-bcs self-requested a review December 12, 2024 12:14
@dlinzner-bcs
Copy link
Contributor

@jduerholt @Osburg This PR is now ready for merging. Do you approve?

@jduerholt
Copy link
Contributor Author

We first review :-) Thank you very much. I try to have a look at it on the weekend. @Osburg would be good if you also have a look.

@dlinzner-bcs dlinzner-bcs requested a review from Osburg December 12, 2024 13:00
@jduerholt
Copy link
Contributor Author

There are failing tests due to a new sklearn version, I already went into the rabbit hole. Will post an issue later.

Copy link
Collaborator

@Osburg Osburg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dlinzner-bcs Thanks!!! :)) <3 looks good to me, left some minor comments. Feel free to ignore them if they are not helpful.
Cheers, Aaron :)

@@ -83,6 +74,71 @@ def evaluate_jacobian(self, x: np.ndarray) -> np.ndarray:
def _evaluate_jacobian(self, x: np.ndarray) -> np.ndarray:
pass

@abstractmethod
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these functions needed in the Objective class? Since the SpaceFilling objective actually does not have to implement any of these functions, right? (The only function that is used for any objective is get_model_matrix() in the exit message find_local_max_ipopt() i think, but imo it is not necessary there as well...). What is your opinion?

@@ -493,19 +552,66 @@ def _convert_input_to_tensor(
)
return torch.tensor(X.values, requires_grad=requires_grad, **tkwargs)

def get_model_matrix(self, design: pd.DataFrame) -> pd.DataFrame:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could then also be removed

@@ -572,7 +199,7 @@ def find_local_max_ipopt(
if _ipopt_options[b"print_level"] > 12: # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this could be removed. The objective criterion can be viewed via the IPOPT output and any other criterion can also be calculated with little effort by creating another Objective. What do you think? :) --> then there is also no need anymore to implement get_model_matrix() for SpaceFilling.
Also the metrics(), g_optimality(), a_optimality(), d_optimality() functions in doe utils could be deleted then since they are not used anywhere else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks Aaron for the review :)

@jduerholt
Copy link
Contributor Author

Thanks @Osburg, I will finally have look tmr. Sorry @dlinzner-bcs !

@R-M-Lee
Copy link
Contributor

R-M-Lee commented Dec 17, 2024

why is the nbstripout precommit hook not being executed properly? The notebook output should not be there. Right now there are some images and outputs referencing local paths on someone's machine

edit: ah, never mind... we use nbstripout with the argument to keep outputs. But the warnings should still be removed I think

Copy link
Contributor Author

@jduerholt jduerholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks overall very good, I let some questions and I am open to also implement some of the mentioned points ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding this? We removed it during the hackathon in favor of having everything in the pyproject.toml.


objective: OptimalityCriterionEnum = OptimalityCriterionEnum.D_OPTIMALITY

transform_range: Optional[Bounds] = None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the transform_range gone?

n_experiments: Optional[int] = None,
delta: float = 1e-7,
n_experiments: int,
criterion: Optional[AnyOptimalityCriterion] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the criterion here optional? We always need one, or?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of this functional strategy here, and just map the data model of the SpaceFillingStrategy to the DoeStrategy in the mapper?

Copy link
Collaborator

@Osburg Osburg Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have liked to use the SpaceFillingStrategy as it is to generate the design space grid for the I-optimality criterion. To avoid circular imports it would be nice if the space filling strategy would be available indepent of the DoeStrategy (@dlinzner-bcs is it okay if I add a commit for the I-optimality - now compatible with your changes - criterion to this branch?).
Only if there are no good reasons against keeping it this way ofc @jduerholt .

edit: nvm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also test the optimality criteria data models for serialization and desirilization, should I implement this into this PR? One has to register a few new fixures for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants