-
Notifications
You must be signed in to change notification settings - Fork 89
feat: add unconstrained hyperparameter #263
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
73c95a2
feat: add target modules hyperparameter and use it in quanto
gsprochette 731b716
refactor: change target modules usage to map function
gsprochette 3f7dfdd
fix: add attribute name in target modules map
gsprochette deafe8f
docs: remove docs to merge separately
gsprochette 63e4bb4
fix: improve names
gsprochette e2f799f
fix: typos
gsprochette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Copyright 2025 - Pruna AI GmbH. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from ConfigSpace import CategoricalHyperparameter, Constant | ||
| from typing_extensions import override | ||
|
|
||
|
|
||
| class Boolean(CategoricalHyperparameter): | ||
|
gsprochette marked this conversation as resolved.
Outdated
|
||
| """ | ||
| Represents a boolean hyperparameter with choices True and False. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| name : str | ||
| The name of the hyperparameter. | ||
| default : bool | ||
| The default value of the hyperparameter. | ||
| meta : Any | ||
| The metadata for the hyperparameter. | ||
| """ | ||
|
|
||
| def __init__(self, name: str, default: bool = False, meta: Any = dict()) -> None: | ||
| super().__init__(name, choices=[True, False], default_value=default, meta=meta) | ||
|
|
||
| def __new__(cls, name: str, default: bool = False, meta: Any = None) -> CategoricalHyperparameter: # type: ignore | ||
| """Create a new boolean hyperparameter.""" | ||
| return CategoricalHyperparameter(name, choices=[True, False], default_value=default, meta=meta) | ||
|
|
||
|
|
||
| class UnconstrainedHyperparameter(Constant): | ||
| """ | ||
| Represents a hyperparameter that is unconstrained and can be set to any value by the user. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| name : str | ||
| The name of the hyperparameter. | ||
| default_value : Any | ||
| The default value of the hyperparameter. | ||
| meta : Any | ||
| The metadata for the hyperparameter. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| name: str, | ||
| default_value: Any = None, | ||
| meta: Any = None, | ||
| ) -> None: | ||
| super().__init__(name, default_value, meta) | ||
|
|
||
| @override | ||
| def legal_value(self, value): # numpydoc ignore=GL08 | ||
|
gsprochette marked this conversation as resolved.
Outdated
|
||
| """ | ||
| Check if a value is legal for this hyperparameter. | ||
|
|
||
| This hyperparameter is unconstrained and can be set to any value by the user. | ||
| Therefore, this method always returns `True` as long as the format is accepted | ||
| by ConfigSpace. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| value : Any | ||
| The value to check. | ||
|
|
||
| Returns | ||
| ------- | ||
| bool or numpy.ndarray | ||
| `True` if the value is legal, `False` otherwise. If `value` is an array, | ||
| a boolean mask of legal values is returned. | ||
| """ | ||
| # edit the internal state of the Constant to allow for the new value | ||
| self._contains_sequence_as_value = isinstance(value, (list, tuple)) | ||
| self._transformer.value = value | ||
| # we still run the super method which should return True, to make sure internal values | ||
| # are correctly updated | ||
| return super().legal_value(value) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.