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

Transforms #355

Merged
merged 24 commits into from
Mar 1, 2024
Merged

Transforms #355

merged 24 commits into from
Mar 1, 2024

Conversation

bertiqwerty
Copy link
Contributor

@bertiqwerty bertiqwerty commented Feb 22, 2024

Implement Transforms

For instance, they they can be applied to steps in the step-wise strategy. This way you can for example change data or candidates the strategies for certain steps or restrict the domain.

@bertiqwerty bertiqwerty self-assigned this Feb 22, 2024
from bofire.data_models.domain.api import Domain


class Transform:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we do not need here a distinction between data model and functional model, as the transform does not need any non standard dependecies, or? So one can just implement it for the datamodel. The same could be done also for the conditions, or?

We should also have a loo here: https://github.com/facebook/Ax/tree/main/ax/modelbridge/transforms and think of making the transforms more prominent, as transforms of the domain, the candidates and the experiments could be also useful in other scenarios. Have a look for this to the PR of @Osburg, where he transform the complete domain between bound of -1 and 1. Having this kinds of transform, that could also be chained behind it each other could make sense, they would always take in the domain, experiments and candidates and return the transformed versions, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to data models as discussed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jduerholt can you have a look at the invalid/valid spec-stuff? I did something wrong and don't really get it.

@bertiqwerty bertiqwerty changed the title Step Transforms Transforms Feb 22, 2024
@R-M-Lee
Copy link
Contributor

R-M-Lee commented Feb 28, 2024

I took a quick look at this. I think that the name RemoveTransform is a little bit confusing because I would expect it to remove the transform rather than be a transform that removes something. What do you think of DropDataTransform or ExcludeTransform?

@bertiqwerty
Copy link
Contributor Author

I took a quick look at this. I think that the name RemoveTransform is a little bit confusing because I would expect it to remove the transform rather than be a transform that removes something. What do you think of DropDataTransform or ExcludeTransform?

Yes! As so often a great naming suggestion from you!

@bertiqwerty bertiqwerty marked this pull request as ready for review February 29, 2024 15:36
Copy link
Contributor

@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.

Hi Behrang,

only a few minor comments and one test is missing, namely where it is checked that the acutal drop data transfrom works and drops the correct data, so to say, testing of its functionality.

Best,

Johannes

from pydantic import Field, field_validator
from typing_extensions import Annotated

from bofire.data_models.base import BaseModel
from bofire.data_models.domain.api import Domain
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you have this extra class and not just put the abstract method in Condition?

Copy link
Contributor Author

@bertiqwerty bertiqwerty Mar 1, 2024

Choose a reason for hiding this comment

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

I prefer abstract classes to be really abstract and NOT to be mixed with data members or implementations.

[edit] not was missing[/edit]

bofire/strategies/stepwise/stepwise.py Outdated Show resolved Hide resolved
self.stratgies = [_map(s.strategy_data) for s in data_model.steps]
self.conditions = [s.condition for s in data_model.steps]
self.transforms = [
s.transform and transforms.map(s.transform) for s in data_model.steps
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the and doing? I do not get it :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the and doing? I do not get it :D

If s.transform is None we keep None. If it is not None the last value is evaluated and returned.

assert (None and 1) is None
assert (None or 1) == 1

https://en.wikipedia.org/wiki/Short-circuit_evaluation

bofire/strategies/stepwise/stepwise.py Outdated Show resolved Hide resolved
bofire/strategies/stepwise/stepwise.py Outdated Show resolved Hide resolved
bofire/strategies/stepwise/stepwise.py Outdated Show resolved Hide resolved
bofire/strategies/stepwise/stepwise.py Outdated Show resolved Hide resolved
bofire/strategies/stepwise/stepwise.py Outdated Show resolved Hide resolved
return domain

def untransform_experiments(self, experiments: pd.DataFrame) -> pd.DataFrame:
return experiments
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also opt for an untransform_candidates

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 only untransform candidates. And only the new candidates that have been proposed. For the other things, the inputs are the untransformed versions, no?

tests/bofire/conftest.py Show resolved Hide resolved
bertiqwerty and others added 2 commits March 1, 2024 11:48
Co-authored-by: Johannes P. Dürholt <[email protected]>
Co-authored-by: Johannes P. Dürholt <[email protected]>
@bertiqwerty
Copy link
Contributor Author

namely where it is checked that the acutal drop data transfrom works and drops the correct data, so to say, testing of its functionality.

There was a test in the stepwise-file. I moved it to a separate file and extended it.

@bertiqwerty bertiqwerty requested a review from jduerholt March 1, 2024 11:28
Copy link
Contributor

@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 good to me, last minor thing would be to not have test_transforms.py under tests/bofire/strategegies but in a new folder tests/bofire/stransforms.py so that we reflect the correct folder structure. If one is very strict we would also need the test_conditions in the data_models part of the test suite.

@bertiqwerty
Copy link
Contributor Author

Looks good to me, last minor thing would be to not have test_transforms.py under tests/bofire/strategegies but in a new folder tests/bofire/stransforms.py so that we reflect the correct folder structure. If one is very strict we would also need the test_conditions in the data_models part of the test suite.

Thanks for the review.

Since transforms are tight to the stepwise strategy I will leave the tests there. We can move them later.

@bertiqwerty bertiqwerty merged commit 7909654 into main Mar 1, 2024
10 checks passed
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.

3 participants