Skip to content

Commit

Permalink
remove math.inf from data model (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
jduerholt authored Mar 27, 2024
1 parent feec334 commit 8fca164
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions bofire/benchmarks/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def __init__(self, locality_factor: Optional[float] = None, **kwargs) -> None:
0.5 * locality_factor,
)
if locality_factor is not None
else (math.inf, math.inf)
else None
),
),
ContinuousInput(
Expand All @@ -246,7 +246,7 @@ def __init__(self, locality_factor: Optional[float] = None, **kwargs) -> None:
1.5 * locality_factor,
)
if locality_factor is not None
else (math.inf, math.inf)
else None
),
),
]
Expand Down
16 changes: 10 additions & 6 deletions bofire/data_models/features/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class ContinuousInput(NumericalInput):
bounds (Tuple[float, float]): A tuple that stores the lower and upper bound of the feature.
stepsize (float, optional): Float indicating the allowed stepsize between lower and upper. Defaults to None.
local_relative_bounds (Tuple[float, float], optional): A tuple that stores the lower and upper bounds relative to a reference value.
Defaults to (math.inf, math.inf).
Defaults to None.
"""

type: Literal["ContinuousInput"] = "ContinuousInput"
order_id: ClassVar[int] = 1

bounds: Tuple[float, float]
local_relative_bounds: Tuple[
Annotated[float, Field(gt=0)], Annotated[float, Field(gt=0)]
] = (math.inf, math.inf)
local_relative_bounds: Optional[
Tuple[Annotated[float, Field(gt=0)], Annotated[float, Field(gt=0)]]
] = None
stepsize: Optional[float] = None

@property
Expand Down Expand Up @@ -154,14 +154,18 @@ def get_bounds(
if reference_value is None or self.is_fixed():
return [self.lower_bound], [self.upper_bound]
else:
local_relative_bounds = self.local_relative_bounds or (
math.inf,
math.inf,
)
return [
max(
reference_value - self.local_relative_bounds[0],
reference_value - local_relative_bounds[0],
self.lower_bound,
)
], [
min(
reference_value + self.local_relative_bounds[1],
reference_value + local_relative_bounds[1],
self.upper_bound,
)
]
Expand Down
3 changes: 1 addition & 2 deletions bofire/data_models/strategies/shortest_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import math
from typing import Annotated, Dict, Literal, Type, Union

import pandas as pd
Expand Down Expand Up @@ -30,7 +29,7 @@ def has_local_search_region(domain: Domain) -> bool:
is_lsr = False
for feat in domain.inputs.get(ContinuousInput):
assert isinstance(feat, ContinuousInput)
if feat.local_relative_bounds != (math.inf, math.inf):
if feat.local_relative_bounds is not None:
is_lsr = True
return is_lsr

Expand Down

0 comments on commit 8fca164

Please sign in to comment.