Skip to content

Conversation

@jduerholt
Copy link
Collaborator

Motivation

This PR refers to #2879. It adds a new input transform that transforms a categorical degree of freedom encoded a an integer into some kind of vector based description. This could be for example a one-hot encoding, but also a descriptor encoding as it is often used in chemistry. It adds the possibility to use the alternating acqf optimizer also with surrogates that do not treat categoricals as integer based values. For example one could then also use a SAAS GP with the mixed alternating acqf optimizer and treat the categoricals under the hood as one-hots.

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

Unit tests, most of them are implemented (also to demonstrate the functionality), the ones which check the equality between transforms and correct behavior of transform on train etc. are still missing. My plan is to add them after a first feedback after a first review.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jul 1, 2025
@codecov
Copy link

codecov bot commented Jul 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4e6079f) to head (ecbfb2d).
⚠️ Report is 46 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #2907    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          212       216     +4     
  Lines        19778     20285   +507     
==========================================
+ Hits         19778     20285   +507     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jduerholt
Copy link
Collaborator Author

@saitcakmak @Balandat any thoughts on this? It would be totally fine for me, if you say that you do not see this functionality directly in botorch. Then I would integrate it into our codebase, which is also totally fine ;)

Copy link
Contributor

@Balandat Balandat left a comment

Choose a reason for hiding this comment

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

The implementation seems reasonable to me. I'd be curious to see a concrete example using this end-to-end, including fitting a model and optimizing the acquisition function.

Similar to @saitcakmak , I would also be curious about how this compares against using a kernel that may work on the categoricals directly.

Comment on lines 1629 to 1631
"""Transform categorical parameters from an integer representation
to a vector based representation like one-hot encoding or a descriptor
encoding.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to have a description of how the columns in the output of the transform are organized. Ideally there would be a concrete example in the docstring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added an example ;)

Args:
dim: The dimension of the numerically encoded input.
categorical_features: A dictionary mapping the index of each
Copy link
Contributor

Choose a reason for hiding this comment

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

this arg name could be more descriptive, e.g. numeric_cardinality or sth like that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I was naming it like this as it also called like this in the related OneHotToNumeric transform. What do you think about categorical_features_cardinality?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm yeah we should keep things consistent with OneHotToNumeric. I don't think the arg name is ideal (cc @sdaulton) but I don't know if it warrants changing things in OneHotToNumeric and having to deal with backward compatibility issues. So this seems ok to me.

@jduerholt
Copy link
Collaborator Author

Thanks for the review, I will go over it and adapt accordingly. Best, Johannes

@jduerholt
Copy link
Collaborator Author

Hi @Balandat,

I have now implemented all your suggestions besides the one regarding the name, what do you think about my proposal there?

Best,

Johannes

@jduerholt jduerholt requested a review from Balandat August 12, 2025 07:54
Copy link
Contributor

@Balandat Balandat left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great. A number of minor nits, happy to merge once updated.

Args:
dim: The dimension of the numerically encoded input.
categorical_features: A dictionary mapping the index of each
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm yeah we should keep things consistent with OneHotToNumeric. I don't think the arg name is ideal (cc @sdaulton) but I don't know if it warrants changing things in OneHotToNumeric and having to deal with backward compatibility issues. So this seems ok to me.

jduerholt and others added 3 commits August 12, 2025 15:17
Co-authored-by: Max Balandat <Balandat@users.noreply.github.com>
@jduerholt
Copy link
Collaborator Author

@Balandat: Should be done now ;)

@facebook-github-bot
Copy link
Contributor

@Balandat has imported this pull request. If you are a Meta employee, you can view this in D80088225.

@facebook-github-bot
Copy link
Contributor

@Balandat merged this pull request in cd77978.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants