parameterspace.transformations.zero_one
ZeroOneFloat (BaseTransformation)
Maps a bounded interval to [0, 1] via a linear transformation.
Source code in parameterspace/transformations/zero_one.py
class ZeroOneFloat(BaseTransformation):
"""Maps a bounded interval to [0, 1] via a linear transformation."""
@store_init_arguments
def __init__(self, bounds: Optional[Tuple]):
super().__init__(bounds, (0, 1))
self.interval_size = bounds[1] - bounds[0]
def inverse(self, numerical_value: float) -> float:
return float(
np.clip(
self.input_bounds[0] + numerical_value * (self.interval_size),
self.input_bounds[0],
self.input_bounds[1],
)
)
def __call__(self, value: Any) -> float:
return float((value - self.input_bounds[0]) / self.interval_size)
def __eq__(self, other):
return np.allclose(self.input_bounds, other.input_bounds)
def jacobian_factor(self, numerical_value: float) -> float:
return 1.0 / self.interval_size
inverse(self, numerical_value)
Convert the numerical representation back to the true value with the proper type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numerical_value |
float |
Transformed/Numerical representation of a value. |
required |
Returns:
Type | Description |
---|---|
float |
The value corresponding to the given value. Type depends no the kind of transformation. |
Source code in parameterspace/transformations/zero_one.py
def inverse(self, numerical_value: float) -> float:
return float(
np.clip(
self.input_bounds[0] + numerical_value * (self.interval_size),
self.input_bounds[0],
self.input_bounds[1],
)
)
jacobian_factor(self, numerical_value)
Factor to correct the likelihood based on the non-linear transformation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numerical_value |
float |
Transformed/Numerical representation of a value. |
required |
Returns:
Type | Description |
---|---|
float |
Jacobian factor to properly transform the likelihood. |
Source code in parameterspace/transformations/zero_one.py
def jacobian_factor(self, numerical_value: float) -> float:
return 1.0 / self.interval_size
ZeroOneInteger (BaseTransformation)
Maps a bounded interval of integers to [0, 1] via a linear transformation.
Source code in parameterspace/transformations/zero_one.py
class ZeroOneInteger(BaseTransformation):
"""Maps a bounded interval of integers to [0, 1] via a linear transformation."""
@store_init_arguments
def __init__(self, bounds: Optional[Tuple]):
super().__init__(bounds, (0, 1))
self.interval_size = bounds[1] - bounds[0] + 1
def inverse(self, numerical_value: float) -> int:
return int(
np.clip(
np.around(
self.input_bounds[0] - 0.5 + numerical_value * (self.interval_size)
),
self.input_bounds[0],
self.input_bounds[1],
)
)
def __call__(self, value: Any) -> float:
return float((value - self.input_bounds[0] + 0.5) / self.interval_size)
def __eq__(self, other):
return np.allclose(self.input_bounds, other.input_bounds)
def jacobian_factor(self, numerical_value: float) -> float:
return 1.0 / self.interval_size
inverse(self, numerical_value)
Convert the numerical representation back to the true value with the proper type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numerical_value |
float |
Transformed/Numerical representation of a value. |
required |
Returns:
Type | Description |
---|---|
int |
The value corresponding to the given value. Type depends no the kind of transformation. |
Source code in parameterspace/transformations/zero_one.py
def inverse(self, numerical_value: float) -> int:
return int(
np.clip(
np.around(
self.input_bounds[0] - 0.5 + numerical_value * (self.interval_size)
),
self.input_bounds[0],
self.input_bounds[1],
)
)
jacobian_factor(self, numerical_value)
Factor to correct the likelihood based on the non-linear transformation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numerical_value |
float |
Transformed/Numerical representation of a value. |
required |
Returns:
Type | Description |
---|---|
float |
Jacobian factor to properly transform the likelihood. |
Source code in parameterspace/transformations/zero_one.py
def jacobian_factor(self, numerical_value: float) -> float:
return 1.0 / self.interval_size