Converters
Contents
Converters
Converters are Addons for:ref:sp and Variables, they allow to convert points into another format (e.g. mixed to continuous). Each Variables must have their own converter implemented, as well as the Search space so it can convert points according each Variables.
from zellij.core import IntVar, ArrayVar, DiscreteSearchspace, Loss
from zellij.core import MockModel
from zellij.utils.converters import IntMinmax,ArrayMinmax, Continuous
lf = Loss()(MockModel())
sp = DiscreteSearchspace(ArrayVar(
IntVar("a",-5,5, to_continuous=IntMinmax()),
IntVar("b",-5,5, to_continuous=IntMinmax()),
to_continuous=ArrayMinmax()),
lf,
to_continuous=Continuous())
point = sp.random_point(1)
print(point)
float_points = sp.to_continuous.convert([[-5,-5],[0,0],point,[5,5]])
print(float_points)
int_points = sp.to_continuous.reverse(float_points)
print(int_points)
To continuous
- class Continuous(search_space=None)[source]
Bases:
zellij.core.addons.ConverterConvert Variables of a Search space to continuous. to_continuous addon must be implemented for each Variables.
- Parameters
search_space (Search space) – Targeted Search space.
- target
Targeted Search space.
- Type
- convert(self, points, sub_values=False)[source]
Convert given points from mixed to continuous
- Parameters
points ({list[list[{int, float, str}, {int, float, str}...], ...], list[list[float, float...], ...]}) – List of points to convert
sub_values (boolean, default=True) – If the search space is a subspace and if True, uses the original values to convert, else uses its own bounds. See Search space
- Returns
points – List of converted points. Points are list of float if converted to continuous.
- Return type
{list[list[{int, float, str}, {int, float, str}…], …], list[list[float, float…], …]}
- reverse(self, points, sub_values=False)[source]
Convert given points from continuous to mixed
- Parameters
points ({list[list[{int, float, str}, {int, float, str}...], ...], list[list[float, float...], ...]}) – List of points to convert
sub_values (boolean, default=True) – If the search space is a subspace and if True, uses the original values to convert, else uses its own bounds. See Search space
- Returns
points – List of converted points. Points are list of float if converted to continuous.
- Return type
{list[list[{int, float, str}, {int, float, str}…], …], list[list[float, float…], …]}
MinMax
- class ArrayMinmax(variable=None)[source]
Bases:
zellij.core.addons.VarConverterVariable Addon used when elements of the array must be converted to continous.
- Parameters
variable (ArrayVar) – Targeted ArrayVar.
- variable
Targeted ArrayVar.
- Type
ArrayVar
- convert(value)[source]
- reverse(value)[source]
- class FloatMinmax(variable=None)[source]
Bases:
zellij.core.addons.VarConverterConvert the value of a FloatVar, using
.Reverse: 
- convert(value)[source]
- reverse(value)[source]
- class IntMinmax(variable=None)[source]
Bases:
zellij.core.addons.VarConverterConvert the value of an IntVar, using
.Reverse: 
- convert(value)[source]
- reverse(value)[source]
To discrete
- class ArrayBinning(variable=None)[source]
Bases:
zellij.core.addons.VarConverterVariable Addon used when elements of the array must be converted to discrete. When binning some information can be lost.
- Parameters
variable (ArrayVar) – Targeted ArrayVar.
- variable
Targeted ArrayVar.
- Type
ArrayVar
- convert(value)[source]
- reverse(value)[source]
- class FloatBinning(K, variable=None)[source]
Bases:
zellij.core.addons.VarConverterConvert a value from an FloatVar using binning between its upper and lower bounds. Reversing a converted value will not return the initial value. When binning some information can be lost. here the decimal part of the float number.
- convert(value)[source]
- reverse(value)[source]
- class IntBinning(K, variable=None)[source]
Bases:
zellij.core.addons.VarConverterIntMinmax
Convert a value from an IntVar using binning between its upper and lower bounds. Reversing a converted value will not return the initial value. When binning some information can be lost.
- convert(value)[source]
- reverse(value)[source]
- class CatBinning(variable=None)[source]
Bases:
zellij.core.addons.VarConverterCatMinmax
Convert the value of a CatVar to its corresponding index in the features list.
- convert(value)[source]
- reverse(value)[source]
- class ConstantBinning(variable=None)[source]
Bases:
zellij.core.addons.VarConverterConstantMinmax
Convert the value of a Constant.
Reverse:
.- convert(value)[source]
- reverse(value)[source]
Binning
- class Discrete(search_space=None, K=10)[source]
Bases:
zellij.core.addons.ConverterConvert Variables of a Search space to discrete. to_discrete addon must be implemented for each Variables.
- Parameters
search_space (Search space) – Targeted Search space.
- target
Targeted Search space.
- Type
- convert(self, points, sub_values=False)[source]
Convert given points from mixed to discrete
- Parameters
points ({list[list[{int, float, str}, {int, float, str}...], ...],list[list[float, float...], ...]}) – List of points to convert
sub_values (boolean, default=True) – If the search space is a subspace and if True, uses the original values to convert, else uses its own bounds. See Search space
- Returns
points – List of converted points. Points are list of float if converted to continuous.
- Return type
{list[list[{int, float, str}, {int, float, str}…], …], list[list[float, float…], …]}
- reverse(self, points, sub_values=False)[source]
Convert given points from continuous to mixed
- Parameters
points ({list[list[{int, float, str}, {int, float, str}...], ...], list[list[float, float...], ...]}) – List of points to convert
sub_values (boolean, default=True) – If the search space is a subspace and if True, uses the original values to convert, else uses its own bounds. See Search space
- Returns
points – List of converted points. Points are list of float if converted to continuous.
- Return type
{list[list[{int, float, str}, {int, float, str}…], …], list[list[float, float…], …]}
Others
- class DoNothing(variable=None)[source]
Bases:
zellij.core.addons.VarConverterVariable Addon used when a Variables must not be converted. It does nothing, excep returning a non converted value.
- convert(value, *args, **kwargs)[source]
- reverse(value, *args, **kwargs)[source]
.Reverse:
.
.Reverse: