syne_tune.config_space module
- class syne_tune.config_space.Domain[source]
Bases:
object
Base class to specify a type and valid range to sample parameters from.
This base class is implemented by parameter spaces, like float ranges (
Float
), integer ranges (Integer
), or categorical variables (Categorical
). TheDomain
object contains information about valid values (e.g. minimum and maximum values), and exposes methods that allow specification of specific samplers (e.g.uniform()
orloguniform()
).- sampler = None
- default_sampler_cls = None
- property value_type
- Returns:
Type of values (one of
str
,float
,int
)
- cast(value)[source]
- Parameters:
value – Value top cast
- Returns:
value
cast to domain. For a finite domain, this can involve rounding
- sample(spec=None, size=1, random_state=None)[source]
- Parameters:
spec (
Union
[List
[dict
],dict
,None
]) – Passed to samplersize (
int
) – Number of values to sample, defaults to 1random_state (
Optional
[RandomState
]) – PRN generator
- Return type:
Union
[Any
,List
[Any
]]- Returns:
Single value (
size == 1
) or list (size > 1
)
- is_valid(value)[source]
- Parameters:
value (
Any
) – Value to test- Returns:
Is
value
a valid value in domain?
- property domain_str
- match_string(value)[source]
Returns string representation of
value
(which must be of domain type) which is to match configurations for (approximate) equality. For discrete types (e.g.,Integer
,Categorical
), this matches for exact equality.- Parameters:
value (
Any
) – Value of domain type (usecast()
to be safe)- Return type:
str
- Returns:
String representation useful for matching
- class syne_tune.config_space.LogUniform(base=2.718281828459045)[source]
Bases:
Sampler
Note: We keep the argument
base
for compatibility with Ray Tune. Sincebase
has no effect on the distribution, we don’t use it internally.
- class syne_tune.config_space.Float(lower, upper)[source]
Bases:
Domain
Continuous value in closed interval
[lower, upper]
.- Parameters:
lower (
float
) – Lower bound (included)upper (
float
) – Upper bound (included)
- default_sampler_cls
alias of
_Uniform
- property value_type
- Returns:
Type of values (one of
str
,float
,int
)
- is_valid(value)[source]
- Parameters:
value (
float
) – Value to test- Returns:
Is
value
a valid value in domain?
- property domain_str
- match_string(value)[source]
Returns string representation of
value
(which must be of domain type) which is to match configurations for (approximate) equality. For discrete types (e.g.,Integer
,Categorical
), this matches for exact equality.- Parameters:
value – Value of domain type (use
cast()
to be safe)- Return type:
str
- Returns:
String representation useful for matching
- class syne_tune.config_space.Integer(lower, upper)[source]
Bases:
Domain
Integer value in closed interval
[lower, upper]
. Note thatupper
is included.- Parameters:
lower (
int
) – Lower bound (included)upper (
int
) – Upper bound (included)
- default_sampler_cls
alias of
_Uniform
- property value_type
- Returns:
Type of values (one of
str
,float
,int
)
- cast(value)[source]
- Parameters:
value – Value top cast
- Returns:
value
cast to domain. For a finite domain, this can involve rounding
- is_valid(value)[source]
- Parameters:
value (
int
) – Value to test- Returns:
Is
value
a valid value in domain?
- property domain_str
- match_string(value)[source]
Returns string representation of
value
(which must be of domain type) which is to match configurations for (approximate) equality. For discrete types (e.g.,Integer
,Categorical
), this matches for exact equality.- Parameters:
value – Value of domain type (use
cast()
to be safe)- Return type:
str
- Returns:
String representation useful for matching
- class syne_tune.config_space.Categorical(categories)[source]
Bases:
Domain
Value from finite set, whose values do not have a total ordering. For values with an ordering, use
Ordinal
.- Parameters:
categories (
Sequence
) – Finite sequence, all entries must have same type
- default_sampler_cls
alias of
_Uniform
- is_valid(value)[source]
- Parameters:
value (
Any
) – Value to test- Returns:
Is
value
a valid value in domain?
- property value_type
- Returns:
Type of values (one of
str
,float
,int
)
- property domain_str
- cast(value)[source]
- Parameters:
value – Value top cast
- Returns:
value
cast to domain. For a finite domain, this can involve rounding
- match_string(value)[source]
Returns string representation of
value
(which must be of domain type) which is to match configurations for (approximate) equality. For discrete types (e.g.,Integer
,Categorical
), this matches for exact equality.- Parameters:
value – Value of domain type (use
cast()
to be safe)- Return type:
str
- Returns:
String representation useful for matching
- class syne_tune.config_space.Ordinal(categories)[source]
Bases:
Categorical
Represents an ordered set. As far as random sampling is concerned, this type is equivalent to
Categorical
, but when used in methods that require encodings (or distances), nearby values have closer encodings.- Parameters:
categories (
Sequence
) – Finite sequence, all entries must have same type
- class syne_tune.config_space.OrdinalNearestNeighbor(categories, log_scale=False)[source]
Bases:
Ordinal
Different type for ordered set of numerical values (int or float). Essentially, the finite set is represented by a real-valued interval containing all values, and random sampling draws a value from this interval and rounds it to the nearest value in
categories
. Iflog_scale
is True, all of this happens in log scale. Unless values are equidistant, this is different fromOrdinal
.- Parameters:
categories (
Sequence
) – Finite sequence, must be strictly increasing, value type must befloat
orint
. Iflog_scale=True
, values must be positivelog_scale (
bool
) – Encoding and NN matching in log domain?
- property lower_int: float | None
- property upper_int: float | None
- property categories_int: ndarray | None
- cast(value)[source]
- Parameters:
value – Value top cast
- Returns:
value
cast to domain. For a finite domain, this can involve rounding
- sample(spec=None, size=1, random_state=None)[source]
- Parameters:
spec (
Union
[List
[dict
],dict
,None
]) – Passed to samplersize (
int
) – Number of values to sample, defaults to 1random_state (
Optional
[RandomState
]) – PRN generator
- Return type:
Union
[Any
,List
[Any
]]- Returns:
Single value (
size == 1
) or list (size > 1
)
- class syne_tune.config_space.FiniteRange(lower, upper, size, log_scale=False, cast_int=False)[source]
Bases:
Domain
Represents a finite range
[lower, ..., upper]
withsize
values equally spaced in linear or log domain. Ifcast_int
, the value type is int (rounding after the transform).- Parameters:
lower (
float
) – Lower bound (included)upper (
float
) – Upper bound (included)size (
int
) – Number of valueslog_scale (
bool
) – Equal spacing in log domain?cast_int (
bool
) – Value type isint
(float
otherwise)
- property values
- property value_type
- Returns:
Type of values (one of
str
,float
,int
)
- cast(value)[source]
- Parameters:
value – Value top cast
- Returns:
value
cast to domain. For a finite domain, this can involve rounding
- sample(spec=None, size=1, random_state=None)[source]
- Parameters:
spec (
Union
[List
[dict
],dict
,None
]) – Passed to samplersize (
int
) – Number of values to sample, defaults to 1random_state (
Optional
[RandomState
]) – PRN generator
- Return type:
Union
[Any
,List
[Any
]]- Returns:
Single value (
size == 1
) or list (size > 1
)
- property domain_str
- match_string(value)[source]
Returns string representation of
value
(which must be of domain type) which is to match configurations for (approximate) equality. For discrete types (e.g.,Integer
,Categorical
), this matches for exact equality.- Parameters:
value – Value of domain type (use
cast()
to be safe)- Return type:
str
- Returns:
String representation useful for matching
- syne_tune.config_space.uniform(lower, upper)[source]
Uniform float value between
lower
andupper
- Parameters:
lower (
float
) – Lower bound (included)upper (
float
) – Upper bound (included)
- Returns:
Float
object
- syne_tune.config_space.loguniform(lower, upper)[source]
Log-uniform float value between
lower
andupper
Sampling is done as
exp(x)
, where x is uniform betweenlog(lower)
andlog(upper)
.- Parameters:
lower (
float
) – Lower bound (included; positive)upper (
float
) – Upper bound (included; positive)
- Returns:
Float
object
- syne_tune.config_space.randint(lower, upper)[source]
Uniform integer between
lower
andupper
lower
andupper
are inclusive. This is a difference to Ray Tune, whereupper
is exclusive.- Parameters:
lower (
int
) – Lower bound (included)upper (
int
) – Upper bound (included)
:return
Integer
object
- syne_tune.config_space.lograndint(lower, upper)[source]
Log-uniform integer between
lower
andupper
lower
andupper
are inclusive. Note: Ray Tune has an argumentbase
here, but since this does not affect the distribution, we drop it.- Parameters:
lower (
int
) – Lower bound (included)upper (
int
) – Upper bound (included)
:return
Integer
object
- syne_tune.config_space.choice(categories)[source]
Uniform over list of categories
- Parameters:
categories (
list
) – Sequence of values, all entries must have the same type- Returns:
Categorical
object
- syne_tune.config_space.ordinal(categories, kind=None)[source]
Ordinal value from list
categories
. Different variants are selected bykind
.For
kind == "equal"
, sampling is the same as forchoice
, and the internal encoding is by int (first value maps to 0, second to 1, …).For
kind == "nn"
, the finite set is represented by a real-valued interval containing all values, and random sampling draws a value from this interval and rounds it to the nearest value incategories
. This behaves like a finite version ofuniform
orrandint
. Forkind == "nn-log"
, nearest neighbour rounding happens in log space, which behaves like a finite version ofloguniform`()
orlograndint`()
. You can also use the synonymlogordinal()
. For this type, values incategories
must be int or float and strictly increasing, and also positive ifkind == "nn-log"
.- Parameters:
categories (
list
) – Sequence of values, all entries must have the same typekind (
Optional
[str
]) – Can be “equal”, “nn”, “nn-log”
- Returns:
Ordinal
orOrdinalNearestNeighbor
object
- syne_tune.config_space.logordinal(categories)[source]
Corresponds to
ordinal()
withkind="nn-log"
, so that nearest neighbour mapping happens in log scale. Values incategories
must be int or float, strictly increasing, and positive.- Parameters:
categories (
list
) – Sequence of values, strictly increasing, of typefloat
orint
, all positive- Returns:
OrdinalNearestNeighbor
object
- syne_tune.config_space.finrange(lower, upper, size, cast_int=False)[source]
Finite range
[lower, ..., upper]
withsize
entries, which are equally spaced. Finite alternative touniform()
.- Parameters:
lower (
float
) – Smallest feasible valueupper (
float
) – Largest feasible valuesize (
int
) – Size of (finite) domain, must be >= 2cast_int (
bool
) – Values rounded and cast to int?
- Returns:
FiniteRange
object
- syne_tune.config_space.logfinrange(lower, upper, size, cast_int=False)[source]
Finite range
[lower, ..., upper]
withsize
entries, which are equally spaced in the log domain. Finite alternative tologuniform()
.- Parameters:
lower (
float
) – Smallest feasible value (positive)upper (
float
) – Largest feasible value (positive)size (
int
) – Size of (finite) domain, must be >= 2cast_int (
bool
) – Values rounded and cast to int?
- Returns:
FiniteRange
object
- syne_tune.config_space.is_log_space(domain)[source]
- Parameters:
domain (
Domain
) – Hyperparameter type- Return type:
bool
- Returns:
Logarithmic encoding?
- syne_tune.config_space.is_uniform_space(domain)[source]
- Parameters:
domain (
Domain
) – Hyperparameter type- Return type:
bool
- Returns:
Linear (uniform) encoding?
- syne_tune.config_space.add_to_argparse(parser, config_space)[source]
Use this to prepare argument parser in endpoint script, for the non-fixed parameters in
config_space
.- Parameters:
parser (
ArgumentParser
) –argparse.ArgumentParser
objectconfig_space (
Dict
[str
,Any
]) – Configuration space (modified)
- syne_tune.config_space.cast_config_values(config, config_space)[source]
Returns config with keys, values of
config
, but values are cast to their specific types.- Parameters:
config (
Dict
[str
,Any
]) – Config whose values are to be castconfig_space (
Dict
[str
,Any
]) – Configuration space
- Return type:
Dict
[str
,Any
]- Returns:
New config with values cast to correct types
- syne_tune.config_space.non_constant_hyperparameter_keys(config_space)[source]
- Parameters:
config_space (
Dict
[str
,Any
]) – Configuration space- Return type:
List
[str
]- Returns:
Keys corresponding to (non-fixed) hyperparameters
- syne_tune.config_space.config_space_size(config_space, upper_limit=1048576)[source]
Counts the number of distinct configurations in the configuration space
config_space
. If this is infinite (due to real-valued parameters) or larger thanupper_limit
, None is returned.- Parameters:
config_space (
Dict
[str
,Any
]) – Configuration spaceupper_limit (
int
) – See above. Defaults to2**20
- Return type:
Optional
[int
]- Returns:
Number of distinct configurations; or
None
if infinite or more thanupper_limit
- syne_tune.config_space.config_to_match_string(config, config_space, keys)[source]
Maps configuration to a match string, which can be used to compare configs for (approximate) equality. Only keys in
keys
are used, in that ordering.- Parameters:
config (
Dict
[str
,Any
]) – Configuration to be encoded in match stringconfig_space (
Dict
[str
,Any
]) – Configuration spacekeys (
List
[str
]) – Keys of parameters to be encoded
- Return type:
str
- Returns:
Match string
- syne_tune.config_space.to_dict(x)[source]
We assume that for each
Domain
subclass, the__init__()
kwargs are also members, and all other members start with_
.
- syne_tune.config_space.config_space_to_json_dict(config_space)[source]
Converts
config_space
into a dictionary that can be saved as a json file.- Parameters:
config_space (
Dict
[str
,Union
[Domain
,int
,float
,str
]]) – Configuration space- Return type:
Dict
[str
,Union
[int
,float
,str
]]- Returns:
JSON-serializable dictionary representing
config_space
- syne_tune.config_space.config_space_from_json_dict(config_space_dict)[source]
Converts the given dictionary into a Syne Tune search space.
Reverse of
config_space_to_json_dict()
.- Parameters:
config_space_dict (
Dict
[str
,Union
[int
,float
,str
]]) – JSON-serializable dict, as output byconfig_space_to_json_dict()
- Return type:
Dict
[str
,Union
[Domain
,int
,float
,str
]]- Returns:
Configuration space corresponding to
config_space_dict
- syne_tune.config_space.restrict_domain(numerical_domain, lower, upper)[source]
Restricts a numerical domain to be in the range
[lower, upper]
- syne_tune.config_space.quniform(lower, upper, q)[source]
Sample a quantized float value uniformly between
lower
andupper
.Sampling from
tune.uniform(1, 10)
is equivalent to sampling fromnp.random.uniform(1, 10))
The value will be quantized, i.e. rounded to an integer increment of
q
. Quantization makes the upper bound inclusive.
- syne_tune.config_space.reverseloguniform(lower, upper)[source]
Values 0 <= x < 1, internally represented as -log(1 - x)
- Paam lower:
Lower boundary of the output interval (e.g. 0.99)
- Parameters:
upper (
float
) – Upper boundary of the output interval (e.g. 0.9999)- Returns:
Float
object
- syne_tune.config_space.qloguniform(lower, upper, q)[source]
Sugar for sampling in different orders of magnitude.
The value will be quantized, i.e. rounded to an integer increment of
q
. Quantization makes the upper bound inclusive.- Parameters:
lower (
float
) – Lower boundary of the output interval (e.g. 1e-4)upper (
float
) – Upper boundary of the output interval (e.g. 1e-2)q (
float
) – Quantization number. The result will be rounded to an integer increment of this value.